Jump to content
We've recently updated our Privacy Statement, available here ×

Excel currency formatting


domurtag

Recommended Posts

Hi,

 

When I export my report to Excel, the following warning appears in each cell containing a monetary amount:

 

"The number in this cell is formatted as text or preceded by an apostrophe"

 

In an effort to get Excel to recognise the contents of these cells as currency amounts, I've added the pattern "$ #,##0.00" to the corresponding <reportElement> in the .jrxml file. I've also added the export parameter:

 

net.sf.jasperreports.engine.export.JRXlsExporterParameter.IS_DETECT_CELL_TYPE=true

 

Although the values look like monetary amounts when displayed in Excel, they are obviously stored as strings, which causes those annoying warnings to appear. Does anyone knows how to persuade Excel that these cells contain monetary amounts?

 

Thanks in advance,

domurtag

Post edited by: domurtag, at: 2008/07/04 12:44

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

I found this post which describes:

How to format these cells

[/ul]

Unfortunately, this approach is still not working for me. Here's an example of a report detail field that I would like to be stored as a currency-formatted number in Excel:

Code:
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
<reportElement style="currency" x="1034" y="0" width="71" height="17" forecolor="#000000" key="textField"/>
<box/>
<textElement textAlignment="Right">
<font size="12"/>
</textElement>
<textFieldExpression class="java.math.BigDecimal">$F{sale}</textFieldExpression>
</textField>

The 'currency' style referenced above is defined thus:

Code:
[code]<style name="currency" pattern="$ #,##0.00" isDefault="false"/>

 

I've also added the following exporter parameters:

Code:
[code]JExcelApiExporter exporter = new JExcelApiExporter();
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.True);
Map numberFormats = new HashMap();
numberFormats.put("$ #,##0.00", "$#,##0.00;-$#,##0.00"«»);
exporter.setParameter(JRXlsExporterParameter.FORMAT_PATTERNS_MAP, numberFormats);

However, Excel is still storing these fields as strings, what am I doing wrong?

 

Thanks in advance,

domurtag

Post edited by: domurtag, at: 2008/07/04 18:53

Link to comment
Share on other sites

  • 6 months later...
  • 2 months later...
  • 8 months later...
  • 4 weeks later...

Sorry,

I still have the same problem.

Was the solution set the "net.sf.jasperreports.export.xls.detect.cell.type" property in jrxml file?

I see this problem only in jasper 3.0 (poi-3.0). In jasper 1.3 (poi-2.0) works well.

In really, I would like to solve this problem in my java project, not in jrxml file.

Thanks for any response?

[]'s

Cris.



Post Edited by cris_rufino at 01/08/2010 19:07
Link to comment
Share on other sites

Solved problem ;-)

Setting IS_AUTO_DETECT_CELL_TYPE=true and IS_DETECT_CELL_TYPE=false make jasper 3.0.0 behavior equal jasper before 2.0.3, when the default value of IS_AUTO_DETECT_CELL_TYPE have changed, acording to chagelog file:

JasperReports 2.0.3 (2007-12-12)

- the default value of the deprecated JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE exporter parameter is now "false"; the newer IS_DETECT_CELL_TYPE exporter parameter should be used to control the cell types in the generated XLS documents.

[]'s Cris



Post Edited by cris_rufino at 01/11/2010 17:04
Link to comment
Share on other sites

  • 2 years later...
  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...