亲们 poi写入excel时出现问题 帮忙看下吧
小弟基础薄弱,求指导 poi?excel
[解决办法]
poi是绝对支持07版的excel写入的。看楼主的代码写入操作有问题。
楼主开输出流和book.write都是在for循环里面做的,正确的应该要for循环里面把表格内容修改完一次性写入,因为07办的excel其实是基于xml的SAX方式的。不能回退的
[解决办法]
真艹单,不做excel了官网的例子也出来了。。、
public static void main(String[] args) throws Throwable {
SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
Sheet sh = wb.createSheet();
for(int rownum = 0; rownum < 1000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
String address = new CellReference(cell).formatAsString();
cell.setCellValue(address);
}
}
// Rows with rownum < 900 are flushed and not accessible
for(int rownum = 0; rownum < 900; rownum++){
Assert.assertNull(sh.getRow(rownum));
}
// ther last 100 rows are still in memory
for(int rownum = 900; rownum < 1000; rownum++){
Assert.assertNotNull(sh.getRow(rownum));
}
FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx");
wb.write(out);
out.close();
// dispose of temporary files backing this workbook on disk
wb.dispose();
}