2017-01-30 8 views
0

Я новичок в отчетах Jasper. Я использую версию 5.6.0, и я могу экспортировать некоторые данные в PDF, и все поля заполнены правильно, но когда я пытаюсь экспортировать одни и те же данные в Excel, некоторые поля отсутствуют. Код, который я использую, является некоторым в обоих кланах (у меня есть один класс для экспорта каждого файла)Отчеты Jasper хорошо экспортируются в PDF, но не в Excel

Я также читал, что шаблон для экспорта в PDF или Excel - это то же самое, поэтому я не знаю, зачем это заполняет все PDF, а не в Excel.

Когда я генерировать PDF прохожу все данные, чтобы:

JasperExportManager.exportReportToPdfStream(jasperPrint,fileOutputStream); 

И когда я пытаюсь генерировать Excel Я называю это несильно:

private void generateExcel(JasperPrint jasperPrint) throws IOException, JRException { 
    JRXlsExporter exporterXLS = new JRXlsExporter(); 
    JFileChooser jFileChooser = new JFileChooser("."); 
    jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
    int status = jFileChooser.showOpenDialog(SIXACOPWorkbench.getWorkbenchContext().getWorkbench().getFrame()); 
    if (status == JFileChooser.APPROVE_OPTION) { 
     if (jFileChooser.getSelectedFile() != null) { 
      String pathPDFs = (jFileChooser.getSelectedFile().getAbsolutePath()); 
      File ficheroXLS = new File(pathPDFs+"//testing.xls"); 
      FileOutputStream fos = new FileOutputStream(ficheroXLS); 
      exporterXLS.setExporterInput(new SimpleExporterInput(jasperPrint)); 
      exporterXLS.setExporterOutput(new SimpleOutputStreamExporterOutput(fos)); 
      SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); 
      configuration.setRemoveEmptySpaceBetweenRows(true); 
      configuration.setDetectCellType(true); 
      configuration.setWhitePageBackground(false); 
      exporterXLS.setConfiguration(configuration); 
      exporterXLS.exportReport();  
      fos.close(); 
     } 
    } 
} 

¿Что я делаю неправильно при экспорте в Excel?

С уважением.

--- Update ---

Я thoguht, что если PDF производило хорошо Excel должен это сделать, но после чтения Dave Jarvis комментарий Я обновляю с jrxml:

1 - Там 3 информирует: Inform A - Inform B - Inform C. 2 - Inform A имеет верхний и нижний колонтитул, и каждая строка заполняется Inform B. 3 - На Информ Аргументы B поле, которое он н.у.к. отображается на Excel это numberIndex:

<?xml version="1.0" encoding="UTF-8"?> 
<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="SubinformeAtribucionesPorPropietario1" pageWidth="813" pageHeight="842" columnWidth="813" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="5af05b05-4f4d-4ff8-8bcb-ef8fa6c2b067"> 
    <property name="ireport.scriptlethandling" value="0"/> 
    <property name="ireport.encoding" value="UTF-8"/> 
    <property name="ireport.zoom" value="1.4641000000000008"/> 
    <property name="ireport.x" value="178"/> 
    <property name="ireport.y" value="0"/> 
    <import value="net.sf.jasperreports.engine.*"/> 
    <import value="java.util.*"/> 
    <import value="net.sf.jasperreports.engine.data.*"/> 
    <parameter name="Inform C" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/> 
    <parameter name="useNumberIndex" class="java.lang.Boolean" isForPrompting="false"/> 
    <field name="fieldA" class="java.util.List"/> 
    <field name="fieldB" class="java.lang.String"/> 
    <field name="fieldC" class="java.lang.String"/> 
    <field name="fieldD" class="java.lang.String"/> 
    <field name="fieldF" class="java.lang.String"/> 
    <field name="numberIndex" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band splitType="Stretch"/> 
    </title> 
    <pageHeader> 
     <band splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band splitType="Stretch"/> 
    </columnHeader> 
    <detail> 
     <band height="21" splitType="Stretch"> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-1" mode="Transparent" x="1" y="1" width="53" height="19" forecolor="#000000" backcolor="#FFFFFF" uuid="974d00c4-7438-4d1f-92ff-6b720e113ecd"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$P{useNumberIndex}.booleanValue() ? $F{numberIndex} : $F{fieldC}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-2" mode="Transparent" x="53" y="1" width="297" height="19" forecolor="#000000" backcolor="#FFFFFF" uuid="6dee9995-5734-4e42-b7e1-4c2cbe02739b"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{fieldB}]]></textFieldExpression> 
      </textField> 
      <subreport isUsingCache="true"> 
       <reportElement key="subreport-1" mode="Opaque" x="350" y="1" width="463" height="18" forecolor="#000000" backcolor="#FFFFFF" uuid="a40d7385-072d-4cfc-a952-88b23a906b85"/> 
       <subreportParameter name="name1"> 
        <subreportParameterExpression><![CDATA[$F{fieldD}]]></subreportParameterExpression> 
       </subreportParameter> 
       <subreportParameter name="name2"> 
        <subreportParameterExpression><![CDATA[$F{fieldE}]]></subreportParameterExpression> 
       </subreportParameter> 
       <subreportParameter name="Inform C"> 
        <subreportParameterExpression><![CDATA[$P{Inform C}]]></subreportParameterExpression> 
       </subreportParameter> 
       <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource((Collection) $F{fieldA})]]></dataSourceExpression> 
       <subreportExpression><![CDATA[$P{Inform C}]]></subreportExpression> 
      </subreport> 
     </band> 
    </detail> 
    <columnFooter> 
     <band splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band splitType="Stretch"/> 
    </pageFooter> 
    <summary> 
     <band splitType="Stretch"/> 
    </summary> 
