Home
Analytics
Timezone issue when exporting to excel format
shalu30aug
<p>Hello everyone,</p>
<p> </p>
<p> </p>
<p>Actually I am facing an issue with timezone whenI am export my report to xlsx format. We have integrated BIRT in our application and used ReportEngine API to generate report. So in RenderTask ,i have set timezone</p>
<p>using</p>
<p> </p>
<p>renderTask.setTimeZone(<User set timezone">);</p>
<p> </p>
<p>Using this,we could generate report in all other format like html,pdf .All are changing the data according to timezone except excel format.</p>
<p> </p>
<p>Please help if any other configuration is needed or not.</p>
Find more posts tagged with
Comments
mwilliams
What is your BIRT version?
shalu30aug
<p>We are using 4.3.1 version of BIRT</p>
mwilliams
Any way you could post the code you're using so I can test on your exact code? Thanks.
shalu30aug
<p>This is the code snippet I have used to create a RenderTask and then generate the report in excel format.</p>
<p> </p>
<p>I have set the timezone which we extract based on user's timezone at runtime with the help of userid.</p>
<p> </p>
<p> </p>
<p> </p>
<p><u>IRenderTask</u></p>
<p>renderTask=engine.createRenderTask(doc, design); // doc is the rptdocument</p>
<p> </p>
<p>/*----setting the <u>timezone</u> ----*/</p>
<p> </p>
<p><b>if</b>(timeZone!=<b>null</b>){</p>
<p>TimeZone userTimeZone=TimeZone.<i>getTimeZone</i>(timeZone);//timeZone is the string e.g "Asia/Kolkata"</p>
<p>renderTask.setTimeZone(userTimeZone);</p>
<p>}</p>
<p><b>else</b>{</p>
<p>renderTask.setTimeZone(TimeZone.<i>getDefault</i>());</p>
<p>}</p>
<p> </p>
<p><strong>This part of the code is the generation of excel</strong>:</p>
<p> </p>
<p><u>HTMLRenderOption </u>options = <b>new</b> HTML<u>RenderOption</u>();</p>
<p>response.setContentType(mimeType);</p>
<p>response.setHeader("Content-Disposition", "attachment; filename=\"" + reportName ".xlsx");</p>
<p> </p>
<p>options.setBaseURL(baseUrl);</p>
<p>options.setImageHandler(<b>new</b> <u>HTMLServerImageHandler</u>());</p>
<p>options.setMasterPageContent(<b>true</b>);</p>
<p>options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF");</p>
<p>options.setOutputStream(response.getOutputStream());</p>
<p>options.setOutputFormat("xlsx");</p>
<p>options.setEmitterID("uk.co.spudsoft.birt.emitters.excel.XlsxEmitter");</p>
<p>options.setOption("ExcelEmitter.StructuredHeader", <b>true</b>); </p>
<p>options.setOutputStream(response.getOutputStream()); </p>
<p> </p>
<p>task.setRenderOption(options);</p>
<p> </p>
<p>//run the report </p>
<p>task.render();</p>
<p>task.close();</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>I have tried with</p>
<p> </p>
<p>options.setOption("timeZone" ,timeZone)</p>
<p> </p>
<p>I have also tried with EXCELRenderOption class.</p>
<p> </p>
<p>But still its not working.</p>
<p> </p>
<p>Excel is generated with different elements behaving in different ways.</p>
<p> </p>
<p>e.g Footer is generated with timestamp taking timezone in consideration but the data in the grid ,table is not showing data w.r.t timeZone.</p>
<p> </p>
<p>Please help.Its very critical.</p>
mwilliams
This works for me (executed from within Eclipse as a Java project):<br><br><pre class="_prettyXprint _lang-auto _linenums:0">
EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFileName("myReport.xlsx");
options.setOutputFormat("xlsx");
renderTask.setRenderOption(options);
TimeZone tz = TimeZone.getTimeZone("Asia/Kolkata");
renderTask.setTimeZone(tz);
renderTask.render();
</pre>
shalu30aug
<p>I have tried this code in my application....but it behaves very differently..In the footer the generated time of the report is coming according to the timezone selected but the in the table,that data fetched from database are not converter according to timezone.It is shown in the way its was saved.</p>
<p> </p>
<p>Likewise if i have used a dynamic text and generated the current time...it again is taking timezone in consideration.</p>
<p> </p>
<p>But the data in table are not taking timezone in consideration.</p>
mwilliams
Ah. My mistake. I was only looking at the footer time. I'll take a look at the database data issue in the morning.
mwilliams
This appears to be a bug with the XLS emitter. You can log the bug in the bugzilla in the community area of eclipse.org/birt. Post the bug info in here for future reference if you post one. Thanks!
shalu30aug
<p>I have logged the bug and the link to access - <a data-ipb='nomediaparse' href='
https://bugs.eclipse.org/bugs/show_bug.cgi?id=452599'>https://bugs.eclipse.org/bugs/show_bug.cgi?id=452599</a></p>
;
mwilliams
Thanks for the update!