在程序中要把显示的页面列表生成Excel导出,点下载的时候会弹出打开或者保存或者取消,如果是直接打开第一个显示Excel的话显示正常,但是打开第二个则Excel中的内容还是第一个Excel中的内容。但是如果把这两个Excel不是在页面上直接通过Excel打开,而是下载到本地再打开,则里面的内容是不一样的,也就是正确。不知道这是什么原因?有没有什么办法解决?

解决方案 »

  1.   

    生成excel的代码有问题吧!要不不会出现这种错误的...            out.flush();
                out.close();
      

  2.   

    你那两句我有写的,我把我源代码贴上来吧
    <%
    //生成Excel代码
    HSSFWorkbook workbook = new HSSFWorkbook();   //创建新的Excel工作薄
           HSSFSheet sheet = workbook.createSheet("合格数量");   //在Excel工作薄中建工作表,名为缺省

           HSSFRow row;
           HSSFCell cell;
           int row_id=0;
           int cell_id=0;
           row= sheet.createRow((short)0); //在索引0的位置建行(最顶端的行) 

           cell = row.createCell((short)0); //在索引0的位置建单元格
           cell.setEncoding(HSSFCell.ENCODING_UTF_16); //定义单元格为字符串类型
           cell.setCellValue("员工名称"); //在单元格输入一些内容
           cell = row.createCell((short)1); 
           cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
           cell.setCellValue("发送内容");  
           cell = row.createCell((short)2); 
           cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
           cell.setCellValue("发送短信时间");  
           cell = row.createCell((short)3); 
         
           String start_time1=" and to_date(to_char(recive_time,'yyyy-mm-dd'),'yyyy-mm-dd')>=to_date('"+start_time+"','yyyy-mm-dd')";
        String end_time1=" and to_date(to_char(recive_time,'yyyy-mm-dd'),'yyyy-mm-dd')<=to_date('"+end_time+"','yyyy-mm-dd')";

       strsql="select e.employee_id,e.employee_name,y.recive_time,y.content from employee_info e,yj_info y where e.employee_id=y.employee_id and y.employee_id = "+employee_id+" and is_qj=0 and is_ok=1  "+start_time1+end_time1;
    System.out.println(strsql);
            conn.executeQuery(strsql,rs);
            while(rs.next())
           {
          
           row_id++;
           row = sheet.createRow(row_id); //在索引1的位置创建行

           cell = row.createCell((short)0); 
           cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
           cell.setCellValue(rs.getString("employee_name")); 
           cell=row.createCell((short)1);     
           cell.setEncoding(HSSFCell.ENCODING_UTF_16);       
           cell.setCellValue(rs.getString("content"));
           cell=row.createCell((short)2);     
           cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
           cell.setCellValue(rs.getString("recive_time"));
           cell=row.createCell((short)3);     
          
           }

           String filename = "file/"+"hegeshuliang"+".xls";
           String filename_all = application.getRealPath("/")+ filename;  

    //filename是工作薄的存放位置,存放在当前应用程序的根目录下
           FileOutputStream fOut = new FileOutputStream(filename_all); //新建输出文件流
           workbook.write(fOut); //把相应的Excel工作薄存盘
           fOut.flush();
           fOut.close(); //操作结束,关闭文件 out.println("<td>已生成excel文件:<A HREF='../"+filename+"'>" + filename+ "请点右键选择另存为进行下载</A></td>");
    %>
      

  3.   

    页面缓存问题吧?把代码中的缓存设成no-cache试试!