我想使用POI在Java中创建excel报告。但我有关于对行和列单元格进行分组的问题。我想创建三行,所有行都有不同数量的列单元格。我怎样才能克服这个问题?
谢谢。我的代码在这里:
public ByteArrayOutputStream getExcel(List<List<String>> dynamicValues, List<String> headerColumns ){
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("PAGE");
int rownum = 0;
int cellnum = 0;
Row row = sheet.createRow(rownum++);
Cell cell = row.createCell(cellnum++);
cell.setCellValue("AAA");
sheet.groupColumn(0, 3);
sheet.setColumnGroupCollapsed(3, false);
Cell cell4 = row.createCell(cellnum++);
cell4.setCellValue("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
workbook.write(baos);
baos.close();
}catch (Exception e) {
e.printStackTrace();
}
return baos;
}