2017-11-06 87 views
0

Jaspersoft Studioでレポートを生成しようとしています。私の目標は、1つのレポートで2つの異なるCSVファイルを使用することです。ここで私が達成したいものです:私は2番目CSVを使用しないときJasperReportsのデータソースと異なるcsvファイル

enter image description here

すべてが正常に動作します。別のCSVを使用してテーブルを生成するときに、データセット接続を指定する必要があります(前に名前DRのデータセットを作成し、このデータセットにはCSVからの適切なデータがあります)。

enter image description here

私は接続せずとJRCsvDatasourceてみましたが、それは動作しません。私はこれを行う方法の例を発見していない。 接続テーブルが指定されていないときは空です。私はJRCsvDataSourceを追加すると、それは例外をスロー:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException:不明な列名を: FID。 (ReportController.java:596) でcom.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport(ReportController.java:596) でcom.jaspersoft.studio.editor.preview.view.control.ReportController.access $ 20(ReportController。 java:571) at com.jaspersoft.studio.editor.preview.view.control.ReportController $ 5.run(ReportController.java:449) at org.eclipse.core.internal.jobs.Worker.run(Worker。 java:55)

Jaspersoft StudioでJRCsvDataSourceの列名を設定することはできません。これは、この解決策が動作しないという本当の理由です。

したがって、テーブルとデータセット間の接続に問題があります。テーブルと新しいデータセットの間の接続を指定するには?本質的には

答えて

1

  • あなたは(私はCSV_DA_1とCSV_DA_2それらを呼ばれる)は、2つのデータアダプタ、CSVファイルごとに1つずつ必要です。
  • 最初のアダプタをレポートのメインデータセットにリンクします。
  • ファイルに2番目のファイル(CSV_DA_2.xml)をエクスポートし、テーブルデータセットのデフォルトデータアダプタをポイントします。 enter image description here この方法でのみ、Studioは両方のデータアダプタを選択します。
  • 理由はわかりませんが、queryStringの言語を表のデータセット内のcsvに手動で設定する必要がありました。

