当前位置:首页经验技巧Word经验word办公

jsp如何转word,jsp

2026-01-10 10:15:39

1.如何把JSP中的内容转化为WORD文档形式

可以利用table把试卷输出,然后利用JavaScript保存此表格为Word文档。

//下面代码为引用论坛其他人的回复,自己没测试过

App为表格ID,你调用一下SaveAs函数.

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;

}

2.如何将JSP页面显示的内容导出到WORD文档

JSP页面显示的内容导出到WORD文档:

<%response.setContentType("application/msword;charset=UTF-8");

response.setHeader("Content-Disposition","attachment;filename=test.doc"); //用word打开页面

%>

<html>

<body>

<table>

<tr>

<td>8888</td>

</tr>

</table>

</body>

</html>

3.jsp导出到word

jsp输出word

在页面直接打开word。

在Action中写

response.reset();

response.setContentType("application/msword;charset=GBK");

response.setHeader("Content-Disposition", "inline;filename=temp.doc");

response.getOutputStream().write(document.getContent());

response.getOutputStream().flush();

response.getOutputStream().close();

return null;

在页面时下载word。

在Action中写

response.reset();

response.setContentType("application/x-download;charset=GBK");

response.setHeader("Content-Disposition", "attachment;filename=temp.doc");

response.getOutputStream().write(document.getContent());

response.getOutputStream().flush();

response.getOutputStream().close();

return null;


电脑版

免责声明:本站信息来自网络收集及网友投稿,仅供参考,如果有错误请反馈给我们更正,对文中内容的真实性和完整性本站不提供任何保证,不承但任何责任,谢谢您的合作。
版权所有:五学知识网 Copyright © 2015-2026 All Rights Reserved .