Results 1 to 2 of 2
- 12-06-2010, 09:52 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Problem with exporting csv file using template
the code above i write to export report.csv base on template.csv format, but when i run the web, it always export report.xls, although i changed the file name already, so can anyone take a look of it and help me toa resolve this problemJava Code:public ActionForward createReport(ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response) { ((MenuForm)request.getSession().getAttribute("MenuForm")).setAction(Constants.ACTION_REPORT); ReportForm reportForm = (ReportForm)form; String year = reportForm.getYear(); String month = reportForm.getMonth(); try{ ServletContext context = this.getServlet().getServletContext(); String path = context.getRealPath("/WEB-INF/classes/template.csv"); FileInputStream fileInputStream = new FileInputStream(path); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); reportBusiness.report(year, month, workbook); response.setContentType("Text/csv"); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=report.csv"); ServletOutputStream outputStream = response.getOutputStream(); workbook.write(outputStream); outputStream.close(); } catch (Exception exception){ System.out.println(exception.getMessage()); } return null; }
- 12-08-2010, 03:40 AM #2
I think it is because the HSSFWorkbook wants to write out an .xls file.
You would need to instead have the .xls contents converted to .csv and have that written out, instead of the workbook directly writing to the output stream. see also: How can I convert HSSFWorkbook into a CSV file..? - Stack Overflow
Similar Threads
-
Exporting to a executable JAR file
By Drun in forum EclipseReplies: 4Last Post: 03-27-2010, 03:16 PM -
Exporting WAR File Issue
By bsimic in forum EclipseReplies: 0Last Post: 12-29-2009, 03:23 PM -
Exporting jar problem
By cocorota in forum EclipseReplies: 0Last Post: 11-20-2009, 05:08 PM -
Apache Velocity template file and output locations
By mjwoodford in forum New To JavaReplies: 1Last Post: 10-05-2009, 03:59 PM -
Problem when exporting to CSV
By deepusrp in forum New To JavaReplies: 10Last Post: 06-26-2009, 09:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks