Jasper reports 为什么在使用标记时XLSX中忽略样式?

Jasper reports 为什么在使用标记时XLSX中忽略样式?,jasper-reports,export-to-excel,xlsx,Jasper Reports,Export To Excel,Xlsx,我对部分文本使用粗体样式,因此它看起来像: "<style isBold = 'true'>" + $P{REPORT_RESOURCE_BUNDLE}.getString("report.label.foo") +": "+"</style>"+$F{foo} <textField> <reportElement style="moduleBorderColumnStyle" mode="Opaque" x="0" y="0" width="555"

我对部分文本使用粗体样式,因此它看起来像:

"<style isBold = 'true'>" + $P{REPORT_RESOURCE_BUNDLE}.getString("report.label.foo") +": "+"</style>"+$F{foo}
<textField>
<reportElement style="moduleBorderColumnStyle" mode="Opaque" x="0" y="0" width="555" height="20" uuid="6adbbfa7-e549-4378-903c-04095c2f34c4"/>
<textElement markup="styled"/>
<textFieldExpression><![CDATA["<style isBold = 'true'>" +
$P{REPORT_RESOURCE_BUNDLE}
.getString("report.label.foo")
+": "+"</style>"+$F{foo}]]></textFieldExpression>
</textField>
TextField标记属性-已设置样式

它适用于PDF和HTML。但是,我对XLSX使用相同的方法有问题

不幸的是,即使直接将字体大小设置为14(我以前尝试过将其从样式中设置),我也会得到整个标签的字体11 callibri(它是默认字体),这是使用标记

我在
text
和markup=HTML中尝试了相同的方法-结果没有改变

结论:XLSX中的任何样式文本对字体不敏感(将其设置为默认),如何解决此问题?

编辑:


我发现问题出在我之前申请这个
textField
的风格上,但问题仍然存在于excel中。
标记只是将其覆盖为默认字体和字体大小。

我可以确认导出到
xlsx
时存在相同的错误,样式被忽略,它似乎与为
XSSFSheet
中的单元格创建
RichTextString
有关。(不正确/没有字体设置为
RichTextString
?)

编辑:我创建了一个,标记为下一版本已解决(当前版本为v6.3.0)

复制错误的简单示例 jrxml(SimpleTest.jrxml)


@是的,我还有一个问题。我这里不使用条件样式。字体问题overwriting@PetterFriberg就在xlsx中,我认为这是一个bug,我已经测试了一些,在xlsx中(不是在xls中),如果标记与textField一起使用,样式属性将被忽略,我将看看是否可以找到解决方法,但事实上,这是一个bug。@PetterFriberg谢谢你,你有什么想法如何修复它或以其他方式解决它吗?我可以创建两个不同的文本字段,但是语言环境会很难看(不同的边距)@quento FYI:我已经打开了一个bug问题,因为我找不到任何相关的问题,jasper reports的人很好,所以他们可能会很快感谢你们发现这个bug。现在已修复,该修复将在下一个JasperReports版本中提供。@PetterFriberg如果无法删除样式属性该怎么办?@AmmarAkouri获取jasper report的最新版本,或使用poi发布详细说明,我看不到其他许多解决方案。@PetterFriberg我已经有了最新的解决方案,我的问题是,在预览模式下,颜色和文本对齐方式完全按照我希望的方式显示,但当我导出到Excel时,颜色似乎变得有点暗,文本对齐方式被忽略。我尝试了你的建议,并直接在文本字段上应用了该样式,但一点运气都没有!
<?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="SimpleTest" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="e4188d8a-c7f9-4f7d-8f0f-ada07b89d42f">
    <style name="test" mode="Transparent" forecolor="#CC0000" fontSize="14"/>
    <detail>
        <band height="20">
            <textField isStretchWithOverflow="true">
                <reportElement style="test" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="200" height="20" uuid="6d5644bf-480e-4ed2-831b-3ed043f38f70"/>
                <textElement verticalAlignment="Middle" markup="html">
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA["<b>TEST</b> TEXT"]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="test" positionType="Float" stretchType="RelativeToTallestObject" x="200" y="0" width="200" height="20" uuid="f876d0a3-136b-468c-b3bd-bd9cd5475ca9"/>
                <textElement verticalAlignment="Middle" markup="html">
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA["TEXT2"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
JasperReport report = JasperCompileManager.compileReport("SimpleTest.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(report,new HashMap<String, Object>(), new JREmptyDataSource(1));

//Export to excel xls
JRXlsExporter exporterXls = new JRXlsExporter();
File outputFile = new File("excelTest.xls");
exporterXls.setExporterInput(new SimpleExporterInput(jasperPrint));
exporterXls.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
SimpleXlsReportConfiguration configXls = new SimpleXlsReportConfiguration();
configXls.setDetectCellType(true);
configXls.setRemoveEmptySpaceBetweenColumns(true);
configXls.setRemoveEmptySpaceBetweenRows(true);
configXls.setCollapseRowSpan(true);
configXls.setWhitePageBackground(false);
exporterXls.setConfiguration(configXls);
exporterXls.exportReport();

//Export to excel xlsx
JRXlsxExporter exporterXlsx = new JRXlsxExporter();
File output = new File("excelTest.xlsx");
exporterXlsx.setExporterInput(new SimpleExporterInput(jasperPrint));
exporterXlsx.setExporterOutput(new SimpleOutputStreamExporterOutput(output));
SimpleXlsxReportConfiguration configXlsx = new SimpleXlsxReportConfiguration();
configXlsx.setDetectCellType(true);
configXlsx.setRemoveEmptySpaceBetweenColumns(true);
configXlsx.setRemoveEmptySpaceBetweenRows(true);
configXlsx.setCollapseRowSpan(true);
configXlsx.setWhitePageBackground(false);
exporterXlsx.setConfiguration(configXlsx);
exporterXlsx.exportReport();
<textField isStretchWithOverflow="true">
    <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="200" height="20" forecolor="#CC0000" uuid="6d5644bf-480e-4ed2-831b-3ed043f38f70"/>
    <textElement verticalAlignment="Middle" markup="html">
        <font size="14"/>
        <paragraph lineSpacing="Single"/>
    </textElement>
    <textFieldExpression><![CDATA["<b>TEST</b> TEXT"]]></textFieldExpression>
</textField>