Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Rep Power

    Default Problem with exporting csv file using template

    Java Code:
    public ActionForward createReport(ActionMapping mapping
                            , ActionForm form
                            , HttpServletRequest request
                            , HttpServletResponse response) {
                    ReportForm reportForm = (ReportForm)form;
                    String year = reportForm.getYear();
                    String month = reportForm.getMonth();
                            ServletContext context = this.getServlet().getServletContext();
                            String path = context.getRealPath("/WEB-INF/classes/template.csv");
                            FileInputStream fileInputStream = new FileInputStream(path);
                            HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);                      
                  , month, workbook);
                            response.setHeader("Content-Disposition", "attachment;filename=report.csv");
                            ServletOutputStream outputStream = response.getOutputStream();
                    catch (Exception exception){
                    return null;    
    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 problem

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    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

  1. Exporting to a executable JAR file
    By Drun in forum Eclipse
    Replies: 4
    Last Post: 03-27-2010, 03:16 PM
  2. Exporting WAR File Issue
    By bsimic in forum Eclipse
    Replies: 0
    Last Post: 12-29-2009, 03:23 PM
  3. Exporting jar problem
    By cocorota in forum Eclipse
    Replies: 0
    Last Post: 11-20-2009, 05:08 PM
  4. Apache Velocity template file and output locations
    By mjwoodford in forum New To Java
    Replies: 1
    Last Post: 10-05-2009, 03:59 PM
  5. Problem when exporting to CSV
    By deepusrp in forum New To Java
    Replies: 10
    Last Post: 06-26-2009, 09:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts