How to append and write a .xls file with JRXlsExporter

0

I use JRXlsExporter to write my .xls files it works ok as long as I write in a new file every time, my problem is that i want to append an existing .xls file and add new data to the end of that file.

public static void exportXLS(JasperPrint jasperPrint, String fileName) throws IOException, JRException{
 
        SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
        configuration.setOnePagePerSheet(true);
        configuration.setDetectCellType(true);
        configuration.setCollapseRowSpan(false);
        configuration.setWhitePageBackground(false);
 
        File file = new File(fileName+".xls");
        FileOutputStream fos = new FileOutputStream(file,true);
 
        JRXlsExporter exporterXLS = new JRXlsExporter();
        exporterXLS.setExporterInput(new SimpleExporterInput(jasperPrint));
        exporterXLS.setExporterOutput(new SimpleOutputStreamExporterOutput(fos));
        exporterXLS.setConfiguration(configuration);
        exporterXLS.exportReport();
 
        fos.flush();
        fos.close()
  }                                                                                                                                                                                                         
vintila_2005's picture
Joined: Aug 4 2014 - 1:25am
Last seen: 3 years 12 months ago

1 Answer:

0

Check this Sample, is comes with JR so you should have it under /demo/samples/xlsfeatures/

http://jasperreports.sourceforge.net/sample.reference/xlsfeatures/#xlsfe...

You need to use the net.sf.jasperreports.export.xls.workbook.template property See the section "Embedding Content From External Documents Into The Generated Document "

 

marianol's picture
4427
Joined: Sep 13 2011 - 8:04am
Last seen: 9 months 3 weeks ago
Feedback
randomness