I would like to convert a xls to a xlsx file. Since I have only one tab, is it best to just iterate the rows and cells and copy them from one sheet to the other? Should the API provide a why to set entire rows or sheets instead of copying all of the information one-by-one with getters and setters?
This is what I'm having to do:
InputStream in = new BufferedInputStream(new FileInputStream(inpFn));
try {
Workbook wbIn = new HSSFWorkbook(in);
OPCPackage outPkg = OPCPackage.open(outFn);
try {
Workbook wbOut = new XSSFWorkbook(outPkg);
int sheetCnt = wbIn.getNumberOfSheets();
for (int i = 0; i < sheetCnt; i++) {
Sheet s = wbIn.getSheetAt(0);
Sheet s2 = wbOut.createSheet(s.getSheetName());
Iterator<Row> rowIt = s.iterator();
while (rowIt.hasNext()) {
Row row = rowIt.next();
// ....
}
}
} finally {
outPkg.close();
}
} finally {
in.close();
}
If you point me in the right direction, I'll make sure to update the post with the final code. I have not found any good code examples for this yet.