我可以选择将数据导出为 PDF,代码如下:
response.setHeader("Content-disposition", "attachment; filename=\"" + title + ".pdf\"");
PdfWriter.getInstance(document,response.getOutputStream());
Excel
导出文件的等效选项是什么PdfWriter.getInstance(document,response.getOutputStream());
PDF
下面的代码也非常适合执行下载,但是当我使用选项打开时它无法打开文件。
怎么办。
更新 :
这是我用来生成和导出 PDF 文件的代码,同样的方法对 excel 文件有什么办法吗?
if(exportTo.equals("pdf"))
{
response.setHeader("Content-disposition", "attachment; filename=\"" + title + ".pdf\"");
response.setContentType("application/pdf");
PdfWriter.getInstance(document,response.getOutputStream());
try {
document.open();
addTitlePage(document, "Employee Report Details");
/* Image image = Image.getInstance(path+"images/abi.png");
image.setAbsolutePosition(40f, 770f);
image.scaleAbsolute(70f, 50f);
document.add(image);*/
Map headerMap = new LinkedHashMap();
headerMap = custDAO.getHeader(query);
float[] colsWidth = {1.5f,3f,4f,4f,2f};
PdfPTable table = new PdfPTable(colsWidth);
table.setWidthPercentage(98);
table.setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell c1 = new PdfPCell();
for (Iterator it = headerMap.keySet().iterator(); it.hasNext();) {
String headerName = (String) headerMap.get(it.next());
c1 = new PdfPCell(new Phrase(headerName, headerFont));
c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
table.addCell(c1);
}
table.setHeaderRows(1);
table = custDAO.creadPDFTable(query, table);
document.add(table);
document.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
问候