Apache POI生成文件并在里面sorting
我正尝试通过“transactionBatch”参数对我的交易进行“ 分组 ”。 我看到我的HashMap成功地收集了独特的批次。 当我debugging下面的代码时,一切似乎都正确完成。 虽然当我检查excel文件时,交易没有相应的分组。 他们应该分组:
batch # 1: - transaction with batch # 1 - transaction with batch # 1 batch # 2: - transaction with batch # 2 - transaction with batch # 2
结果excel文件包含:
batch # 1: - transaction with batch # 1 - transaction with batch # 2 batch # 2: - transaction with batch # 4 - transaction with batch # 1
这是代码:
HashMap<String, String> hashMap = new HashMap<>(); for (int i = 0; i < nodeList.getLength(); i++) { hashMap.put(((Element) (nodeList.item(i))).getElementsByTagName("transactionBatch").item(0) .getFirstChild().getNodeValue(), ((Element) (nodeList.item(i))).getElementsByTagName("transactionBatchDate").item(0) .getFirstChild().getNodeValue()); } for (Map.Entry<String, String> entry : hashMap.entrySet()) { for (int i = 0; i < nodeList.getLength(); i++) { String transactionBatch = ((Element) (nodeList.item(i))).getElementsByTagName("transactionBatch").item(0) .getFirstChild().getNodeValue(); String key = entry.getKey(); if (transactionBatch.equals(key)) { HSSFRow dynamicRow = spreadSheet.createRow(i + 2); if (nodeList.getLength() != 0) { cell = dynamicRow.createCell((short) 0); cell.setCellValue(((Element) (nodeList.item(i))).getElementsByTagName("transactionNumber").item(0) .getFirstChild().getNodeValue()); cell.setCellStyle(styleWithDataCentered); ... cell = dynamicRow.createCell((short) 8); cell.setCellValue(((Element) (nodeList.item(i))).getElementsByTagName("transactionBatch").item(0) .getFirstChild().getNodeValue()); cell.setCellStyle(styleWithDataCentered); } } } }
问题在于这一行:
HSSFRow dynamicRow = spreadSheet.createRow(i + 2);
我不得不在for方法之外分配另外一个variables来保持int:
int rowNumber = 2;
然后只是增加每行的价值。
HSSFRow dynamicRow = spreadSheet.createRow(rowNumber += 1);
- 将所有types的RELATIONS从一个工作簿复制到新的工作簿Apache POI XSSFWorkbook
- Apache POI 3.9无法获得HSSFPalette
- 如何使用apache poi创build数据透视表后格式化时间列?
- Apache POI或Excel公式语法
- 在使用apache POI从xlsx文件读取数据时出现的线程“main”org.apache.poi.POIXMLExceptionexception中的exception
- 如何摆脱用户试图打开Excel电子表格时显示的警告消息?
- 我想安排整个单元格在特定的列,而不是单个单元格
- 如何通过SXSSF保护Excel工作簿?
- 使用Apache POI Java在单元格文本中添加下标