Search code examples
javajasper-reportsmetadataexport-to-excel

Remove Software info from generated with JasperReports report at Excel format


I'm creating an XLS report using JasperReports with code:

JRXlsExporter exporter = new JRXlsExporter();

exporter.setExporterInput(new SimpleExporterInput(compile(report)));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(stream));

SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();

configuration.setOnePagePerSheet(TRUE);

exporter.setConfiguration(configuration);
exporter.exportReport();

I need to remove Software information from the xls file metadata

The result of running exiftool Vinculaciones.xls command:

ExifTool Version Number         : 12.00

File Name                       : Vinculaciones.xls

Directory                       : .

File Size                       : 5.5 kB

File Modification Date/Time     : 2020:06:11 15:53:33-05:00

File Access Date/Time           : 2020:06:11 15:53:33-05:00

File Creation Date/Time         : 2020:06:11 15:53:32-05:00

File Permissions                : rw-rw-rw-

File Type                       : XLS

File Type Extension             : xls

MIME Type                       : application/vnd.ms-excel

Software                        : JasperReports Library version 6.12.2-75c5e90a222ab406e416cbf590a5397028a52de3

Warning                         : Truncated property list

Solution

  • Try adding these lines:

        SimpleXlsExporterConfiguration exportConfig = new SimpleXlsExporterConfiguration();
        exportConfig.setMetadataApplication("");
        exporter.setConfiguration(exportConfig);
    

    This won't remove the Software metadata field, but it would put an empty value for it. If you want to completely remove the field you'll have to change/extend the exporter code, e.g. like this:

        JRXlsExporter exporter = new JRXlsExporter() {
            @Override
            protected void openWorkbook(OutputStream os) {
                super.openWorkbook(os);
                workbook.getSummaryInformation().removeApplicationName();
            }           
        };