我正在尝试将 xssfWorkbook 文件转换为 SXSSF,因为我正在生成一个大报告,但问题是我无法转换,我目前正在尝试的是这个示例。
public void export(Workbook hssfWorkbook, Map<String, Object> model) throws Exception {
XSSFWorkbook workbook = (XSSFWorkbook)hssfWorkbook;
Sheet sheet = workbook.getSheet(this.excelSheetName);
try {
this.initCommonCellStyles(workbook);
List<ItemsToBillReport> itemsObject= (List<ItemsToBillReport>)model.get("the model name");
CellStyle boldCellStyle = workbook.createCellStyle();
this.setCellStyleBoldFont(workbook, boldCellStyle);
new HSSFColor.GREY_40_PERCENT();
boldCellStyle.setFillForegroundColor(GREY_40_PERCENT.index);
boldCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
Row bdmRow = sheet.getRow(0);
Cell bdmCell = bdmRow.getCell(0);
Bdm bdm = (Bdm)model.get("anoder model");
if(bdm != null && bdm.getLastName()!=null && bdm.getFirstName()!=null){
bdmCell.setCellValue("BDM : "+bdm.getLastName()+", "+bdm.getFirstName());
}else{
bdmCell.setCellValue("BDM : -");
}
bdmCell.setCellStyle(boldCellStyle);
Row billDateRow = sheet.getRow(1);
Cell billDateCell = billDateRow.getCell(0);
String dateFrom = (String)model.get("date from model");
String dateTo = (String)model.get("dateTo");
billDateCell.setCellValue("title "+ dateFrom +" TO "+dateTo);
billDateCell.setCellStyle(boldCellStyle);
Row dateTimeRow = sheet.getRow(2);
Cell dateTimeCell = dateTimeRow.getCell(0);
Format formatter;
final Date date = new Date();
formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String dateString = formatter.format(date);
dateTimeCell.setCellValue("AS OF : "+dateString);
dateTimeCell.setCellStyle(boldCellStyle);
boolean includeFullData = (Boolean)model.get(thisExporter.INCLUDE_FULL_DATA);
boolean isBriefView = (Boolean)model.get(thisExporter.ATTRIBUTE_ITB_BRIEF_VIEW);
SXSSFWorkbook wb = new SXSSFWorkbook(workbook,1000);
sheet = wb.createSheet(this.excelSheetName);
final int totalColNum = this.printItemsToBillListDetails(sheet, itemsObject, includeFullData, isBriefView);
//this.autosizeColumns(sheet, totalColNum);
}catch(Exception e){
Exception h = e;
}
}
如您所见,我正在使用模板文件生成报告,因为开始时有一些数据,当我尝试在开始时转换为 SXSSF 时,它无法完成,因为如果我理解正确,SXSSF 必须写在空白处,因为这是一个模板,它不能在那里写。
因此,我尝试在第一行之后进行转换,但不打印任何内容,它会生成带有信息的第一行,但目前要写入它什么也不写的数据,所以,我如何使用像这个示例这样的模板来转换 ot SXSSF矿?
谢谢你的时间,我只是找不到答案。