- ·上一篇:word字体如何下,字体
- ·下一篇:PowerPoint幻灯片重叠的图形如何选中
jsp如何转word,jsp
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;
