代码之家  ›  专栏  ›  技术社区  ›  learner420

将报表导出为html格式

  •  0
  • learner420  · 技术社区  · 10 年前

    我正在使用 JasperReports API 在浏览器上打印报告。我有很多格式可以导出报告,但我主要关注的是HTML。我使用以下代码将报告导出为HTML:

    JRExporter exporter = null;
    exporter = new JRHtmlExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
    exporter.exportReport();
    

    此代码将输出打印如下(即使我的jrxml文件中没有图像):

    sample report

    日食 向我表明JRExporter已被弃用,我做了一些研究,发现现在我们使用“Exporter”进行出口。我正在尝试在代码中使用Exporter来删除此错误,但无论如何都找不到,我可以将jasperPrint文件写入输出流。

    新代码:

    Exporter exporter = null;
    exporter = new HtmlExporter();
    

    http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/HtmlExporter.html#exportReportToWriter()

    我在jrxml中的一些代码如下:

    <title>
            <band height="79" splitType="Stretch">
                <staticText>
                    <reportElement x="219" y="28" width="194" height="40" uuid="44028360-543f-4352-a028-9e262bb24347"/>
                    <textElement>
                        <font size="24"/>
                    </textElement>
                    <text><![CDATA[Project Report]]></text>
                </staticText>
            </band>
        </title>
        <columnHeader>
            <band height="61" splitType="Stretch">
                <staticText>
                    <reportElement x="119" y="41" width="100" height="20" uuid="1f6ca9e9-92d5-41e5-9e8d-cd6ede8bfa25"/>
                    <text><![CDATA[Project Status]]></text>
                </staticText>
                <staticText>
                    <reportElement x="0" y="41" width="100" height="20" uuid="6059b496-7ff9-4156-836b-f91436b8e79c"/>
                    <text><![CDATA[Aldon Number]]></text>
                </staticText>
            </band>
        </columnHeader>
    
    2 回复  |  直到 10 年前
        1
  •  1
  •   FIFA oneterahertz    8 年前

    首先不要使用 JRHtmlExporter() 。已弃用。我在使用 HtmlExporter() 。然后我开始使用以下语句:

    import net.sf.jasperreports.engine.export.HtmlExporter;
    // ...
    HtmlExporter exporter = new HtmlExporter();
    

    我的HTML编码是

    HtmlExporter exporter = new HtmlExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); 
    exporter.exportReport(); 
    
        2
  •  0
  •   navya bhushan    9 年前

    尝试与JRXhtmlExporter()一起使用;

    JRExporter exporter = new JRXhtmlExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
    exporter.exportReport();