在ConvertToWord plugin jar
中,我在类路径中添加了<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2015-09-08T12:45:28 -->
<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="num" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7a5c9b49-9dc5-422a-ac69-e92cf61ef530">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample1"/>
<style name="Title" forecolor="#FFFFFF" fontName="Times New Roman" fontSize="50" isBold="false"/>
<style name="SubTitle" forecolor="#CCCCCC" fontName="Times New Roman" fontSize="18" isBold="false"/>
<style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true"/>
<style name="Detail" mode="Transparent" fontName="Times New Roman"/>
<style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style mode="Opaque" backcolor="#F0EFEF"/>
</conditionalStyle>
</style>
<scriptlet name="REPORT" class="com.reporter.jasper.ConvertToWord"/>
<queryString>
<![CDATA[select * from userntow]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="salary" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="id" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="salary1" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{salary}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="102" splitType="Stretch">
<image>
<reportElement x="725" y="0" width="77" height="102" uuid="651ccc4b-e999-40fe-bcbf-1f25bcfc98af"/>
<imageExpression><![CDATA["cherry.jpg"]]></imageExpression>
</image>
<frame>
<reportElement mode="Opaque" x="0" y="0" width="721" height="66" backcolor="#000000" uuid="d8d9e644-3a32-491d-97cb-a277aff17133"/>
<staticText>
<reportElement style="Title" x="0" y="0" width="370" height="66" uuid="27d8f6ee-f0a9-44f6-a160-1763c3b00f30"/>
<box topPadding="4" leftPadding="4" bottomPadding="4" rightPadding="4"/>
<textElement verticalAlignment="Bottom">
<font isBold="false"/>
</textElement>
<text><![CDATA[Cherry Title]]></text>
</staticText>
<staticText>
<reportElement style="SubTitle" x="370" y="37" width="316" height="29" uuid="cfa21334-0634-4605-9ea7-aca4981f67e4"/>
<textElement textAlignment="Right">
<font size="22" isBold="false"/>
</textElement>
<text><![CDATA[Cherry SubTitle]]></text>
</staticText>
</frame>
<frame>
<reportElement mode="Opaque" x="0" y="70" width="721" height="32" forecolor="#000000" backcolor="#CC0000" uuid="b0c895f6-6dbd-477d-9858-9ad66af087e1"/>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="553" y="12" width="144" height="20" forecolor="#FFFFFF" uuid="a33fce3b-20c1-4696-873a-fe134d1e7d88"/>
<textElement textAlignment="Right">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="18" splitType="Stretch">
<staticText>
<reportElement style="Column header" x="0" y="0" width="265" height="18" forecolor="#000000" uuid="06a70999-03a2-403a-994e-a387a021b4ef"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[name]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="265" y="0" width="265" height="18" forecolor="#000000" uuid="57af4e0f-b095-441d-b0b7-2727312ffc03"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[salary]]></text>
</staticText>
<staticText>
<reportElement style="Column header" x="530" y="0" width="265" height="18" forecolor="#000000" uuid="f0a7d2a9-5d50-46fe-874b-9b7849393693"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[id]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" splitType="Stretch">
<frame>
<reportElement style="Row" mode="Opaque" x="0" y="0" width="797" height="18" uuid="34a2ae4b-4055-476b-8676-d499f6af510b"/>
<textField isStretchWithOverflow="true">
<reportElement style="Detail" positionType="Float" x="0" y="0" width="265" height="18" uuid="cfbfb7f7-04e0-42c6-86eb-aa91a4fc8c12"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement style="Detail" positionType="Float" x="265" y="0" width="265" height="18" uuid="9434a0ca-26d2-4603-8812-dad5452b3522"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{salary}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement style="Detail" positionType="Float" x="530" y="0" width="265" height="18" uuid="ffb6b7cd-2a48-4a39-9d75-57e199d9105b"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
<columnFooter>
<band height="7" splitType="Stretch">
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1" uuid="501ac6c4-e9d4-43cb-ba6b-7f2f44394cf3"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
</line>
</band>
</columnFooter>
<pageFooter>
<band height="25" splitType="Stretch">
<frame>
<reportElement mode="Opaque" x="0" y="0" width="802" height="25" forecolor="#D0B48E" backcolor="#000000" uuid="ffb10ec8-0371-4545-8eaa-96d62ad3cec0"/>
<textField evaluationTime="Report">
<reportElement style="Column header" x="757" y="3" width="40" height="20" forecolor="#FFFFFF" uuid="b5521ea6-5f36-4864-856f-58d0bcd011f2"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Column header" x="677" y="3" width="80" height="20" forecolor="#FFFFFF" uuid="e625ea3c-1741-4cfe-81cf-fbbdd00162c8"/>
<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="2" y="3" width="197" height="20" forecolor="#FFFFFF" uuid="0c9f7e91-d3f5-47f9-82b7-0b2b3a43a5d6"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
</band>
</pageFooter>
<summary>
<band height="36" splitType="Stretch">
<textField>
<reportElement x="240" y="3" width="380" height="30" uuid="c1a499d4-5e1d-4f70-8af4-63f891465a18"/>
<textElement>
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{REPORT_SCRIPTLET} .readNumber($V{salary1})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="140" y="3" width="100" height="30" uuid="d160f515-04c1-4725-aae4-1b5ac1e49b59"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{salary1}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
,用于将数字转换为单词并创建了scriplet,在引用Jasperstudio教程后,在scriplet属性中包含了完全限定的类名。
num.jrxml文件
$P{REPORT_SCRIPTLET} .readNumber($V{salary1}).
用于将数字转换为我添加的单词的TextField表达式是
readNumber
其中public class Music {
private String Artist;
private String[] Songs;
public Music MarilynManson(){
setArtist("MM");
setSongs(new String[220]);
//How to set ID of songs?
}
public Music Slipknot(){
setArtist("Slipknot");
setSongs(new String[200]);
//How to set IDs of songs?
}
public String getArtist() { return Artist; }
public void setArtist(String artist) {Artist = artist; }
public String[] getSongs() { return Songs; }
public void setSongs(String[] songs) {
Songs = songs;
}
public static void main(String args[]) {}
是我导入的ConvertToWord类中的方法。
Jasperstudio没有从导入的jar中识别方法并得到以下编译错误。
对于JRAbstractScriplet类型,未定义methodreadNumber(Integer)。
答案 0 :(得分:0)
参数和方法之间不应该有任何空格,它应该是这样的
$P{REPORT_SCRIPTLET}.readNumber($V{salary1})
有关ConvertToWord的更多信息,请访问this文档。