java读取word模版渲染报错Compile template failed。(poi-tl currently only supperts .docx fomat)

poi-tl渲染word报错:Compile template failed
在这里插入图片描述

XWPFTemplate.compile(inputStream,config)
打断点追进去发现,报错 poi-tl currently only supperts .docx fomat

在这里插入图片描述

poi tl目前只支持.docx格式

如果是docx文件重新将word文件保存到本地,然后另存为docx文件,把新保存的文件重新放到idea上就可以了。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
登录页面。 最后,我们需要实现一个ProductService类,用于操作商品信息: ```java public class ProductService { 使用 Apache POI-TL 1.4.2 版本对 Word 文档中的文本框赋值可以非常方 private UserDao userDao = new UserDao(); private Map<Integer, Product> products = new HashMap<>(); public ProductService() { // 初始化便地完成。下面是一个示例代码: ``` XWPFTemplate template = XWPFTemplate.compile("template.docx").render(); // 获取第一个文本框 XWPFTextBox textBox = template.getTextBoxes().get(0); // 在文商品信息 products.put(1, new Product(1, "iPhone", 5999)); products.put(2, new Product本框内插入文本 textBox.setText("新的文本"); template.write(new FileOutputStream("output.docx")); template.close(); ``(2, "iPad", 3999)); products.put(3, new Product(3, "MacBook", 9999)); ` 在示例代码中,首先使用 XWPFTemplate 类编译 Word 模板并渲染出一个新的 Word 文档对象。然后,通过调用 getTextBoxes 方法获取文档中的所有文本框对象,使用 get(0) products.put(4, new Product(4, "iPod", 999)); } public User getUser(String username) { 方法获取第一个文本框对象。最后,使用 setText 方法对文本框内的文本进行赋值。 注意, return userDao.getUser(username); } public List<Product> getProducts(String username) { List<Product> result = new ArrayList<>(); 使用 POI-TLWord 文档进行操作需要在 pom.xml 文件中引入以下依赖: ``` <dependency> <groupId>com.deepoove</groupId> <artifactId>poi-tl</artifactId> <version>1.4 User user = userDao.getUser(username); Map<Integer, Integer> shoppingCart = user.getShoppingCart(); for (Integer productId : shopping.2</version> </dependency> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值