我们有一个内部遗留Java库,用jasper + spring生成报告,并将它们导出为html,pdf或xls。 但是,excel文件具有相同(无)格式的所有单元格 我们有一个报告,其中一列填充了文本,并且担心它可以被解释为带有数值或其他类型代码的公式。同样,我们有一些前导零的字符串应该出现在报告中。 我尝试通过jasperExportParameters将JExcelApiExporterParameter.IS_DETECT_CELL_TYPE设置为true。
报告配置通过xml完成,如下所示:
<bean id="jasperReportHeader" class="java.lang.String">
<constructor-arg>
<value>
<![CDATA[
<html>
]]>
</value>
</constructor-arg>
</bean>
<bean id="jasperExportParameters" class="java.util.HashMap">
<constructor-arg>
<map>
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN"
value="false" />
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI">
<value><![CDATA[utils.jasper?opcion=muestraImagen&image=]]></value>
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.HTML_HEADER">
<ref bean="jasperReportHeader" />
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.HTML_FOOTER">
<ref bean="jasperReportFooter" />
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRCsvExporterParameter.FIELD_DELIMITER"
value="|" />
<entry
key="net.sf.jasperreports.engine.export.JExcelApiExporterParameter.IS_DETECT_CELL_TYPE"
value="true" />
</map>
</constructor-arg>
</bean>
<bean id="jasperReportFooter" class="java.lang.String">
<constructor-arg>
<value>
<![CDATA[
</html>
]]>
</value>
</constructor-arg>
</bean>
<!-- REPORTES -->
<bean id="solicitudRevisionView"
class="mx.org.rfe.ife.siirfe.comun.web.spring.views.jasper.CustomJasperReportsMultiFormatView">
<property name="url" value="/WEB-INF/reportes/SOLICITUD_REVISION.jasper" />
<property name="exporterParameters" ref="jasperExportParameters" />
</bean>
如何告诉jasper格式化文本格式的单元格? 它可以吗?
这个库正在使用jasper 4.6.0,但如果需要,我可以迁移。 我们的报告已使用iReport 3.7.6进行编辑。
答案 0 :(得分:0)
Jasperreports won't interpret your cells to be formulas unless you tell it that they are so. On the other hand, I guess your exporter parameters are not set properly with the map declaration fed into CustomJasperReportsMultiFormatView
. Instead of the map declaration, I'd expect something more like
<bean id="solicitudRevisionView"
class="mx.org.rfe.ife.siirfe.comun.web.spring.views.jasper.CustomJasperReportsMultiFormatView">
<property name="url" value="/WEB-INF/reportes/SOLICITUD_REVISION.jasper" />
<property name="exporterParameters">
<props>
<prop name="net.sf.jasperreports.export.xls.detect.cell.type">true</prop>
</props>
</property>
as the Java constants in your spring xml configuration file, like net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN
, won't be evaluated unless you do it in a different way.