protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//  String aaa=request.getParameter("param");
//  System.out.println(aaa);
response.setContentType("application/vnd.ms-excel");

                HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");

HSSFRow  row= sheet.createRow((short)0);
HSSFCell cell= row.createCell((short)0);
cell.setCellValue(1);
row.createCell((short)1).setCellValue(1.2);
 
row.createCell((short)3).setCellValue(true);
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();
}本来想想客户端返回一个EXCEL 的,但是没什么反应?
不知道这个过程对不对?

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【wudaobugu】截止到2008-07-09 15:55:08的历史汇总数据(不包括此帖):
    发帖的总数量:19                       发帖的总分数:700                      每贴平均分数:36                       
    回帖的总数量:11                       得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:15                       结贴的总分数:560                      
    无满意结贴数:2                        无满意结贴分:100                      
    未结的帖子数:4                        未结的总分数:140                      
    结贴的百分比:78.95 %               结分的百分比:80.00 %                  
    无满意结贴率:13.33 %               无满意结分率:17.86 %                  
    楼主加油
      

  2.   

    OutputStream out = response.getOutputStream();
    wb.write(out); 
    好像不是这样的吧.
    OutputStream os =  response.getOutputStream();
    String str = "xxx";
    os.write(str.getBytes());
    这样才能向客户端返回数据的.
      

  3.   

    wb.write(out); 
    这个是不是把wb的流写到out里去,类似于某些类的writeto方法?如果是的话,应该是没错的..
    如果没反映的话,有可能是以下几点造成的,content-type不对,另外,如果是文本文件的话,最好带上charset参数.
    excel文件的mimetype应该是application/excel吧
      

  4.   

    application/msexcel,application/excel,这两个换着试下
      

  5.   

    application/msexcel *.xls *.xla Microsoft Excel Dateien 这是在网上查的...不知道对你用没.....
      

  6.   

            // 设置输出格式
            response.setContentType("application/xls");
            // 设置文件属性
            response.setHeader("Content-disposition",
                "attachment; filename=dataList.xls");
            try {
                ServletOutputStream out = response.getOutputStream();
                BeanFactory.getInstance().getTurbineTestManager().dataLoadOut(
                    title, dataList, out);
                out.flush();
                out.close();
            } catch (IOException e) {
                throw new IOException (e.toString());
            }
      

  7.   

    另外如果不行
    你最好查下你的office版本 2000 XP 2003都可以