Refactor JExcelHelper
This commit is contained in:
parent
a44ea9588f
commit
b9c4496a71
@ -1,22 +1,24 @@
|
|||||||
package com.baeldung.excel;
|
package com.baeldung.excel;
|
||||||
|
|
||||||
import jxl.*;
|
import jxl.Sheet;
|
||||||
import java.util.Map;
|
import jxl.Workbook;
|
||||||
import java.util.HashMap;
|
import jxl.format.Colour;
|
||||||
import java.util.ArrayList;
|
|
||||||
import jxl.read.biff.BiffException;
|
import jxl.read.biff.BiffException;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import jxl.write.*;
|
import jxl.write.*;
|
||||||
import jxl.write.Number;
|
import jxl.write.Number;
|
||||||
import jxl.format.Colour;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class JExcelHelper {
|
public class JExcelHelper {
|
||||||
|
|
||||||
public Map<Integer, ArrayList<String>> readJExcel(String fileLocation) throws IOException, BiffException {
|
public Map<Integer, ArrayList<String>> readJExcel(String fileLocation) throws IOException, BiffException {
|
||||||
Map<Integer, ArrayList<String>> data = new HashMap<Integer, ArrayList<String>>();
|
Map<Integer, ArrayList<String>> data = new HashMap<>();
|
||||||
|
|
||||||
Workbook workbook = Workbook.getWorkbook(new File(fileLocation));
|
Workbook workbook = Workbook.getWorkbook(new File(fileLocation));
|
||||||
Sheet sheet = workbook.getSheet(0);
|
Sheet sheet = workbook.getSheet(0);
|
||||||
@ -24,7 +26,7 @@ public class JExcelHelper {
|
|||||||
int columns = sheet.getColumns();
|
int columns = sheet.getColumns();
|
||||||
|
|
||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < rows; i++) {
|
||||||
data.put(i, new ArrayList<String>());
|
data.put(i, new ArrayList<>());
|
||||||
for (int j = 0; j < columns; j++) {
|
for (int j = 0; j < columns; j++) {
|
||||||
data.get(i).add(sheet.getCell(j, i).getContents());
|
data.get(i).add(sheet.getCell(j, i).getContents());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user