最終結果(.jrxml)は次のようになります。

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 --> 
<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="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6fe5ff80-463c-48a5-870b-b9eb72c8c9f3"> 
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="CSV_DA_1"/> 
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF"> 
     <box> 
      <pen lineWidth="0.5" lineColor="#000000"/> 
      <topPen lineWidth="0.5" lineColor="#000000"/> 
      <leftPen lineWidth="0.5" lineColor="#000000"/> 
      <bottomPen lineWidth="0.5" lineColor="#000000"/> 
      <rightPen lineWidth="0.5" lineColor="#000000"/> 
     </box> 
    </style> 
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF"> 
     <box> 
      <pen lineWidth="0.5" lineColor="#000000"/> 
      <topPen lineWidth="0.5" lineColor="#000000"/> 
      <leftPen lineWidth="0.5" lineColor="#000000"/> 
      <bottomPen lineWidth="0.5" lineColor="#000000"/> 
      <rightPen lineWidth="0.5" lineColor="#000000"/> 
     </box> 
    </style> 
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF"> 
     <box> 
      <pen lineWidth="0.5" lineColor="#000000"/> 
      <topPen lineWidth="0.5" lineColor="#000000"/> 
      <leftPen lineWidth="0.5" lineColor="#000000"/> 
      <bottomPen lineWidth="0.5" lineColor="#000000"/> 
      <rightPen lineWidth="0.5" lineColor="#000000"/> 
     </box> 
    </style> 
    <style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF"> 
     <box> 
      <pen lineWidth="0.5" lineColor="#000000"/> 
      <topPen lineWidth="0.5" lineColor="#000000"/> 
      <leftPen lineWidth="0.5" lineColor="#000000"/> 
      <bottomPen lineWidth="0.5" lineColor="#000000"/> 
      <rightPen lineWidth="0.5" lineColor="#000000"/> 
     </box> 
    </style> 
    <style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF"> 
     <box> 
      <pen lineWidth="0.5" lineColor="#000000"/> 
      <topPen lineWidth="0.5" lineColor="#000000"/> 
      <leftPen lineWidth="0.5" lineColor="#000000"/> 
      <bottomPen lineWidth="0.5" lineColor="#000000"/> 
      <rightPen lineWidth="0.5" lineColor="#000000"/> 
     </box> 
    </style> 
    <style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF"> 
     <box> 
      <pen lineWidth="0.5" lineColor="#000000"/> 
      <topPen lineWidth="0.5" lineColor="#000000"/> 
      <leftPen lineWidth="0.5" lineColor="#000000"/> 
      <bottomPen lineWidth="0.5" lineColor="#000000"/> 
      <rightPen lineWidth="0.5" lineColor="#000000"/> 
     </box> 
    </style> 
    <subDataset name="TableDataset" uuid="e4a79faf-d2c6-42ff-9afd-1b73b938e128"> 
     <property name="com.jaspersoft.studio.data.defaultdataadapter" value="different_csv/CSV_DA_2.xml"/> 
     <property name="net.sf.jasperreports.data.adapter" value="CSV_DA_2.xml"/> 
     <queryString language="csv"> 
      <![CDATA[]]> 
     </queryString> 
     <field name="fruitStand" class="java.lang.String"/> 
     <field name="fruitId" class="java.lang.String"/> 
     <field name="fruitSold" class="java.lang.Integer"/> 
    </subDataset> 
    <queryString> 
     <![CDATA[]]> 
    </queryString> 
    <field name="number" class="java.lang.Integer"/> 
    <field name="name" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="79" splitType="Stretch"/> 
    </title> 
    <pageHeader> 
     <band height="35" splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="30" splitType="Stretch"> 
      <staticText> 
       <reportElement x="0" y="0" width="278" height="30" uuid="675dfea9-c792-4aa2-b5cc-1506b6de4cf6"/> 
       <text><![CDATA[number]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="278" y="0" width="277" height="30" uuid="77fcc5b3-4d31-47bc-a682-3059757ff1fb"/> 
       <text><![CDATA[name]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="100" splitType="Stretch"> 
      <textField> 
       <reportElement x="0" y="0" width="278" height="30" uuid="aa065144-9ec4-4658-a0c5-150cdea07ae1"/> 
       <textFieldExpression><![CDATA[$F{number}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="278" y="0" width="277" height="30" uuid="5284bbc5-f1e9-47f2-9b87-a0a7f7e4011c"/> 
       <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> 
      </textField> 
      <componentElement> 
       <reportElement x="150" y="40" width="200" height="60" uuid="5e2faee2-cc09-469b-a5eb-917ddfdccbdf"> 
        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/> 
        <property name="com.jaspersoft.studio.table.style.table_header" value="Table 1_TH"/> 
        <property name="com.jaspersoft.studio.table.style.column_header" value="Table 1_CH"/> 
        <property name="com.jaspersoft.studio.table.style.detail" value="Table 1_TD"/> 
       </reportElement> 
       <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> 
        <datasetRun subDataset="TableDataset" uuid="886ce5d8-f55a-4573-8d7e-c47f04fa818f"/> 
        <jr:column width="66" uuid="f118bba1-a9b0-4b6e-91e5-b532f5ab3f86"> 
         <jr:columnHeader style="Table 1_CH" height="30"> 
          <staticText> 
           <reportElement x="0" y="0" width="66" height="30" uuid="c89e45e3-1513-44fd-932f-7dcb457fdf88"/> 
           <text><![CDATA[fruitStand]]></text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell style="Table 1_TD" height="30"> 
          <textField> 
           <reportElement x="0" y="0" width="66" height="30" uuid="b1211b0b-5321-42fd-bc44-3d13a291e1e1"/> 
           <textFieldExpression><![CDATA[$F{fruitStand}]]></textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
        <jr:column width="66" uuid="d2ad8e66-e7c8-44be-ae3d-d806bca7e9fa"> 
         <jr:columnHeader style="Table 1_CH" height="30"> 
          <staticText> 
           <reportElement x="0" y="0" width="66" height="30" uuid="d0d7dbbb-2b2c-42f2-ad18-85bbbc1e8cc7"/> 
           <text><![CDATA[fruitId]]></text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell style="Table 1_TD" height="30"> 
          <textField> 
           <reportElement x="0" y="0" width="66" height="30" uuid="b1df8795-8505-4533-8dad-d74c339bcc74"/> 
           <textFieldExpression><![CDATA[$F{fruitId}]]></textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
        <jr:column width="66" uuid="26903850-beb5-440c-bb69-4d4dc3d0f5dc"> 
         <jr:columnHeader style="Table 1_CH" height="30"> 
          <staticText> 
           <reportElement x="0" y="0" width="66" height="30" uuid="dac2afb9-0f76-4f94-b98f-0336fd2e3a05"/> 
           <text><![CDATA[fruitSold]]></text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell style="Table 1_TD" height="30"> 
          <textField> 
           <reportElement x="0" y="0" width="66" height="30" uuid="2f1f473e-04e2-4e96-a9de-a87e901c2c35"/> 
           <textFieldExpression><![CDATA[$F{fruitSold}]]></textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
       </jr:table> 
      </componentElement> 
     </band> 
    </detail> 
    <columnFooter> 
     <band height="45" splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band height="54" splitType="Stretch"/> 
    </pageFooter> 
    <summary> 
     <band height="42" splitType="Stretch"/> 
    </summary> 
</jasperReport> 

そして出力: enter image description here

関連する問題