【问题标题】:Excel export cell background colorExcel 导出单元格背景颜色
【发布时间】:2014-09-12 14:55:53
【问题描述】:

我正在使用 iReport 5.6,当我在 iReport 中为表格预览中的单元格设置条件格式时工作正常

当我保存为 xls 文档时,表格显示为单元格着色并且值在单元格中,但它们(值)不显示。如果我将单元格颜色设置为正常,我可以看到这些值。任何想法如何解决它。在 Excel 或 iReport 中(最好)?

我的 xml

    <?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="test_tabelegrafi" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.4641000000000006"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="92"/>
    <style name="table" lineSpacing="Single">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF" lineSpacing="Single">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF" lineSpacing="Single">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF" lineSpacing="Single">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="barva_rdeca" mode="Transparent" forecolor="#000000" backcolor="#FFFFFF" lineSpacing="Single" pattern="">
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{count} > 100]]></conditionExpression>
            <style mode="Opaque" backcolor="#FF0000" fill="Solid" lineSpacing="Single"/>
        </conditionalStyle>
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{count} <= 100]]></conditionExpression>
            <style mode="Opaque" backcolor="#00CC33" fill="Solid" lineSpacing="Single"/>
        </conditionalStyle>
    </style>
    <subDataset name="New Dataset 2">
        <queryString>
            <![CDATA[select
    o_teacher,
    o_class,
    o_location,
    count(*)
     from outputs_txt
     where o_date between  '2014-05-30' and '2014-06-30' and o_class != '' and o_location is not null
 group by o_teacher, o_class,o_location
order by  o_class,o_teacher
limit 10]]>
        </queryString>
        <field name="o_teacher" class="java.lang.String"/>
        <field name="o_class" class="java.lang.String"/>
        <field name="o_location" class="java.lang.String"/>
        <field name="count" class="java.lang.Long"/>
    </subDataset>
    <subDataset name="Graf">
        <queryString>
            <![CDATA[select
    o_teacher,
    o_class,
    o_location,
    count(*)
 from outputs_txt
 where o_date between  '2014-05-30' and '2014-06-30' and o_class != '' and o_location is not null
 and o_location IN ('tel1','tel2', 'tel3')
     group by o_teacher, o_class,o_location
order by  o_class,o_teacher
limit 10]]>
        </queryString>
        <field name="o_teacher" class="java.lang.String"/>
        <field name="o_class" class="java.lang.String"/>
        <field name="o_location" class="java.lang.String"/>
        <field name="count" class="java.lang.Long"/>
    </subDataset>
    <queryString>
        <![CDATA[select
    o_teacher,
    o_class,
    o_location,
    count(*)
 from outputs_txt
 where o_date between  '2014-05-30' and '2014-06-30' and o_class != '' and o_location is not null
     group by o_teacher, o_class,o_location
    order by  o_class,o_teacher
limit 10]]>
    </queryString>
    <field name="o_teacher" class="java.lang.String"/>
    <field name="o_class" class="java.lang.String"/>
    <field name="o_location" class="java.lang.String"/>
    <field name="count" class="java.lang.Long"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="154" y="0" width="234" height="38"/>
                <textElement textAlignment="Center" lineSpacing="Single">
                    <font size="14"/>
                </textElement>
                <text><![CDATA[TESTNI REPORT TABEL IN GRAFOV]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="287" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="barva_rdeca" stretchType="RelativeToBandHeight" x="0" y="0" width="555" height="118"/>
                <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="New Dataset 2">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement lineSpacing="Single"/>
                                <text><![CDATA[o_teacher]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement lineSpacing="Single"/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$F{o_teacher}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement lineSpacing="Single"/>
                                <text><![CDATA[o_class]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center" lineSpacing="Single"/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$F{o_class}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement lineSpacing="Single"/>
                                <text><![CDATA[o_location]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center" lineSpacing="Single"/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$F{o_location}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement lineSpacing="Single"/>
                                <text><![CDATA[count]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement style="barva_rdeca" x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center" lineSpacing="Single" markup="none"/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$F{count}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
            <bar3DChart>
                <chart>
                    <reportElement positionType="Float" x="0" y="141" width="555" height="146"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <categoryDataset>
                    <dataset>
                        <datasetRun subDataset="Graf">
                            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        </datasetRun>
                    </dataset>
                    <categorySeries>
                        <seriesExpression><![CDATA[$F{o_location}]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{o_teacher}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{count}]]></valueExpression>
                    </categorySeries>
                </categoryDataset>
                <bar3DPlot>
                    <plot/>
                    <itemLabel/>
                    <categoryAxisFormat>
                        <axisFormat/>
                    </categoryAxisFormat>
                    <valueAxisFormat>
                        <axisFormat/>
                    </valueAxisFormat>
                </bar3DPlot>
            </bar3DChart>
        </band>
    </pageHeader>
    <columnHeader>
        <band splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band splitType="Stretch"/>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

【问题讨论】:

  • 请分享一份报告和数据以重现或至少是一个样本结果。
  • 我添加了excel的xml和图片
  • 当我保存为 xls 文档时 - 你在哪里做的?从预览器启动的 Excel 实例?我试过了,但我总是在那一栏中得到可读的数字。 (不过,我不得不更改数据源,因为我显然没有您的数据库作为后端。)
  • 我运行预览并保存-->一张 xls。值在单元格中,但看不到。此外,如果我设置了一个 Excel 公式来引用该字段,则该值再次不会显示。大声笑我猜:-)
  • 啊,好的,我明白了,即使我仍在使用 iReport 4.5.1,我也可以重现。您是否尝试过从preview 菜单中选择 XLS 或 XSLX 预览并刷新/重新运行预览生成?这会创建一个与预览平行的 xls(x),在我的情况下,xls(x) 中的数字是可见的。

标签: excel formatting jasper-reports


【解决方案1】:

我能找到的唯一解决方案是,在导出后,我选择了 Excel 中的单元格并将类型更改为数字或其他自定义类型。

【讨论】:

  • 它只是说自定义。我尝试在 ireport 中更改为 double、integer 等,但在 excel(自定义)中始终相同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-12
  • 2015-11-29
  • 1970-01-01
  • 2017-09-17
  • 2017-06-19
  • 2017-05-02
相关资源
最近更新 更多