aspose.word根据word模板填充对应信息并导出

本文介绍了如何利用Aspose.Word根据预设的Word模板填充信息,并导出文档。首先,展示了模板文件的位置。接着,通过Java代码演示了如何读取模板,替换占位符,最后保存并输出到浏览器作为附件。还提及了Aspose的授权设置,包括在web启动时设置许可证以及提供license.xml文件的样例内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、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>

                



   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值