Skip to content

Commit

Permalink
excel handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chaneylc committed Jul 7, 2023
1 parent 5e56c6d commit cd4da6a
Showing 1 changed file with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,16 @@ public String[] readNext() {
}

public void close() {
//TODO check for memory leak
try {
if (wb != null) {
wb.close();
}
if (super.getInputStream() != null) {
super.getInputStream().close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Expand Down Expand Up @@ -387,23 +396,26 @@ public boolean isOther() {
public String[] getColumns() {

try {

wb = new XSSFWorkbook(super.getInputStream());

XSSFSheet sheet = wb.getSheetAt(0);
if (super.getInputStream() != null) {

XSSFRow headerRow = sheet.getRow(0);
wb = new XSSFWorkbook(super.getInputStream());

ArrayList<String> columns = new ArrayList<>();
XSSFSheet sheet = wb.getSheetAt(0);

for (Iterator<Cell> it = headerRow.cellIterator(); it.hasNext();) {
XSSFCell cell = (XSSFCell) it.next();
XSSFRow headerRow = sheet.getRow(0);

columns.add(cell.getStringCellValue());
ArrayList<String> columns = new ArrayList<>();

}
for (Iterator<Cell> it = headerRow.cellIterator(); it.hasNext();) {
XSSFCell cell = (XSSFCell) it.next();

return columns.toArray(new String[] {});
columns.add(cell.getStringCellValue());

}

return columns.toArray(new String[] {});
}

} catch (IOException format) {

Expand Down Expand Up @@ -485,7 +497,16 @@ public String[] readNext() {
}

public void close() {
//todo check for memory leak
try {
if (wb != null) {
wb.close();
}
if (super.getInputStream() != null) {
super.getInputStream().close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Expand Down

0 comments on commit cd4da6a

Please sign in to comment.