我正在使用JRXlsxExporter
将JasperReport导出为XLSX格式。为了创建输出流,我打开一个Blob流并将其设置为SimpleOutputStreamExporterOutput
。然后,在调用exporter.exportReport()
方法之后,将Blob保存到DB。
OutputStreamExporterOutput simpleOutputStreamExporterOutput = new SimpleOutputStreamExporterOutput(blob.setBinaryStream(1));
问题是,报告内容中包含jpg图片部分。将报告导出到XLSX时,xlsx中会显示“无法显示图像”消息,而不是图像,但其余数据显示正常。
我尝试使用FileOutputStream
代替Blob流,并且包括图像在内的所有内容在导出的xlsx中都显示良好。但是,由于我无法将导出的报告文件保存在应用程序服务器上,并且由于我必须以blob的形式写入数据库,因此我绝对希望使用blob流。
我正在使用DynamicReportBuilder addFirstPageImageBanner()
方法添加图像。
任何帮助深表感谢。谢谢!
根据要求,这是我的jrxml文件的一部分。
<title>
<band height="30"/>
</title>
<pageHeader>
<band height="141">
<textField>
<reportElement x="0" y="78" width="290" height="78"/>
<textElement>
<font fontName="Times New Roman"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{reportInfo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="58" width="290" height="20"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{reportType}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="38" width="290" height="20"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{reportTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="290" height="38"/>
<textElement>
<font fontName="Times New Roman" size="18" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
这是添加图像的代码:
drb.addFirstPageImageBanner("imagepath" + "imagename", new Integer(197), new Integer(53), ImageBanner.ALIGN_LEFT);
You can display images in XLS by click
-> report properties
-> advanced
-> edit properties
and search for :
net.sf.jasperreports.export.xls.ignore.graphic
and mark it as false
it will fix the problem ..