0

We have an inhouse legacy java library to generate reports with jasper+spring and export them to html, pdf or xls. However excel files have all the cells with the same (no ) format We have one report where one column is filled with text and there is concern that it could be interpreted as formula with numeric values or some other type of code. Likewise we have strings with leading zeroes that should appear in the report. I have tried setting JExcelApiExporterParameter.IS_DETECT_CELL_TYPE to true through jasperExportParameters.

The report configuration is done through xml like the following:

<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>

How can I tell jasper to format cells with text format? is it doable at all?

This library is using jasper 4.6.0, but I could migrate if that is what is needed. Our reports have been edited with iReport 3.7.6.

dabicho
  • 383
  • 4
  • 19

1 Answers1

1

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.

Community
  • 1
  • 1