title: jasperreports - excel export
body: <p>i have already managed to export a pdf report with jasperreports but i cannot export to excel format.</p>
  
  <p>The xls output file my program produces doesn't open with Excel(corrupted), and is totally empty if i open it with LibreOffice.</p>
  
  <p>Here is the jrxml code(a test example):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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="xls" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d8281a37-1a28-43e6-824c-0d39b69f7d23"&gt;
  &lt;property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/&gt;
  &lt;property name="net.sf.jasperreports.print.keep.full.text" value="true"/&gt;
  &lt;property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/&gt;
  &lt;property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/&gt;
  &lt;property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/&gt;
  &lt;style name="table"&gt;
      &lt;box&gt;
          &lt;pen lineWidth="1.0" lineColor="#000000"/&gt;
      &lt;/box&gt;
  &lt;/style&gt;
  &lt;style name="table_TH" mode="Opaque" backcolor="#F0F8FF"&gt;
      &lt;box&gt;
          &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
      &lt;/box&gt;
  &lt;/style&gt;
  &lt;style name="table_CH" mode="Opaque" backcolor="#BFE1FF"&gt;
      &lt;box&gt;
          &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
      &lt;/box&gt;
  &lt;/style&gt;
  &lt;style name="table_TD" mode="Opaque" backcolor="#FFFFFF"&gt;
      &lt;box&gt;
          &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
      &lt;/box&gt;
  &lt;/style&gt;
  &lt;subDataset name="Table Dataset 1" uuid="3897caef-b047-4ba2-8b62-bd46ec43553d"/&gt;
  &lt;field name="credit" class="java.lang.Double"/&gt;
  &lt;field name="time" class="java.lang.String"/&gt;
  &lt;title&gt;
      &lt;band height="50"/&gt;
  &lt;/title&gt;
  &lt;pageHeader&gt;
      &lt;band height="50"&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="30" width="100" height="20" uuid="4a091ece-05dc-48a7-8390-bf3722715ca8"/&gt;
              &lt;text&gt;&lt;![CDATA[Nikos]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
      &lt;/band&gt;
  &lt;/pageHeader&gt;
  &lt;columnHeader&gt;
      &lt;band height="50"&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="30" width="100" height="20" uuid="39c43e60-ee74-4373-bafb-b78647870be5"/&gt;
              &lt;text&gt;&lt;![CDATA[Nikos]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
      &lt;/band&gt;
  &lt;/columnHeader&gt;
  &lt;detail&gt;
      &lt;band height="153"&gt;
          &lt;textField&gt;
              &lt;reportElement x="0" y="0" width="100" height="20" uuid="ec837765-6e78-417f-b6ea-1cec760fba54"/&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{credit}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;textField&gt;
              &lt;reportElement x="100" y="0" width="100" height="20" uuid="23e21ff0-e776-4a04-a5d0-a4188694446e"/&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{time}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
      &lt;/band&gt;
  &lt;/detail&gt;
  &lt;summary&gt;
      &lt;band height="229"&gt;
          &lt;textField&gt;
              &lt;reportElement x="0" y="0" width="100" height="20" uuid="a5015437-e944-41c1-88bf-9a0d9f88e2d0"/&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{credit}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;textField&gt;
              &lt;reportElement x="100" y="0" width="100" height="20" uuid="066120ca-8df1-40fb-8dea-b93bf5ef30a9"/&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{time}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
      &lt;/band&gt;
  &lt;/summary&gt;
  </code></pre>
  
  <p></p>
  
  <p>And this is my java program (contains also pdf successful export):</p>
  
  <pre><code>public static void main(String[] args) {
      String inPdfFileName = "src/test/javabeans.jasper";
      String inXlsFileName = "src/test/xls.jasper";
      String outPdfName = "test.pdf";
      String outXlsName = "test.xls";
      HashMap pdfParams = new HashMap();
      HashMap xlsParams = new HashMap();
  
      Collection&lt;FundBean&gt; fundbeans = FundBeanFactory.getBeanCollection();
      pdfParams.put("HighTime", FundBeanFactory.getMax().getTime());
      pdfParams.put("LowTime", FundBeanFactory.getMin().getTime());
  
      pdfParams.put("Highest", FundBeanFactory.getMax().getCredit().toString());
      pdfParams.put("Lowest", FundBeanFactory.getMin().getCredit().toString());
  
      JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(fundbeans);
      try {
          JasperPrint PdfPrint = JasperFillManager.fillReport(
                  inPdfFileName,
                  pdfParams,
                  beanCollectionDataSource);
  
          JasperPrint xlsPrint = JasperFillManager.fillReport(
                  inXlsFileName,
                  xlsParams,
                  beanCollectionDataSource);
  
          JRPdfExporter pdfExporter = new JRPdfExporter();
          pdfExporter.setExporterInput(new SimpleExporterInput(PdfPrint));
          pdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outPdfName));
          SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
          configuration.setCreatingBatchModeBookmarks(true);
          pdfExporter.setConfiguration(configuration);
          pdfExporter.exportReport();
  
          JRXlsExporter xlsExporter = new JRXlsExporter();
  
          xlsExporter.setExporterInput(new SimpleExporterInput(xlsPrint));
          xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outXlsName));
          SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration();
          xlsReportConfiguration.setOnePagePerSheet(false);
          xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(true);
          xlsReportConfiguration.setDetectCellType(false);
          xlsReportConfiguration.setWhitePageBackground(false);
          xlsExporter.setConfiguration(xlsReportConfiguration);
  
          xlsExporter.exportReport();
      } catch (JRException e) {
          e.printStackTrace();
      }
    }
  </code></pre>
  
  <p>When i preview in xls format with iReport Designer i get the desired result.
  So i guess the problem lies in my java code...</p>