请教大师们一个问题,关于JAVA导出Excel问题:         public String exportExcel() throws Exception{

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
filename=simpleDateFormat.format(new Date())+".xls";
this.getTargetInputStream();
return SUCCESS;
} public InputStream getTargetInputStream() throws Exception{

List exportDataList = getExportDataList(); //从数据库中得到要加在Excel表格中的数据

//创建一个EXCEL
HSSFWorkbook wb = new HSSFWorkbook();

//创建一个SHEET
HSSFSheet sh1 = wb.createSheet();
String[] title = {"单位编号","//这里还有一系列的title名字,不列出了"}
                  short i = 0;
HSSFFont font = wb.createFont();
font.setBoldweight((short)12);
font.setFontHeight((short)12);
font.setFontHeightInPoints((short)12);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFont(font);

//创建一行
HSSFRow row = sh1.createRow((short)0);

//填充标题
for(String s : title){
HSSFCell cell = row.createCell(i);
cell.setCellValue(s);
cell.setCellStyle(cellStyle);
i++;
}
for (int j = 0; j < exportDataList.size(); j++) {
Pz19DTO pz = (Pz19DTO) exportDataList.get(j);
HSSFRow row1 = sh1.createRow((short)j+1);

HSSFCell cell = row1.createCell((short) 0);//单位编号
cell.setCellStyle(cellStyle);
cell.setCellValue(pz.getAab001()); //下面是一些列设值操作。
                  }

ByteArrayOutputStream fo = new ByteArrayOutputStream();
wb.write(fo);
byte[] by = fo.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(by);
if(fo!=null){
fo.close();
}
return in;
       }
配置文件:<action name="exportExcel"    class="primaryObjectOfAuditAction" method="exportExcel">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="inputName">targetInputStream</param>
<param name="contentDisposition">
attachment;filename="${filename}"
</param>
<param name="bufferSize">100000</param>
</result>
</action>
点击页面上的导出按钮时:提示错误如下:消息: 由于出现错误 c00ce514 而导致此项操作无法完成。
行: 81
字符: 346
代码: 0
URI: http://localhost:8080/e3/ca96515/extjs/base/ext-core.js
我在我jsp页面中写的js是:
        //导出
function exExcel(){
    url="${pageContext.request.contextPath}/e3/f21010404/exportExcel.action";
             Wssip.util.request(url,'post');  //是否此处有问题???? }

解决方案 »

  1.   

    js 出了问题  你的调用没有对 换种方式请求action试试
      

  2.   


    换成window.location.href = url;
    下载的是一个不可读的文件类型,文件名称:exportExcel
      

  3.   

    应该是js调用的问题,window.location.href或者windows.open试试看吧
      

  4.   


    换成window.location.href = url; he window.open
    都出现如下情况:
    下载的是一个不可读的文件类型,文件名称:exportExcel 
     
      

  5.   

    把 action 里面的 result标签去掉,空着就可以了。输出流应该是这个response.getOutputStream()。还不行,我给你发个例子吧。
      

  6.   


    给我也发一个呀,[email protected]