</jasperReport> 

4 - На Информ В есть секция заполнена Информ C и Inform C, поле, которое не отображается расширение:

<?xml version="1.0" encoding="UTF-8"?> 
<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="SubinformeAtribucionesPorPropietarios" pageWidth="463" pageHeight="842" columnWidth="463" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="92989482-f12d-409d-bbbc-5168396c7b22"> 
    <property name="ireport.scriptlethandling" value="0"/> 
    <property name="ireport.encoding" value="UTF-8"/> 
    <property name="ireport.zoom" value="1.9487171000000016"/> 
    <property name="ireport.x" value="0"/> 
    <property name="ireport.y" value="0"/> 
    <import value="net.sf.jasperreports.engine.*"/> 
    <import value="java.util.*"/> 
    <import value="net.sf.jasperreports.engine.data.*"/> 
    <parameter name="paramA" class="java.lang.String" isForPrompting="false"/> 
    <parameter name="paramB" class="java.lang.String" isForPrompting="false"/> 
    <field name="fieldA" class="java.lang.String"/> 
    <field name="fieldB" class="java.lang.String"/> 
    <field name="fieldC" class="java.lang.String"/> 
    <field name="fieldD" class="java.lang.String"/> 
    <field name="extension" class="java.lang.String"/> 
    <field name="fieldE" class="java.lang.String"/> 
    <field name="fieldF" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band splitType="Stretch"/> 
    </title> 
    <pageHeader> 
     <band splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band splitType="Stretch"/> 
    </columnHeader> 
    <detail> 
     <band height="17" splitType="Stretch"> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-1" mode="Transparent" x="0" y="0" width="109" height="16" forecolor="#000000" backcolor="#FFFFFF" uuid="4e1802bf-4ad3-4ed8-a378-e451866ef365"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{fieldA}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-2" mode="Transparent" x="109" y="0" width="71" height="16" forecolor="#000000" backcolor="#FFFFFF" uuid="a87c767c-8b6e-4dcf-b397-2412a752acaa"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{fieldD}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-3" mode="Transparent" x="180" y="0" width="71" height="16" forecolor="#000000" backcolor="#FFFFFF" uuid="82e3a926-8f8f-41af-b478-db4eed521356"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{fieldC}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-4" mode="Transparent" x="251" y="0" width="71" height="16" forecolor="#000000" backcolor="#FFFFFF" uuid="b8954bd1-387e-4a5d-a762-9b1c19a86a78"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{fieldB} + $F{fieldF}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-6" mode="Transparent" x="322" y="0" width="71" height="16" forecolor="#000000" backcolor="#FFFFFF" uuid="80594584-7236-407f-99b1-a5bd8b7cb91f"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{extension}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-7" mode="Transparent" x="392" y="0" width="71" height="16" forecolor="#000000" backcolor="#FFFFFF" uuid="4792a89e-5852-4fcb-9f34-510d411a3cc3"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{fieldE}]]></textFieldExpression> 
      </textField> 
     </band> 
    </detail> 
    <columnFooter> 
     <band splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band splitType="Stretch"/> 
    </pageFooter> 
    <lastPageFooter> 
     <band height="22" splitType="Stretch"> 
      <staticText> 
       <reportElement x="221" y="3" width="101" height="17" uuid="45817d74-5748-40d9-ac2a-f07baa316e7e"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Arial" size="8" isBold="true"/> 
       </textElement> 
       <text><![CDATA[Text]]></text> 
      </staticText> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-8" mode="Transparent" x="322" y="3" width="70" height="17" forecolor="#000000" backcolor="#FFFFFF" uuid="2d0cc5e5-1e50-4196-867f-a729d1c5a2f9"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.5" lineColor="#000000"/> 
        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$P{paramA}]]></textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField-9" mode="Transparent" x="392" y="3" width="71" height="17" forecolor="#000000" backcolor="#FFFFFF" uuid="19d787cb-e1df-473d-9f52-3c3aa7bed427"/> 
       <box> 
        <pen lineWidth="0.5"/> 
        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.5" lineColor="#000000"/> 
        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None"> 
        <font fontName="Arial" size="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
        <paragraph lineSpacing="Single"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$P{paramB}]]></textFieldExpression> 
      </textField> 
     </band> 
    </lastPageFooter> 
    <summary> 
     <band splitType="Stretch"/> 
    </summary> 
</jasperReport> 
+0

Вы использовали 'apache poi' lib? –

+0

Привет, Атаур, я нахожусь в проекте, и я не могу перейти на Apache Poi:/ – Aker666

+0

Это веб-проект или настольный компьютер? –

ответ

0

Я не знаю, была ли ошибка, но я скопировал строку другого выражения textFieldExpression работающего jrxml, переименовал его в значение, которое не отображалось, и теперь значение, которое оно отображает.

Какого черта ...

 Смежные вопросы

  • Нет связанных вопросов^_^