This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes Export to excel - in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Export to excel - in Struts 2" Watch "Export to excel - in Struts 2" New topic

Export to excel - in Struts 2

Rohit Rai
Ranch Hand

Joined: Aug 04, 2008
Posts: 53
Hi !
I have the following in my testapplication.xml

<action name="exportPlanToExcel" class="com.manageme.action.ExportToExcelAction">
<result name="success" type="stream">
<param name="contentType">application/</param>
<param name="inputName">inputStream</param>
<param name="bufferSize">4096</param>

And the action class is as follows:

public class ExportToExcelAction extends ActionSupport implements ServletRequestAware,ServletResponseAware,SessionAware

public String execute() throws Exception{
inputStream = getExcelInputStream();
return SUCCESS;

public InputStream getExcelInputStream() {
return new ByteArrayInputStream(exportExcel().toByteArray());

private ByteArrayOutputStream exportExcel() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
response.setHeader("Content-disposition", "attachment; filename=" + "MyFile.xls");
try {
WritableWorkbook workbook = Workbook.createWorkbook(bos);
WritableSheet sheet = workbook.createSheet("Contactos", 0);
WritableCellFormat textFormat = new WritableCellFormat(NumberFormats.TEXT);


} catch (RowsExceededException e) {
} catch (WriteException e) {
} catch (IOException e) {
return bos;


The following code does not give any error but the expected Save As / Open dialogue does not come up.

What may i be doing wrong?
Please help
David Newton

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.

What *does* happen?
jiggs ray

Joined: Mar 25, 2011
Posts: 1
Hi Rohit,

It must have been long time since you posted it. By any chance do you have the solution for it.

It is sorta covered in the JavaRanch Style Guide.
subject: Export to excel - in Struts 2
It's not a secret anymore!