51,410
社区成员
发帖
与我相关
我的任务
分享
<?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="report3" language="groovy" columnDirection="RTL" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryWithPageHeaderAndFooter="true" uuid="7790bc54-1ac2-4d8b-9398-c1491925a7a8">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="Dataset1" resourceBundle="$P{datasource}" uuid="8ddf6f3a-0cfe-4b8b-a5f0-9093d53dbbc5">
<field name="f1" class="java.lang.String"/>
<field name="f2" class="java.lang.String"/>
<field name="f3" class="java.lang.String"/>
<field name="f4" class="java.lang.String"/>
<field name="f5" class="java.lang.String"/>
</subDataset>
<parameter name="datasource" class="net.sf.jasperreports.engine.data.JRMapCollectionDataSource" isForPrompting="false"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["E:\\JasperWorkSpace\\"]]></defaultValueExpression>
</parameter>
<queryString language="json">
<![CDATA[qNaire.uAnswer]]>
</queryString>
<field name="field1" class="java.lang.String"/>
<field name="field2" class="java.lang.String"/>
<field name="field3" class="java.lang.String"/>
<field name="field4" class="java.lang.String"/>
<field name="field5" 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="61" splitType="Stretch">
<staticText>
<reportElement uuid="daa42969-7955-4ed2-8d9d-9cf02991251a" x="0" y="0" width="100" height="61"/>
<textElement/>
<text><![CDATA[name]]></text>
</staticText>
<staticText>
<reportElement uuid="bc54e53f-3d89-42ef-8979-2855e1cd6870" x="100" y="30" width="45" height="31"/>
<textElement/>
<text><![CDATA[male]]></text>
</staticText>
<staticText>
<reportElement uuid="05f03285-1d4d-4239-a0ea-11a21b6c7318" x="100" y="0" width="100" height="30"/>
<textElement/>
<text><![CDATA[性别]]></text>
</staticText>
<staticText>
<reportElement uuid="4d238a1d-6020-45ad-a8d4-e5408d0848f2" x="145" y="30" width="55" height="31"/>
<textElement/>
<text><![CDATA[female]]></text>
</staticText>
<staticText>
<reportElement uuid="44cdf3bb-e563-4d44-8651-f16d292dd8cb" x="200" y="0" width="113" height="30"/>
<textElement/>
<text><![CDATA[question1]]></text>
</staticText>
<staticText>
<reportElement uuid="9676997c-f89c-443d-a5a4-d3f18bd0bb9b" x="200" y="30" width="55" height="31"/>
<textElement/>
<text><![CDATA[answer1]]></text>
</staticText>
<staticText>
<reportElement uuid="35781f69-0ce0-4fe7-ae83-b9a91ce6e067" x="255" y="30" width="58" height="31"/>
<textElement/>
<text><![CDATA[answer2]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<textField>
<reportElement uuid="954f2668-22d8-42e5-bdde-86206eec01fe" x="0" y="0" width="100" height="40"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="433b8460-660a-4b23-846e-01db8ec493dd" x="100" y="0" width="45" height="40"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1c9461b7-6520-41ab-9699-940a7dbb9fad" x="145" y="0" width="55" height="40"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="20438769-75ba-4eeb-9018-4e98742b1ec6" x="200" y="0" width="55" height="40"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field4}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="9078471e-7ed6-407f-beaa-9427d7066cad" x="255" y="0" width="58" height="40"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field5}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
public static void main(String[] args) {
try {
JasperDesign design = JRXmlLoader
.load("jasper/report3.jrxml");
InputStream is=new ByteArrayInputStream(JSONSource.json.getBytes());
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put("net.sf.jasperreports.json.source", JSONSource.json);
paramsMap.put("JSON_INPUT_STREAM", is);
paramsMap.put(JsonQueryExecuterFactory.JSON_LOCALE, Locale.ENGLISH);
paramsMap.put(JRParameter.REPORT_LOCALE, Locale.US);
// compile the report
JasperReport report = JasperCompileManager.compileReport(design);
// fill it with our data
JasperPrint print = JasperFillManager.fillReport(report, paramsMap,
new JREmptyDataSource());
// view the report with the built-in viewer
JasperViewer.viewReport(print);
} catch (JRException e) {
e.printStackTrace();
}
}
{"qNaire": {
"uAnswer": [
{
"field1": "030-0074321", // nonstandard unquoted field name
"field2": 12209, // nonstandard single-quoted field name
"field3": "Maria Anders", // standard double-quoted field name
"field4": "030-0076545",
"field5": "Obere Str. 57",
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"Country": "Germany",
"City": "Berlin",
"ContactTitle": "Sales Representative"
},
{
"field1": "(5) 555-4729",
"field2": 5021,
"field3": "Ana Trujillo",
"field4": "(5) 555-3745",
"field5": "Avda. de la Constitución 2222",
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados",
"Country": "Mexico",
"City": "México D.F.",
"ContactTitle": "Owner"
}
]
}}
public class JSONSource {
public final static String json=
"{\"qNaire\":{\"uAnswer\":[{\"field1\":\"pp\",\"field2\":\"男\",\"field3\":\"0\",\"field4\":\"TTT\",\"field5\":\"0\"}," +
"{\"field1\":\"yy\",\"field2\":\"0\",\"field3\":\"女\",\"field4\":\"0\",\"field5\":\"YYY\"}]}}";
}