I have an option to export the data to PDF, the code is listed below :
response.setHeader("Content-disposition", "attachment; filename=\"" + title + ".pdf\"");
PdfWriter.getInstance(document,response.getOutputStream());
what is the equivalent option to export Excel
file like PdfWriter.getInstance(document,response.getOutputStream());
also below code is perfect to perform download but it fails to open the PDF
file when i give open with option.
how to go about.
UPDATE :
this is the code that i use to genarate and export the PDF file, same way is there any way to do for excel file ?
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();
}
}
Regards
I refer you to this tutorial:
http://www.vogella.com/articles/JavaExcel/article.html#createexcel
there's no one best choice for excel exporting. there's a lot of libraries out there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.