你可以用APACHE上的POI接口包完成该功能。

解决方案 »

  1.   

    http://jakarta.apache.org/poi/index.html
      

  2.   

    sidshen(阿布) :如何保存为word(.doc)格式??
      

  3.   

    只要把contentType改成application/msword就可以了
    具体实现这样,用表单提交个action参数到后面的页面,后面页面判断action,如果是要打印,就response.setContentType("application/msword");
    这样,当前页面就成了word文档了
      

  4.   

    sidshen(阿布) :还是不明白,能不能结合我给的实例说明一下>谢谢
      

  5.   

    说明:
    print_head目录中为要打印内容。传递两个参数type和print
    type控制显示的内容是什么格式,如果type="word",那么就把文档的格式改为word格式,否则是text/html,print控制显示什么内容<%@ page contentType="text/html; charset=GBK" %>
    <%@ page language="java" import="java.sql.*" %>
    <%@ page import="java.util.*" %>
    <%@ include file="include/beans.jsp"%>
    <%@ include file="include/chk.jsp"%>
    <%String print=request.getParameter("print");
    String type=request.getParameter("type");
    if("word".equals(type))
      response.setContentType("application/msword");
    String isNone=null;
    String yanzheng_month=request.getParameter("yanzheng_month");
    int aa=0;
    int cc=0;
    String yanche_month=request.getParameter("yanche_month");
    int bb=0;
    String sql=null;
    ResultSet rs=null;
    if(print.equals("driver_all")){
    %>
    <%@ include file="print_head/driver_all.inc"%>
    <%
    }
    if(print.equals("driver_yanzheng")){
      if(yanzheng_month.equals("")||yanzheng_month==null)
        out.print("传入参数不正确!");
      else{
      aa=Integer.parseInt(yanzheng_month);
    %>
    <%@ include file="print_head/driver_yanzheng.inc"%>
    <%
    }}
    if(print.equals("car_all")){
    %>
    <%@ include file="print_head/car_all.inc"%>
    <%}
    if(print.equals("car_yanche")){
      if(yanche_month.equals("")||yanche_month==null)
        out.print("传入参数不正确!");
      else{
      bb=Integer.parseInt(yanche_month);
    %>
      <%@ include file="print_head/car_yanche.inc"%>
    <%
      }
    }if(print.equals("repair_all")){
    %>
      <%@ include file="print_head/repair_all.inc"%>
    <%
    }
    if(print.equals("accident_all")){
    %>
      <%@ include file="print_head/accident_all.inc"%>
    <%
    }
    %>
      

  6.   

    把你的方法结合我下面的网页<html>
    <head>
    <title>save</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgColor=#FFFFFF text="#996666">
    <FORM name=clock action="" method=""><table width="50%" border="1" align="center" cellspacing="0" bordercolor="#3399FF" cellpadding="0">
      <tr>
        <td>
          <table width="100%" border="0" bordercolor="#33FFFF">
              <td>
                <table width="100%" border="0">
                  <tr>
                    <td width="52%" height="19">
                      <div align="right">Shipper =</div>
                    </td>
                    <td width="48%" height="19">DAIMLERCHRYSLER CORP</td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                <table width="100%" border="0">
                  <tr>
                      <td width="47%">&nbsp;</td>
                      <td width="53%"> 
                        <input type="submit" name="Submit" value="SAVE">
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    </FORM>
    </body>
    </html>
      

  7.   

    这样只要一点save就会把当前页面转换为word格式
    <%@ page contentType="text/html; charset=GBK" %>
    <%
    String type=request.getParameter("type");
    if("word".equals(type))
      response.setContentType("application/msword");
    %>
    <html>
    <head>
    <title>save</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgColor=#FFFFFF text="#996666">
    <FORM name=clock action="?type=word" method="get"><table width="50%" border="1" align="center" cellspacing="0" bordercolor="#3399FF" cellpadding="0">
      <tr>
        <td>
          <table width="100%" border="0" bordercolor="#33FFFF">
              <td>
                <table width="100%" border="0">
                  <tr>
                    <td width="52%" height="19">
                      <div align="right">Shipper =</div>
                    </td>
                    <td width="48%" height="19">DAIMLERCHRYSLER CORP</td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                <table width="100%" border="0">
                  <tr>
                      <td width="47%">&nbsp;</td>
                      <td width="53%"> 
                        <input type="submit" name="Submit" value="SAVE">
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    </FORM>
    </body>
    </html>
      

  8.   

    一个地方改错了,你把form的method改为post就好了
      

  9.   

    不对!一没有保存文件对话框,二也根本没有实质的反映(没有产生.doc文件),只是IE地址栏多了一个什么"type=word".:(
      

  10.   

    程序在我这里运行就可以打印,要不你把<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    这一行去掉
      

  11.   

    你访问一下这个页面
    http://61.170.213.29:8080/sssc/print.jsp