我無法使用autosizecolumn()。 其實我沒有得到哪裏寫這個autosizecoloumn()方法,但我得到了印上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.");