jsp页面的数据怎样保存在word中,页面上是那种柱状图,用
<%
response.setHeader("Content-disposition","attachment;filename=result.doc");//Word
 %>
根本不显示图片,怎么回事呀?

解决方案 »

  1.   

    word 
    我一般是先用word做个模板,另存为网页后,用代码替换相应的标识后保存为doc文件的。
    而且这样无法保存图片。excel
    可以如楼主那样导出xsl文件,因为有这样的组件,-----------------------------------------------
    <%@ page language = "java" contentType="text/html; charset=GBK" %><%@ page language = "java" import = "java.util.*,org.apache.poi.hssf.usermodel.HSSFWorkbook,org.apache.poi.hssf.usermodel.HSSFSheet,org.apache.poi.hssf.usermodel.HSSFRow,org.apache.poi.hssf.usermodel.HSSFCell " %><%@ page import="java.sql.Connection" %><%@ page import="pandy.db.DBConnector" %><%@ page import="fish.search.dwcx" %><%@ page import="java.sql.ResultSet" %><%@ page import="java.sql.Statement" %><%  if(session.getAttribute("dwyhzh")==null){
       out.println("<script>alert('登陆超时,请重新登陆');window.location='dwlogin.jsp';</script>");
       
       } else {
            Connection conn = DBConnector.getconecttion(); //得到一个数据连接
            try {
                String type = request.getParameter("type");
                if(type==null)type="a";
                String dwyhzh = (String) session.getAttribute("dwyhzh");
                dwcx dwcx1 = new dwcx();
                //int k = dwcx1.zgzs(conn, dwyhzh);
     response.setContentType("application/vnd.ms-excel");//设置正确的输出类型
      if(type.equals("a")){
                response.setHeader("Content-Disposition", "attachment; filename=" + dwyhzh + ".xls");}
                String sql="SELECT * FROM v_168_info WHERE dwyhzh = '" + dwyhzh + "' and zhzt!=2 ORDER BY zgyhzh asc";
                if(type.equals("b")){
                sql= "SELECT * FROM v_168_info WHERE dwyhzh = '" + dwyhzh + "' and zhzt!=2 and len(sfzhm)<1 ORDER BY zgyhzh asc";
     response.setHeader("Content-Disposition", "attachment; filename=" + dwyhzh + "-no-sfz.xls");
                }
                if(type.equals("c")){
                sql= "SELECT * FROM v_168_info WHERE dwyhzh = '" + dwyhzh + "' and zhzt!=2 and len(gjjkh)<1 ORDER BY zgyhzh asc";
              response.setHeader("Content-Disposition", "attachment; filename=" + dwyhzh + "-no-gjjkh.xls");
    }//out.print("<script>alert('aaa');</script>");
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery(sql);
               // java.text.DecimalFormat dff = new java.text.DecimalFormat(".##");
                //if(rs.next())  {                      HSSFWorkbook wb = new HSSFWorkbook();
                HSSFSheet sheet = wb.createSheet("sheet1");            // 以下以写表头
                // 表头为第一行
                HSSFRow row = sheet.createRow((short) 0);            HSSFCell cell1 = row.createCell((short) 0);
                HSSFCell cell2 = row.createCell((short) 1);
                HSSFCell cell3 = row.createCell((short) 2);
                HSSFCell cell4 = row.createCell((short) 3);
                HSSFCell cell5 = row.createCell((short) 4);
                HSSFCell cell6 = row.createCell((short) 5);
                HSSFCell cell7 = row.createCell((short) 6);
                HSSFCell cell8 = row.createCell((short) 7);
                HSSFCell cell9 = row.createCell((short) 8);
                HSSFCell cell10 = row.createCell((short) 9);            cell1.setEncoding((short) 1);
                cell1.setCellType(1);
                cell2.setEncoding((short) 1);
                cell2.setCellType(1);
                cell3.setEncoding((short) 1);
                cell3.setCellType(1);
                cell4.setEncoding((short) 1);
                cell4.setCellType(1);
                cell5.setEncoding((short) 1);
                cell5.setCellType(1);
                cell6.setEncoding((short) 1);
                cell6.setCellType(1);
                cell7.setEncoding((short) 1);
                cell7.setCellType(1);
                cell8.setEncoding((short) 1);
                cell8.setCellType(1);
                cell9.setEncoding((short) 1);
                cell9.setCellType(1);
                cell10.setEncoding((short) 1);
                cell10.setCellType(1);            // 定义表头的内容
                cell1.setCellValue(" 单位帐号 ");
                cell2.setCellValue(" 职工帐号 ");
                cell3.setCellValue(" 姓名 ");
                cell4.setCellValue(" 身份证 ");
                cell5.setCellValue(" 卡号 ");
                cell6.setCellValue(" 工资 ");
                cell7.setCellValue(" 个人缴存 ");
                cell8.setCellValue(" 余额 ");
                cell9.setCellValue(" 缴至月份 ");
                cell10.setCellValue(" 缴存状态 ");
               // sheet.setColumnWidth((short)1,(short)15);
                 sheet.setColumnWidth((short)0,(short)3000);
                sheet.setColumnWidth((short)1,(short)3000);
                sheet.setColumnWidth((short)3,(short)5000);
                  sheet.setColumnWidth((short)4,(short)5000);
                  sheet.setColumnWidth((short)8,(short)3000);
                int i = 0;
                String temp;  String kkk="";
                     // rs.first();
                while (rs.next()) {                // 定义数据从第二行开始
                    switch(rs.getInt("zhzt")){
                                case 0:kkk="停缴"; break;
                                case 1:kkk="缴交";  break;
                                    case 2:kkk="销户"; break;
                    }
                    temp = rs.getString("zgwym");
                    row = sheet.createRow((short) i + 1);
                    cell1 = row.createCell((short) 0);
                    cell2 = row.createCell((short) 1);
                    cell3 = row.createCell((short) 2);
                    cell4 = row.createCell((short) 3);
                    cell5 = row.createCell((short) 4);
                    cell6 = row.createCell((short) 5);
                    cell7 = row.createCell((short) 6);
                    cell8 = row.createCell((short) 7);
                    cell9 = row.createCell((short) 8);
                    cell10 = row.createCell((short) 9);
                    cell1.setEncoding((short) 1);
                    cell1.setCellType(1);
                    cell2.setEncoding((short) 1);
                    cell2.setCellType(1);
                    cell3.setEncoding((short) 1);
                    cell3.setCellType(1);
                    cell4.setEncoding((short) 1);
                    cell4.setCellType(1);
                    cell5.setEncoding((short) 1);
                    cell5.setCellType(1);
                    cell6.setEncoding((short) 1);
                    cell6.setCellType(1);
                    cell7.setEncoding((short) 1);
                    cell7.setCellType(1);
                    cell8.setEncoding((short) 1);
                    cell8.setCellType(1);
                    cell9.setEncoding((short) 1);
                    cell9.setCellType(1);
                    cell10.setEncoding((short) 1);
                    cell10.setCellType(1);                // 填充内容                cell1.setCellValue(rs.getString("dwyhzh"));
                    cell2.setCellValue(rs.getString("zgyhzh"));
                    cell3.setCellValue(rs.getString("zgxm"));
                    cell4.setCellValue(rs.getString("sfzhm"));
                    cell5.setCellValue(rs.getString("gjjkh"));
                    cell6.setCellValue(rs.getDouble("ygz"));
                    cell7.setCellValue(rs.getDouble("zgyje"));
                    cell8.setCellValue(dwcx1.zhye(conn, temp));
                    cell9.setCellValue(rs.getString("jzny"));
                    cell10.setCellValue(kkk);
                    i++;
                }
                wb.write(response.getOutputStream());
                response.getOutputStream().flush();
                response.getOutputStream().close();
                //}else{
                            //}
            stmt.close();
                rs.close();response.flushBuffer();
    out.clear();
               out = pageContext.pushBody();
            } catch (Exception e) { 
                e.printStackTrace();
            } finally {
                DBConnector.freecon(conn); //释放数据库连接
            }
        }
    %>
      

  2.   

    楼主是想用 word 打开这个文件吧<%@ page contentType="application/msword; charset=gb2312" %> 加上试试
      

  3.   

    都不行,我试了,都不好使呀,用excel根本就是空白,什么也没有
      

  4.   

    <%@ page contentType="application/msword; charset=gb2312" %>