Java Apache POI – 单元格格式化停止并重新启动工作
我有一个程序,需要一个input文件,并将其放入Excel中。 一切都很好,直到第32000行。 突然左alignment格式停止工作。 此外,似乎突然重新开始在第65000行的工作。 我不确定发生了什么事情或为什么。 我提供了格式化function的代码。
private static void addDataToExcel(ArrayList<String[]> rowList, int amtOfColumns){ SXSSFRow row = null; String[] colValues = null; for(int i = 1 ; i<= rowList.size() ;i++){ row = (SXSSFRow) worksheet.createRow(rowCount); //TODO: Check if really necessary since for loop starts at 1 now if(i == 0){ } else { colValues = rowList.get(i-1); } CellStyle style = workbook.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_RIGHT); for(int j=0; j < amtOfColumns; j++){ if(colValues[j] == null){ SXSSFCell cell = (SXSSFCell) row.createCell(j); cell.setCellValue(colValues[j+1]); cell.setCellStyle(style); } else{ //System.out.println(j); SXSSFCell cell = (SXSSFCell) row.createCell(j); cell.setCellValue(colValues[j]); cell.setCellStyle(style); } } rowCount++; } System.out.println("Running...");
问题是你每行创build一个单元格样式,这不是你应该做的事情。 Excel对工作簿可以处理的单元格样式的最大数量具有相当低的限制。
由于单元格样式是工作簿的范围,所以您应该将您的代码更改为
SXSSFRow row = null; String[] colValues = null; CellStyle style = workbook.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_RIGHT); for (int i = 1 ; i<= rowList.size() ; i++) { row = (SXSSFRow) worksheet.createRow(rowCount);
这将防止你用尽可用的单元格样式,所以应该让你的程序正常工作
- Apache POI和HashMap以错误的顺序打印出来
- 在使用POI将公式单元格插入到Excel中以及从文件系统打开/closures时如何摆脱“想要将更改保存到”Test.xlsx“
- 在android项目中写入excel文件与apache poi
- java:ByteArrayOutputStream.toByteArray()的性能
- POI:意外的loggingtypesorg.apache.poi.hssf.record.HyperlinkRecord
- 使用Apache POI打印电话号码(string)以显示为科学记数法(4.165551234E9)
- Java | Apache POI | 如何在不创build行的情况下避免空指针exception
- 如何在POI API中返回回车
- 使用java从excel中获取图像