2

我正在使用 Spring 和 iReport 以 excel 格式生成碧玉报告。一切正常,但我有一个问题,我的报告在 iReport 中的背景颜色是灰色的,但我在生成的 Excel 文件中出现紫色色调。

我将 Create Custom Palette 设置为 true,但它仍然没有任何效果。

我的 Jrxml:

<?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="Charges Applicable" pageWidth="792" pageHeight="612" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Empty" >
    <property name="net.sf.jasperreports.export.xls.white.page.background" value="false"/>
    <subDataset name="Table Dataset 1" >
        <parameter name="ContractId" class="java.lang.String"/>
        <parameter name="VersionNo" class="java.lang.String"/>
        <queryString>
            <![CDATA[SELECT S.TERM_COMMENTS FROM FCM_TX_TERMINATION_CHARGE_T S
    WHERE S.CONTRACT_ID=$P{ContractId} AND S.VERSION_NO=$P{VersionNo}]]>
        </queryString>
        <field name="TERM_COMMENTS" class="java.lang.String"/>
    </subDataset>
    <parameter name="ContractId" class="java.lang.String"/>
    <parameter name="VersionNo" class="java.lang.String"/>
    <queryString>
        <![CDATA[SELECT F.OFFSET_ABLE_AGAINST_SLA_FLAG SLA_PENALTY_APPLICABLE
     FROM FCM_TX_BASIC_CONTRACT_DTLS_T F
     WHERE F.CONTRACT_ID=$P{ContractId} AND F.VERSION_NO=$P{VersionNo}]]>
    </queryString>
    <field name="SLA_PENALTY_APPLICABLE" class="java.lang.String"/>
    <summary>
        <band height="120" splitType="Stretch">
            <crosstab>
                <reportElement x="0" y="0" width="352" height="30" />
                <rowGroup name="SLA_PENALTY_APPLICABLE" width="200">
                    <bucket class="java.lang.String">
                        <bucketExpression><![CDATA[$F{SLA_PENALTY_APPLICABLE}]]></bucketExpression>
                    </bucket>
                    <crosstabRowHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <textField>
                                <reportElement positionType="Float" stretchType="RelativeToBandHeight" mode="Opaque" x="0" y="0" width="200" height="30" backcolor="#C9D9E7" />
                                <textElement textAlignment="Left" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" isBold="true"/>
                                </textElement>
                                <textFieldExpression><![CDATA["Is SLA Penalty Applicable"]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabRowHeader>
                    <crosstabTotalRowHeader>
                        <cellContents/>
                    </crosstabTotalRowHeader>
                </rowGroup>
                <columnGroup name="SLA_PENALTY_APPLICABLE1" height="0">
                    <bucket class="java.lang.String">
                        <bucketExpression><![CDATA[$F{SLA_PENALTY_APPLICABLE}]]></bucketExpression>
                    </bucket>
                    <crosstabColumnHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <textField>
                                <reportElement x="0" y="0" width="0" height="0" />
                                <textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabColumnHeader>
                    <crosstabTotalColumnHeader>
                        <cellContents/>
                    </crosstabTotalColumnHeader>
                </columnGroup>
                <measure name="SLA_PENALTY_APPLICABLEMeasure" class="java.lang.String">
                    <measureExpression><![CDATA[$F{SLA_PENALTY_APPLICABLE}]]></measureExpression>
                </measure>
                <crosstabCell width="100" height="30">
                    <cellContents>
                        <textField isBlankWhenNull="true">
                            <reportElement x="0" y="0" width="100" height="30" />
                            <textElement textAlignment="Left" verticalAlignment="Middle">
                                <font fontName="Arial" size="8"/>
                            </textElement>
                            <textFieldExpression><![CDATA[( $V{SLA_PENALTY_APPLICABLEMeasure}=="Y" ? "YES" : "NO" )]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell height="25" rowTotalGroup="SLA_PENALTY_APPLICABLE">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <textField>
                            <reportElement x="0" y="0" width="50" height="25" />
                            <textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLEMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell width="50" columnTotalGroup="SLA_PENALTY_APPLICABLE1">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <textField>
                            <reportElement x="0" y="0" width="50" height="25" />
                            <textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLEMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell rowTotalGroup="SLA_PENALTY_APPLICABLE" columnTotalGroup="SLA_PENALTY_APPLICABLE1">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <textField>
                            <reportElement x="0" y="0" width="50" height="25" />
                            <textFieldExpression><![CDATA[$V{SLA_PENALTY_APPLICABLEMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
            </crosstab>
            <componentElement>
                <reportElement key="table" positionType="Float" x="0" y="60" width="180" height="60"/>
                <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="Table Dataset 1" >
                        <datasetParameter name="ContractId">
                            <datasetParameterExpression><![CDATA[$P{ContractId}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="VersionNo">
                            <datasetParameterExpression><![CDATA[$P{VersionNo}]]></datasetParameterExpression>
                        </datasetParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="180" >
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement positionType="Float" mode="Opaque" x="0" y="0" width="180" height="30" backcolor="#C9D9E7" />
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Comments]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30" rowSpan="1">
                            <textField isBlankWhenNull="true">
                                <reportElement positionType="Float" x="0" y="0" width="180" height="30" />
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="Arial" size="8" isBold="false"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{TERM_COMMENTS}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
            <staticText>
                <reportElement mode="Opaque" x="0" y="40" width="180" height="20" backcolor="#C9D9E7"/>
                <textElement>
                    <font fontName="Arial" isBold="true"/>
                </textElement>
                <text><![CDATA[Temination charges for convenience]]></text>
            </staticText>
        </band>
    </summary>
</jasperReport>
4

2 回答 2

0

在报告 jrxml 中将属性 net.sf.jasperreports.export.xls.white.page.background 设置为 true。IE

<property name="net.sf.jasperreports.export.xls.white.page.background" value="false" />
于 2013-10-09T20:35:38.343 回答
0

绘制彩色文本的奇怪行为的原因

JRXlsExporter在使用颜色方面有一些限制。

net.sf.jasperreports.engine.export.JRXlsExporter的源代码片段(我在这个示例中使用了JR 6.3.0版本的源代码)

public void exportText(JRPrintText textElement, JRExporterGridCell gridCell, int colIndex, int rowIndex) throws JRException {
    JRStyledText styledText = getStyledText(textElement);

    if (styledText == null) {
        return;
    }

    short forecolor = getWorkbookColor(textElement.getForecolor()).getIndex();

    TextAlignHolder textAlignHolder = getTextAlignHolder(textElement);
    short horizontalAlignment = getHorizontalAlignment(textAlignHolder);
    short verticalAlignment = getVerticalAlignment(textAlignHolder);
    short rotation = getRotation(textAlignHolder);

    short mode = backgroundMode;
    short backcolor = whiteIndex;
    if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null) {
        mode = HSSFCellStyle.SOLID_FOREGROUND;
        backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex();
    }

使用“错误”颜色的原因在于同一类的getWorkbookColor(Color)方法:

protected HSSFColor getWorkbookColor(Color awtColor) {
    byte red = (byte)awtColor.getRed();
    byte green = (byte)awtColor.getGreen();
    byte blue = (byte)awtColor.getBlue();
    HSSFColor color = null;

    if (getCurrentConfiguration().isCreateCustomPalette()) {
        try {
            color = palette.findColor(red,green, blue) != null
                ? palette.findColor(red,green, blue)
                : palette.addColor(red,green, blue);
        } catch(Exception e) {
            if(customColorIndex < MAX_COLOR_INDEX) {
                palette.setColorAtIndex(customColorIndex, red, green, blue);
                color = palette.getColor(customColorIndex++);
            } else {
                color = palette.findSimilarColor(red, green, blue);
            }
        }
    }

    return color == null ? getNearestColor(awtColor) : color;
}

颜色是在getNearestColor(Color)方法的帮助下定义的:

protected HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = hssfColorsCache.get(awtColor);        
    if (color == null) {
        int minDiff = Integer.MAX_VALUE;
        for (Map.Entry<HSSFColor, short[]> hssfColorEntry : hssfColorsRgbs.entrySet()) {
            HSSFColor crtColor = hssfColorEntry.getKey();
            short[] rgb = hssfColorEntry.getValue();

            int diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen()) + Math.abs(rgb[2] - awtColor.getBlue());

            if (diff < minDiff) {
                minDiff = diff;
                color = crtColor;
            }
        }

        hssfColorsCache.put(awtColor, color);
    }
    return color;
}

如果Apache POI库的org.apache.poi.hssf.util.HSSFColor类的支持颜色列表中不存在元素的颜色(背景色),则将使用“最近”颜色。

对于灰色(例如,#F2F2F2),最接近的颜色可以是白色。在这种情况下, JRXlsExporter将绘制带有白色背景色的文本,而忽略textField元素的原始背景色。

JRXlsxExporter没有这个问题。

如何解决问题?

我们可以看到getWorkbookColor方法有这个检查:

if (getCurrentConfiguration().isCreateCustomPalette()) {

如果我们可以打开自定义调色板怎么办?是的,这将解决我们的问题 - 在这种情况下,将应用原始颜色。

我们可以借助net.sf.jasperreports.export.xls.create.custom.palette属性或借助 Java API 启用自定义调色板。SimpleXlsExporterConfiguration.setCreateCustomPalette (Boolean)方法将执行与net.sf.jasperreports.export.xls.create.custom.palette属性相同的操作。

工作示例

我从HSSFColor类中获取 Excel 中标准调色板的颜色,并准备jrxml演示JRXlsExporter开箱即用支持哪些颜色。

<?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="All supported colours by JRXlsExporter" pageWidth="960" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="960" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" >
    <property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <title>
        <band height="210">
            <staticText>
                <reportElement positionType="Float" mode="Opaque" x="0" y="10" width="960" height="25" forecolor="#000000" backcolor="#F2F2F2" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[All supported colours by JRXlsExporter]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#000000" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[BLACK]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#993300" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[BROWN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#333300" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[OLIVE_GREEN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#003300" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[DARK_GREEN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#003366" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[DARK_TEAL]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#000080" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[DARK_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#333399" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[INDIGO]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="0" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#333333" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[GREY_80_PERCENT]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF6600" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[ORANGE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#808000" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[DARK_YELLOW]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#008000" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[GREEN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#008080" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[TEAL]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#0000FF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#666699" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[BLUE_GREY]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#808080" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[GREY_50_PERCENT]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="160" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF0000" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[RED]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF9900" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIGHT_ORANGE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#99CC00" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIME]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#339966" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[SEA_GREEN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#33CCCC" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[AQUA]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#3366FF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIGHT_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#800080" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[VIOLET]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#969696" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[GREY_40_PERCENT]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="320" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF00FF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[PINK]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FFCC00" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[GOLD]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="70" width="160" height="20" forecolor="#000000" backcolor="#FFFF00" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[YELLOW]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="90" width="160" height="20" forecolor="#000000" backcolor="#00FF00" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[BRIGHT_GREEN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="110" width="160" height="20" forecolor="#000000" backcolor="#00FFFF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[TURQUOISE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#800000" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[DARK_RED]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#00CCFF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[SKY_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="170" width="160" height="20" forecolor="#FFFFFF" backcolor="#993366" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[PLUM]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="480" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#C0C0C0" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[GREY_25_PERCENT]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="50" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF99CC" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[ROSE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="70" width="160" height="20" forecolor="#000000" backcolor="#FFFF99" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIGHT_YELLOW]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="90" width="160" height="20" forecolor="#000000" backcolor="#CCFFCC" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIGHT_GREEN]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="110" width="160" height="20" forecolor="#000000" backcolor="#CCFFFF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIGHT_TURQUOISE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="130" width="160" height="20" forecolor="#000000" backcolor="#99CCFF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[PALE_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="150" width="160" height="20" forecolor="#FFFFFF" backcolor="#CC99FF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LAVENDER]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="170" width="160" height="20" forecolor="#000000" backcolor="#FFFFFF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[WHITE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="640" y="190" width="160" height="20" forecolor="#FFFFFF" backcolor="#9999FF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[CORNFLOWER_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="50" width="160" height="20" forecolor="#000000" backcolor="#FFFFCC" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LEMON_CHIFFON]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="70" width="160" height="20" forecolor="#FFFFFF" backcolor="#7F0000" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[MAROON]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="90" width="160" height="20" forecolor="#FFFFFF" backcolor="#660066" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[ORCHID]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="110" width="160" height="20" forecolor="#FFFFFF" backcolor="#FF8080" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[CORAL]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="130" width="160" height="20" forecolor="#FFFFFF" backcolor="#0066CC" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[ROYAL_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="150" width="160" height="20" forecolor="#000000" backcolor="#CCCCFF" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[LIGHT_CORNFLOWER_BLUE]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="800" y="170" width="160" height="20" forecolor="#000000" backcolor="#FFCC99" />
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[TAN]]></text>
            </staticText>
        </band>
    </title>
</jasperReport>

JSS(Jaspersoft Studio),输出结果如下所示:

JSS 预览

不应用<property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/>生成的xls文件将是这样的:

导出到没有自定义调色板的 xls 文件的结果

带有“JRXlsExporter 支持的所有颜色”文本的textField具有backcolor="#F2F2F2"属性(这是灰色),但生成的文本没有背景色(颜色为白色)。

使用自定义托盘生成的结果是:

使用自定义调色板导出到 xls 文件的结果

正如我们所见,应用自定义调色板已经解决了JRXlsExporter的问题。

于 2019-05-04T14:37:44.687 回答