How to export data to Excel form a portlet?
I need to develop a portlet from which I can export data to Excel. The data keept in a HashMap are presented in a table format, when portlet in VIEW mode. When pressing an "Export" button I would like to be presented with a popup asking if I want to Open / Save the Excel file or Cancel the operation.
The Java code I am using in a JSP is :
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
// attachment - since we don't want to open
// it in the browser, but
// with MS-Excel, and set the
// default file name to use.
StringBuffer recordString = new StringBuffer();
String str = recordString.toString();
But unfortunatelly I get an exception:
2007.01.23 16:03:50.906 E com.ibm.wps.services.dispatcher.DispatcherServiceImpl handleRequest
java.lang.IllegalStateException: Writer already obtained
Can anyone help me please with some piece of code or an workaround for solving this issue?
Thanks in advance.
Re: How to export data to Excel form a portlet?
Maybe you'd like to look at Jakarta POI which is an API for handling Excel files in Java. It's very easy to use. Then you could just return the document you have created, without using the printwriter.
have a look at [url]http://jakarta.apache.org/poi/[/url]