Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to use different number formats depending on output formats (PDF, CSV)
Paradoxx
<p>Hello!</p><p> </p><p>I need to use specific number formatting in my reports depending on output format. One number format for PDF and other number format for CSV.</p><p>Is it possible with BIRT? I think of some scripting, but don't know if BIRT provides any parameter with current output format.</p>
Find more posts tagged with
Comments
micajblock
<p>The easiest way to do this is to have two report items and set the visibility base don output. You can also use the below variable to get the output format.</p><p> </p><p>reportContext.getOutputFormat()</p>
CBR
<p>Instead of using visibility you could also implement onRender for the data element like that:</p><pre class="_prettyXprint _linenums:0">if(reportContext.getOutputFormat()=="pdf") { this.getStyle().numberFormat = "#000.00"}else if(reportContext.getOutputFormat()=="xls") { this.getStyle().numberFormat = "#000.00"}</pre><p>Why you should use onRender and not onCreate:</p><p>Using onCreate works fine if you generate the report using the single phase model (RunAndRender), but doesn't work at all using the two phases model (Run, and later on Render).</p><p>Using onRender works fine in both one and two phases model.</p><p> </p><p>Please also be aware that CSV is not a output format. There are emitters that can create report as CSV but standard BIRT features only allow you to export data as CSV which is different from output as CSV. Therefore reportContext.getOutputFormat() could never give you csv if you are not using one of these third party csv emitters.</p>
CBR
<p>Oh this also means that visibilty and event handlers can not be used to change the number format for CSV generated by export data as CSV in the webviewer.</p><p> </p><p>Are you using a custom CSV emitter?</p>
Paradoxx
<p>Thank you very much!</p><p>Yes, I use custom CSV emitter.</p>
micajblock
<p>Why do you care about the format in CSV, should it not just use the data? What is the real problem with the CSV?</p>