Search code examples
javajasper-reportsexport-to-excelxls

How to disable the "grid line" option in Excel report?


I have a jasper report with output in excel, I would like to disable the "grid line" option in excel for the background to be all white.

How I can do this in jasper report?

EDIT: The following examples worked for me !!

You set this property directly in your jrxml

net.sf.jasperreports.export.xls.show.gridlines=false, the default value is true

jrxml example

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="reputation" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" uuid="a88bd694-4f90-41fc-84d0-002b90b2d73e">
     <property name="net.sf.jasperreports.export.xls.show.gridlines" value="false"/>
     ....
</jasperReport>

or if you are exporting from java set the SimpleXlsReportConfiguration.setShowGridLines(false)

java example

JRXlsExporter exporterXls = new JRXlsExporter();
exporterXls.setExporterInput(new SimpleExporterInput(jasperPrint));
exporterXls.setExporterOutput(new SimpleOutputStreamExporterOutput(new File("excelTest.xls")));
SimpleXlsReportConfiguration configXls = new SimpleXlsReportConfiguration();
configXls.setShowGridLines(false);
//set your additional settings
exporterXls.setConfiguration(configXls);
exporterXls.exportReport();

Note: The code shows xls (since tagged xls) example but the same property can be used for the SimpleXlsxReportConfiguration (xlsx)


Solution

  • You set this property directly in your jrxml

    net.sf.jasperreports.export.xls.show.gridlines=false, the default value is true

    jrxml example

    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="reputation" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" uuid="a88bd694-4f90-41fc-84d0-002b90b2d73e">
         <property name="net.sf.jasperreports.export.xls.show.gridlines" value="false"/>
         ....
    </jasperReport>
    

    or if you are exporting from java set the SimpleXlsReportConfiguration.setShowGridLines(false)

    java example

    JRXlsExporter exporterXls = new JRXlsExporter();
    exporterXls.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporterXls.setExporterOutput(new SimpleOutputStreamExporterOutput(new File("excelTest.xls")));
    SimpleXlsReportConfiguration configXls = new SimpleXlsReportConfiguration();
    configXls.setShowGridLines(false);
    //set your additional settings
    exporterXls.setConfiguration(configXls);
    exporterXls.exportReport();
    

    Note: The code shows xls (since tagged xls) example but the same property can be used for the SimpleXlsxReportConfiguration (xlsx)