我使用Spring和iReport以excel格式生成jasper报告。一切正常,但我遇到一个问题,我在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>
答案 0 :(得分:0)
在报告jrxml中将属性net.sf.jasperreports.export.xls.white.page.background设置为true。 即。
<property name="net.sf.jasperreports.export.xls.white.page.background" value="false" />
答案 1 :(得分:0)
JRXlsExporter 在使用颜色方面有一些限制。
net.sf.jasperreports.engine.export.JRXlsExporter 的源代码片段(在此示例中,我获取了 JR 6.3.0 版本的源代码)< / p>
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 支持哪些颜色。 / p>
<?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)中,输出结果如下所示:
如果不应用<property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/>
,则生成的 xls 文件将如下所示:
带有“ JRXlsExporter支持的所有颜色”文本的 textField 文本具有backcolor="#F2F2F2"
属性(这是灰色),但是生成的文本没有背景色(颜色是白色)。
使用自定义调色板,生成的结果是:
我们可以看到,应用自定义调色板解决了 JRXlsExporter 的问题。