我无法使用 autosizecolumn()。实际上,尽管我将所有数据都打印在 xls 文件上,但我没有找到在哪里编写此 autosizecolumn() 方法,现在我唯一的要求是设置 autosizecolumn。
我在左上角和右上角的公司徽标和下方的表格数据上使用了 addmergeredregion。
对于列标题
short mainrow=10;
row=sheet.createRow(mainrow);
cell= row.createCell((short)0);
cell.setCellValue(new HSSFRichTextString("Sr.No."));
cell.setCellStyle(header);
sheet.autoSizeColumn((short)0);
cell= row.createCell((short)1);
cell.setCellValue(new HSSFRichTextString("Town_Code"));
cell.setCellStyle(header);
cell= row.createCell((short)2);
cell.setCellValue(new HSSFRichTextString("Town_Name"));
cell.setCellStyle(header);
cell= row.createCell((short)3);
cell.setCellValue(new HSSFRichTextString("State_Name"));
cell.setCellStyle(header);
cell= row.createCell((short)4);
cell.setCellValue(new HSSFRichTextString("Country_Name"));
cell.setCellStyle(header);
将数据填充到 XLS
short cellnum;
Integer srno=1;
for(Town town : townList){
row=sheet.createRow(++mainrow);
cellnum=0;
cell= row.createCell(cellnum++);
cell.setCellValue(srno++);
cell.setCellStyle(dataformat);
cell= row.createCell(cellnum++);
cell.setCellValue(new HSSFRichTextString(town.getTownCode()));
cell.setCellStyle(dataformat);
cell= row.createCell(cellnum++);
cell.setCellValue(new HSSFRichTextString(town.getName()));
cell.setCellStyle(dataformat);
cell= row.createCell(cellnum++);
cell.setCellValue(new HSSFRichTextString(town.getStateName()));
cell.setCellStyle(dataformat);
cell= row.createCell(cellnum++);
cell.setCellValue(new HSSFRichTextString(town.getCountryName()));
cell.setCellStyle(dataformat);
}
workbook.write(reportOutBuffer);
reportOutBuffer.close();
printNewReport(request, resp, reportOutBuffer.toByteArray(), "application/xls" ,"Town_Report_2013.");