一、word模板,sourceTemplate.doc,存放在web项目webRoot/template/目录下面
二、代码
response.reset();
response.setContentType("application/x-msdownload");
response.addHeader("Content-Disposition","attachment;filename=xsjbxx_dr.doc");
String sourceDocUrl= request.getSession().getServletContext().getRealPath("template//sourceTemplate.doc");
Document doc = new Document(sourceDocUrl);
doc.getRange().replace("$requre_unit$","这是填充到模板请购单为处的信息");
//剩下的把所有的字段进行替换
OutputStream output = response.getOutputStream();
doc.save(output, SaveFormat.DOC);
output.flush();
output.close();
附加:aspose破解方法
一、将下面三行代码插入web启动时执行
InputStream is = InitServlet.class.getClassLoader().getResourceAsStream("//license.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
二、将license.xml文件放入web项目资源根目录,license.xml内容如下
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>23dcc79f-44ec-4a23-be3a-03c1632404e9</SerialNumber>
</Data>
<Signature>2sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>