2015-12-22 91 views
0

我有一個報告,我需要導出到pdf和xls文件。我試圖在JasperViewer中保存報告,而不用在我的Java類中顯式編寫用於導出的代碼。問題是,當我嘗試以上述方式保存時,pdf和csv正在創建與數據填充正確,但xls似乎只是空白。
我正在使用Ubuntu 14.04,但是我不認爲這會是一個問題,因爲xls格式仍然可以在Linux上打開和查看。JasperReports正確導出到csv和pdf,但不是xls

下面是我的JRXML文件

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 --> 
<!-- 2015-12-22T12:52:53 --> 
<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="_blank" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ced95029-b569-4027-895c-af2843a4e088"> 
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/> 
    <property name="net.sf.jasperreports.export.xlsx.detect.cell.type" value="true"/> 
    <style name="Title" fontName="Times New Roman" fontSize="50" isBold="true"/> 
    <style name="SubTitle" forecolor="#E50000" fontName="Arial" fontSize="18"/> 
    <style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="12" isBold="true"/> 
    <style name="Detail" fontName="Times New Roman" fontSize="12"/> 
    <style name="Row" mode="Opaque" fontName="Times New Roman" fontSize="12"> 
     <conditionalStyle> 
      <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression> 
      <style backcolor="#000000"/> 
     </conditionalStyle> 
    </style> 
    <parameter name="username" class="java.lang.String"/> 
    <field name="filePath" class="java.lang.String"/> 
    <field name="createdOn" class="java.sql.Timestamp"/> 
    <field name="actionby" class="java.lang.Integer"/> 
    <field name="actionType" class="java.lang.String"/> 
    <sortField name="createdOn"/> 
    <title> 
     <band height="136" splitType="Stretch"> 
      <staticText> 
       <reportElement style="Title" x="170" y="0" width="230" height="60" uuid="1a652692-054a-40f3-ade5-68d8da36626d"/> 
       <textElement verticalAlignment="Middle"/> 
       <text><![CDATA[Report]]></text> 
      </staticText> 
      <textField> 
       <reportElement style="SubTitle" x="219" y="62" width="300" height="22" uuid="88d4231e-f014-4b0d-b871-1737ba63a1ae"/> 
       <textElement> 
        <font fontName="Times New Roman"/> 
       </textElement> 
       <textFieldExpression><![CDATA["Activity Report of user "+$P{username}]]></textFieldExpression> 
      </textField> 
      <staticText> 
       <reportElement x="172" y="94" width="383" height="42" uuid="f0bfb1ea-a85a-47cd-a1a4-43f22b45e80f"/> 
       <textElement textAlignment="Right"> 
        <font size="10"/> 
       </textElement> 
      </staticText> 
     </band> 
    </title> 
    <pageHeader> 
     <band splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="16" splitType="Stretch"> 
      <line> 
       <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="555" height="1" uuid="1a61a836-d137-48b1-ad67-6ff64600bf93"/> 
       <graphicElement> 
        <pen lineWidth="0.5" lineColor="#999999"/> 
       </graphicElement> 
      </line> 
      <staticText> 
       <reportElement style="Column header" x="20" y="0" width="100" height="15" forecolor="#03A9F4" uuid="8093e6b6-1479-4d7e-a3e1-8b43ac16fe34"/> 
       <text><![CDATA[Date]]></text> 
      </staticText> 
      <staticText> 
       <reportElement style="Column header" x="150" y="0" width="250" height="15" forecolor="#03A9F4" uuid="c9463f8f-ce24-4798-9f83-1122da0d5f31"/> 
       <text><![CDATA[File/Folder modified]]></text> 
      </staticText> 
      <staticText> 
       <reportElement style="Column header" x="400" y="0" width="150" height="15" forecolor="#03A9F4" uuid="cfb1f8c6-3240-4393-be47-70b56eea3926"/> 
       <text><![CDATA[Action Taken]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="16" splitType="Stretch"> 
      <frame> 
       <reportElement style="Row" mode="Transparent" x="0" y="0" width="555" height="15" forecolor="#009688" uuid="a98495d8-3c8d-4fa0-81f5-30c3efc2f766"/> 
       <textField isStretchWithOverflow="true" pattern="dd-MMM-yyyy"> 
        <reportElement style="Detail" x="20" y="0" width="100" height="15" forecolor="#009688" uuid="714380ba-f273-4f2c-9a24-e01f345aeb03"/> 
        <textFieldExpression><![CDATA[$F{createdOn}]]></textFieldExpression> 
       </textField> 
       <textField isStretchWithOverflow="true"> 
        <reportElement style="Detail" x="150" y="0" width="250" height="15" forecolor="#009688" uuid="e7d518fc-f335-40ab-acc1-8858f53a806e"/> 
        <textFieldExpression><![CDATA[$F{filePath}]]></textFieldExpression> 
       </textField> 
       <textField isStretchWithOverflow="true"> 
        <reportElement style="Detail" x="400" y="0" width="150" height="15" forecolor="#009688" uuid="34a6eb4a-7c05-4129-815e-ae1153f52798"/> 
        <textFieldExpression><![CDATA[$F{actionType}]]></textFieldExpression> 
       </textField> 
      </frame> 
     </band> 
    </detail> 
    <columnFooter> 
     <band height="45" splitType="Stretch"> 
      <line> 
       <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1" uuid="fa45a887-615a-4d84-a2d7-8a2219671b3c"/> 
       <graphicElement> 
        <pen lineWidth="0.5" lineColor="#999999"/> 
       </graphicElement> 
      </line> 
     </band> 
    </columnFooter> 
    <pageFooter> 
     <band height="25" splitType="Stretch"> 
      <frame> 
       <reportElement mode="Transparent" x="-21" y="1" width="597" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" uuid="183682bc-d976-4756-83e0-6625a3f98ed1"/> 
       <textField evaluationTime="Report"> 
        <reportElement style="Column header" x="533" y="0" width="40" height="20" forecolor="#03A9F4" uuid="0193f9b3-1559-491a-8580-b6988863b6a1"/> 
        <textElement verticalAlignment="Middle"> 
         <font size="10" isBold="false"/> 
        </textElement> 
        <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> 
       </textField> 
       <textField> 
        <reportElement style="Column header" x="453" y="0" width="80" height="20" forecolor="#03A9F4" uuid="d00b105e-494b-418b-8ac9-8b1b4824f4f0"/> 
        <textElement textAlignment="Right" verticalAlignment="Middle"> 
         <font size="10" isBold="false"/> 
        </textElement> 
        <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> 
       </textField> 
       <textField pattern="EEEEE dd MMMMM yyyy"> 
        <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#03A9F4" uuid="0616f3fe-0354-456f-8911-ec30ec51a5ae"/> 
        <textElement verticalAlignment="Middle"> 
         <font size="10" isBold="false"/> 
        </textElement> 
        <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> 
       </textField> 
      </frame> 
     </band> 
    </pageFooter> 
    <summary> 
     <band splitType="Stretch"/> 
    </summary> 
</jasperReport> 

下面是我處理報表部分

java.io.InputStream in = this.getClass().getClassLoader().getResourceAsStream("com/ram/report/jasper/Report.jrxml"); 
        JasperReport jasperReport=JasperCompileManager.compileReport(in); 
        HashMap<String, Object> params = new HashMap<String, Object>(); 
        try 
        { 
         if(emp!=null) 
          params.put("username", emp.getFirstName()+" "+emp.getLastName()); 
         else 
          params=null; 
        } 
        catch(Exception e) 
        { 
         params=null; 
        } 
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params,new JRBeanCollectionDataSource(list)); 
        JasperViewer.viewReport(jasperPrint,false);     
        System.out.println("Wrote report"); 
       } 
       catch(Exception e) 
       { 
        e.printStackTrace(); 
       } 

我通過this鏈接去Java代碼片斷,但無法理解的解決方法是完成。請幫忙!

回答

0

很可能你從你的庫項目(如果你使用ant)或從你的maven repo-pom.xml(如果你使用maven)缺少Apache POI。

我沒有看到任何錯誤代碼

+0

我有POI罐子但隨後JasperReports的依賴是一箇舊版本的poi.jar的。感謝重新引導我的注意力! :) –