导Excel,具有下载页面

来源:互联网 发布:北风网大数据百度云 编辑:程序博客网 时间:2024/05/16 14:50

<!--Struts-->配置

<!-- 导出报表 -->

<action name="excel" class="com.sf.action.GenerateReportAction"
method="execute">
<result name="excel" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">attachment;filename="Sales Info.xls"</param>
<param name="inputName">excelStream</param>
</result>

</action>



部分Java代码

private InputStream excelStream;//返回的excel流

public String execute()
{
GenerateReportDS generateReportDS = (GenerateReportDS) Factory
.getInstance("GenerateReportDS");
ByteArrayOutputStream out = new ByteArrayOutputStream();
generateReportDS.generateReport(reportCondition,out);
//将OutputStream转化为InputStream 
excelStream=new ByteArrayInputStream(out.toByteArray());
return "excel";
}


book=Workbook.createWorkbook(out);

out.close();