好象是将jsp页的头设置成word格式的就可以了,具体语法我忘记了,你查查网上资料吧,反正是一定可以的~~ 设置成excel也可以!

解决方案 »

  1.   

    <%@ page contentType="application/msword;  charset=gb2312"  language="java"%>可以将页面内容转化为WORD,但如果打印中如果有图片和表格,我也没有办法处理。
      

  2.   

    将Word文件导到JSP页面
    <object id=FileDialog style="left: 0px; TOP: 0px" classid="clsid:f9043c85-f6f2-101a-a3c9-08002b2f49fb" codebase="http://activex.microsoft.com/controls/vb5/comdlg32.cab">
    </object>
    <input type=button value="打开Word文档" onclick='OpenFile()'>
    <input type=button value="HTML格式" onclick='window.confirm(App.innerHTML)'>
    <div align=left id=App style="border:1 solid #000000;background-color:#FFFFFF;height:400px;overflow:auto;width:100%;z-index:2" contentEditable></div>
    <script>
    function OpenFile()
    {
    try
    {
    FileDialog.CancelError=true;
    FileDialog.Filter="Word模板|*.doc|Word模板|*.dot";
    FileDialog.ShowOpen();
    var WordApp=new ActiveXObject("Word.Application");
    WordApp.Application.Visible=false;
    var Doc=WordApp.Documents.Open(FileDialog.filename);
    Doc.Activate();
    Doc.Parent.Options.InsertedTextColor=4;
    Doc.Parent.Options.InsertedTextMark=2;
    Doc.Parent.Options.DeletedTextColor=4;
    Doc.Parent.Options.DeletedTextMark=1;
    Doc.TrackRevisions=true;
    Doc.PrintRevisions=true;
    Doc.ShowRevisions=true;
    Doc.Application.UserName="";
    var Range=Doc.Range();
    Range.Select();
    var Selection=WordApp.Selection;
    Selection.Copy();
    App.focus();
    document.execCommand("Paste");
    App.focus();
    WordApp.DisplayAlerts=false;
    Doc.Close();
    WordApp.DisplayAlerts=true;
    WordApp.Quit();
    }
    catch(e){}
    return false;
    }
    </script>
      

  3.   

    打印
    function PrintFile()
    {
    var strResult=window.confirm("确认用Word打印吗?");
    if(strResult)
    {
    try
    {
    App.focus();
    document.execCommand("SelectAll");
    document.execCommand("Copy");
    App.focus();
    var WordApp=new ActiveXObject("Word.Application");
    WordApp.Application.Visible=true;
    var Doc=WordApp.Documents.Add();
    Doc.Activate();
    Doc.Content.Paste();
    Doc.PrintPreview();
    WordApp.DisplayAlerts=false;
    Doc.Close();
    WordApp.DisplayAlerts=true;
    WordApp.Quit();
    }
    catch(e){}
    }
    else
    {
    var hwnd=window.open("");
    hwnd.document.write(App.innerHTML);
    }
    return false;
    }
      

  4.   

    这个太难了。有人说用activeX可以,不可始终没有亲见。我写过几次。每次都试着用不同的方法,不过很遗憾,每次都是除了.doc不行外,其它的都行。如果要转换成其它格式,我可以帮你,就这个.doc我帮不上忙