1. 首先建一Word文档模板,并预先进行相关内容填充。
2. 将Word文档另存为htm格式,如果存为筛选过的网页(html),则相关的页眉页脚等格式信息会丢失。
3. 将html的内容拷贝到Jsp页面即可。并将原先填充的内容用动态内容替换即可。
如果要以附件形式显示,则在Jsp页面中加入以下代码:
response.setContentType("application/msword");
String fileName = "JL-6-11-5市场巡查情况记录表.doc";
response.setHeader("Content-Disposition", "attachment; filename=\""
+ new String(fileName.getBytes("GBK"), "ISO8859-1") + "\"");
4. 如果存在页眉页脚信息,url如果为动态页面,需提供完整的url路径(含http前缀)。
@page {mso-mirror-margins:yes; mso-page-border-surround-header:no; mso-page-border-surround-footer:no; mso-footnote-separator:url("<%=headJsp%>") fs; mso-footnote-continuation-separator:url("<%=headJsp%>") fcs; mso-endnote-separator:url("<%=headJsp%>") es; mso-endnote-continuation-separator:url("<%=headJsp%>") ecs;}
5. 如需控制文档分页,则插入以下分页符代码:
<span lang=EN-US style='font-size:10.5pt;font-family:宋体;mso-bidi-font-family: "Times New Roman";color:red;mso-font-kerning:1.0pt;mso-ansi-language:EN-US; mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><br clear=all style='mso-special-character:line-break;page-break-before:always'> </span>