问题
I am using struts2 jQuery plugin in my project.
I use grid to display items..
How to export the items present in the grid to microsoft excel on click of a button?
回答1:
Post the List displayed by the jqGrid to an Action (let's say ExcelExportAction).
In the execute() method, create an Excel using JExcel or Apache POI.
Populate the Excel with the data from the List. Google it, it's full of examples out there.
Expose the result of the Excel through an InputStream from the Action (and its Getter).
Return SUCCESS.
Map the Success Result of the Action as Stream result type and with the excel contenttype like follow:
<action name="excelExport" class="your.package.ExcelExportAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">
attachment; filename="MyExcelName.xls"</param>
<param name="bufferSize">1024</param>
</result>
</action>
来源:https://stackoverflow.com/questions/13873088/how-to-implement-export-to-excel-functionality-in-java-struts2