private static final String SHEET_TO_STREAM = "large sheet";
public static void main(String[] args) throws IOException, SAXException {
- InputStream sourceBytes = new FileInputStream("/path/too/workbook.xlsx");
+ InputStream sourceBytes = new FileInputStream("workbook.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(sourceBytes) {
/** Avoid DOM parse of large sheet */
public void parseSheet(java.util.Map<String,XSSFSheet> shIdMap, CTSheet ctSheet) {
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(workbook.getPackage());
new XSSFSheetXMLHandler(workbook.getStylesSource(), strings, createSheetContentsHandler(), false);
workbook.close();
+ sourceBytes.close();
}
private static SheetContentsHandler createSheetContentsHandler() {
FileOutputStream out = new FileOutputStream("simpleTable.docx");
doc.write(out);
out.close();
+
+ doc.close();
}
/**
rh.setBold(true);
para.setAlignment(ParagraphAlignment.CENTER);
}
- else if (rowCt % 2 == 0) {
- // even row
- rh.setText("row " + rowCt + ", col " + colCt);
- para.setAlignment(ParagraphAlignment.LEFT);
- }
else {
- // odd row
+ // other rows
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
}
FileOutputStream out = new FileOutputStream("styledTable.docx");
doc.write(out);
out.close();
+
+ doc.close();
}
}