• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Export to excel - in Struts 2

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/vnd.ms-excel</param>
<param name="inputName">inputStream</param>
<param name="bufferSize">4096</param>
</result>
</action>

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);

//ADD STUFF TO SHEET

workbook.write();
workbook.close();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags.

What *does* happen?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rohit,

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

Thanks
Jiggs
 
reply
    Bookmark Topic Watch Topic
  • New Topic