Clarity

  • 1.  Dates in Jaspersoft when exporting to excel

    Posted Oct 31, 2016 02:20 PM
      |   view attached

    While using Dates in Ad hoc, the dates come out correctly and sort correctly in excel, no data manipulation is needed.

     

    On the other hand, I can't seem to get the dates to come out correctly in Jaspersoft once we export the data to excel when using a formatted date from a Jaspersoft studio report, the date is not sorting correctly or needs to be formatted again after the data is in excel. 

     

    Using the format within the expression of the report:

    DateFormat.getDateInstance(DateFormat.SHORT, $P{REPORT_LOCALE}).format($F{START_DATE})

     

    When exporting to excel, we get:

     

    Using Ad Hoc report and then exporting, we get (m/d/yy)

     

    How do i get the same results as Ad Hoc?  i don't believe its the formatting, persay, because I also tried the "ad hoc" format and got the same results after export. 

     

    I have opened a ca case but it's been since Sept 16th and nothing has been solved yet. Anyone have any ideas i can try please? Please note that i have tried different formatting... if anyone is interested, here is the date test jrxml file.

     

    The expected results should be the same behavior as the ad hoc report after exporting to excel. 

     

    Thanks!

     

    Keri 

    Attachment(s)



  • 2.  Re: Dates in Jaspersoft when exporting to excel
    Best Answer

    Posted Nov 01, 2016 09:03 PM

    I figured it all out. 

     

    Don't use anything in the expression except the date field . 

    ie. $F{PRSTART}

     

    For the date column: make sure to set to "java.util.Date"

    ie. <field name="PRSTART" class="java.util.Date"/>

     

    Within the detail section of jrxml, set the pattern. Also the alignment if you want.

    <detail>
    <band height="39">

    ...

    ...

    <textField pattern="MM/dd/yyyy" isBlankWhenNull="true">
       <reportElement style="Detail" x="645" y="0" width="99" height="30" uuid="7f2bf696-b1e1-4f14-82c4-c88eee13fd89"/>
       <textElement textAlignment="Center" verticalAlignment="Middle"/>
       <textFieldExpression><![CDATA[$F{PRSTART}]]></textFieldExpression>
    </textField>

     

    When exporting to excel, it will achieve the desired results being type Custom with date formatting and sorting works perfectly.

     

    Hope this helps someone else. 

     

    Keri