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)
Trouble creating EXCEL file using API
Abdel
Hi all,
In my application i am not use BIRT viewer for a particular report. Customers need to directly download this report and I have the below code to do so:
IReportRunnable design;
ServletContext sc = request.getSession().getServletContext();
this.birtReportEngine = BirtEngine.getBirtEngine(sc);
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setBaseImageURL(request.getContextPath()+"/images");
renderContext.setImageDirectory(sc.getRealPath("/images"));
logger.log(Level.FINE, "image directory " + sc.getRealPath("/images"));
System.out.println("stdout image directory " + sc.getRealPath("/images"));
HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();
contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
try {
design = birtReportEngine.openReportDesign( sc.getRealPath("/report")+"/"+"listExport.rptdesign");
IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(design);
task.setAppContext(contextMap);
String filename = "SVC_Export.xls";
response.setContentType("application/excel");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat(EXCELRenderOption.OUTPUT_FORMAT_HTML);
options.setOutputStream(response.getOutputStream());
options.setOutputFileName(filename);
task.setRenderOption(options);
task.run();
task.close();
}catch (Exception e){
e.printStackTrace();
throw new ServletException( e );
}
Unfortunatly, the downloaded file is not named the SVC_Export.xls instead, I get a file named same as the servlet and not as excel file. If i rename the file after downloading it.. it opens up good in EXCEL.. How can I solve this.
Also please check if my rendering options are correct?
Please advice, thanks in advance,
Abdel Olakara
Find more posts tagged with
Comments
There are no comments yet