[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Exporting data to an excel spreadsheet



   public void saveReport( HttpServletRequest pRequest,
                           HttpServletResponse pResponse,
                           HttpSession pSession )
      throws Exception
   {
       
        //get your own data, you can ignor this part.
      HashMap map = getData( pRequest, pResponse, pSession );
      Report report = new MyReport();
      String reportData =
         report.generateReportToString( (Hashtable)map.get( "header" ),
                                        (Enumeration)map.get( "data" ) );

      //set your report type  
      pResponse.setContentType( "application/vnd.ms-excel" );  
     
      //if you want to save the report as a file Force browser to show save as dialog and give default file name.
      pResponse.setHeader( "Content-disposition",
                           "attachment; filename="+DEF_REPORT_NAME );

      pResponse.setContentLength( reportData.length() );
      pResponse.getWriter().print( reportData );
   }

Hello all,

I thought excel spreadsheets were in a proprietary, binary format. So how can the browser simply save the file as *.xls ? Simply making a file "filename.xls" make it an excel file ?

One way to solve this problem is to write to an Access database and export the table as an excel document.

Check this site out. They seem to have some JDBC drivers to manipulate excel documents.

http://www.vistaportal.com/products/vistajdbc.htm

 

Good Luck,

Greg

P.S. e-mail your results



Help STOP SPAM with the new MSN 8 and get 2 months FREE*