我有一个web应用程序,其中我有excel文件(.xls)下载选项。现在我必须在.xlsx中提供该功能使用POI从.xls升级到.xlsx
我正在尝试使用POI Jar。当我尝试这样做,作为一个独立的应用程序,它工作正常,但是当我试图将其集成到一个web应用程序,我得到一个错误
Excel中发现在FILENAME.xlsx无法读取内容。你想恢复这个工作簿的内容吗?
如果您信任此工作簿的来源,请点击是!
XSSFWorkbook w = FileName.createExcelWorkbookPosition(
request.getParameter("BSNS_DT"));
response.setContentType(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition","attachment;filename=filename.xlsx");
w.write(response.getOutputStream());
这里的Java代码,我创建电子表格:
public static XSSFWorkbook createExcelWorkbookPosition(String BsnsDate)
throws Exception
{
FileOutputStream out = new FileOutputStream("workbook.xlsx");
// create a new workbook
XSSFWorkbook wb = new XSSFWorkbook();
// create a new sheet
XSSFSheet s = wb.createSheet();
// declare a row object reference
XSSFRow r = null;
// declare a cell object reference
XSSFCell c = null;
// header row and columns
r = s.createRow(0);
c = r.createCell(0);
c.setCellValue("Business Date");
//c.setCellStyle(cs);
c = r.createCell(1);
c.setCellValue("Account No");
try {
wb.write(out);
out.close();
System.out.println("File writed");
} catch (Exception e) {
System.out.println("Error");
System.out.println(e);
}
return wb;
}
任何人都可以请帮助?对不起,英文不好!谢谢。
你能分享你用它来创建Excel工作簿中的代码? – Priyesh
你可以发布一些代码片段以确保excel正确生成吗?你只改变了文件扩展名吗?也改变了一代? – zeppaman
选中此链接。 http://answers.microsoft.com/en-us/office/forum/office_2007-excel/excel-found-unreadable-content/d5c54cc7-6290-4f55-86ac-21a65f9bb807。可能有帮助。 – Priyesh