日期:2014-05-19  浏览次数:20796 次

struts 导出excel的问题,在线等!
小弟做了个导出,可是怎么都弄不出自定义保存地址来,请大家指导一下啊
这是我的配置文件及代码:
<action name="excel" class="com.nbc.message.client.action.ExportMessageAction">  
  <result name="excel" type="stream">  
  <param name="contentType">application/vnd.ms-excel</param>  
  <param name="inputName">excelStream</param>  
  <param name="contentDisposition">attachment;filename=" ${fileName}.xls"</param>  
  <param name="bufferSize">1024</param>  
  </result>  
  </action>  
页面 
<body>
<h1>导出</h1>
<form action="<%=request.getContextPath()%>/send/excel.action" method="post" >

<input name="submit" type="submit" value="submit" /></form>
</form>

</body>
代码;
public InputStream getExcelInputStream() throws IOException {
HSSFWorkbook hk = new HSSFWorkbook();
HSSFSheet hssfSheet = hk.createSheet("new sheet");
HSSFRow hRow = hssfSheet.createRow(0);
HSSFCell cell = hRow.createCell(0);
cell.setCellValue("中国");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
hk.write(bs);
ByteArrayInputStream asArrayInputStream = new ByteArrayInputStream(bs.toByteArray());
return asArrayInputStream;  


}

------解决方案--------------------
getExcelInputStream
改成
getInputStream

<param name="contentDisposition">attachment;filename=" ${fileName}.xls"</param> 
文件名写死试试看?
<param name="contentDisposition">attachment;filename="output.xls"</param>