java html写入到word文档_java 使用jacob将html页面写入word

0fb53d6daa6757091712e0d87c6d7d72.png

在此先声明最重要的一点:使用jacob将html导入word时图片是使用链接的方式引入的,也就是说如果你的图片删除了,那么word中图片也没了。

原文链接:https://blog.csdn.net/feicy101/article/details/52134938?locationNum=15

本人是对原文链接中 :jacob替换图片进行了测试

maven:

net.sf.jacob-project

jacob

1.14.3

原文代码:

packagecom.thinkgem.jeesite.test;importcom.jacob.activeX.ActiveXComponent;importcom.jacob.com.Dispatch;importcom.jacob.com.Variant;/***@authorliuwei

* @date 2018年9月30日 上午10:58:23

**/

public classInsertPicToWord {/*** 给指定的word文档在字符串指定位置插入图片

*@paramwordFile word文档

*@paramimagePath 待添加图片的路径

*@paramtarStr 指定的字符串位置*/

public static voidinsertImage(String wordFile, String imagePath,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我并不是一个可以浏览文档的程序,也没有能力打开网页查找相关信息。但是,我可以告诉你如何使用Java将多个Word文档合并为一个Word文档。 可以使用Apache POI库来操作Word文档。以下是将多个Word文档合并为一个Word文档的示例代码: ``` import java.io.*; import org.apache.poi.xwpf.usermodel.*; public class MergeWordDocuments { public static void main(String[] args) throws Exception { String[] files = {"doc1.docx", "doc2.docx", "doc3.docx"}; XWPFDocument finalDoc = new XWPFDocument(); for (String file : files) { XWPFDocument doc = new XWPFDocument(new FileInputStream(file)); for (XWPFParagraph para : doc.getParagraphs()) { XWPFParagraph newPara = finalDoc.createParagraph(); newPara.createRun().setText(para.getText()); } for (XWPFTable tbl : doc.getTables()) { XWPFTable newTbl = finalDoc.createTable(); newTbl.getCTTbl().setTblPr(tbl.getCTTbl().getTblPr()); for (int i = 0; i < tbl.getRows().size(); i++) { XWPFTableRow row = newTbl.getRow(i); if (row == null) row = newTbl.createRow(); for (int j = 0; j < tbl.getRow(i).getTableCells().size(); j++) { XWPFTableCell cell = row.getCell(j); if (cell == null) cell = row.createCell(); cell.getCTTc().setTcPr(tbl.getRow(i).getCell(j).getCTTc().getTcPr()); for (XWPFParagraph para : tbl.getRow(i).getCell(j).getParagraphs()) { XWPFParagraph newPara = cell.addParagraph(); newPara.createRun().setText(para.getText()); } } } } } FileOutputStream out = new FileOutputStream("finalDoc.docx"); finalDoc.write(out); out.close(); finalDoc.close(); } } ``` 上述代码将会把 `doc1.docx`,`doc2.docx` 和 `doc3.docx` 合并为 `finalDoc.docx` 文件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值