实现html和word的相互转换(带图片)
项目后端使用了springboot,maven,前端使用了ckeditor富文本编辑器。目前从html转换的word为doc格式,而图片处理支持的是docx格式,所以需要手动把doc另存为docx,然后才可以进行图片替换。
2021年了,我回来填坑了,又碰到了需要把 html 转换成 word 的场景,目前对于格式不固定的带图片的导出,有以下解决方案:
后端只做部分样式处理,导出工作交给前端完成,代码实现见第四部分。
一.添加maven依赖
主要使用了以下和poi相关的依赖,为了便于获取html的图片元素,还使用了jsoup:
<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.14</version>
</dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>3.14</version>
</dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.14</version>
</dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>xdocreport</artifactId><version>1.0.6</version>
</dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>3.14</version>
</dependency><dependency><groupId>org.apache.poi</groupId><artifactId>ooxml-schemas</artifactId><version>1.3</version>
</dependency><dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.11.3</version>
</dependency>
二.word转换为html
在springboot项目的resources目录下新建static文件夹,将需要转换的word文件temp.docx粘贴进去,由于static是springboot的默认资源文件,所以不需要在配置文件里面另行配置了,如果改成其他名字,需要在application.yml进行相应配置。
doc格式转换为html:
public static String docToHtml() throws Exception {File path = new File(ResourceUtils.getURL("classpath:").getPath());String imagePathStr = path.getAbsolutePath() + "\\static\\image\\";String sourceFileName = path.getAbsolutePath() + "\\static\\test.doc";String targetFileName = path.getAbsolutePath() + "\\static\\test2.html";File file = new File(imagePathStr);if(!file.exists()) {file.mkdirs();}HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(sourceFileName));org.w3c.dom.Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(document);//保存图片,并返回图片的相对路径wordToHtmlConverter.setPicturesManager((content, pictureType, name, width, height) -> {try (FileOutputStream out = new FileOutputStream(imagePathStr + name)) {out.write(content);} catch (Exception e) {e.printStackTrace();}return "image/" + name;});wordToHtmlConverter.processDocument(wordDocument);org.w3c.dom.Document htmlDocument = wordToHtmlConverter.getDocument();DOMSource domSource = new DOMSource(htmlDocument);StreamResult streamResult = new StreamResult(new File(targetFileName));TransformerFactory tf = TransformerFactory.newInstance();Transformer serializer = tf.newTransformer();serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");serializer.setOutputProperty(OutputKeys.INDENT, "yes");serializer.setOutputProperty(OutputKeys.METHOD, "html");serializer.transform(domSource, streamResult);return targetFileName;
}
docx格式转换为html
public static String docxToHtml() throws Exception {File path = new File(ResourceUtils.getURL("classpath:").getPath());String imagePath = path.getAbsolutePath() + "\\static\\image";String sourceFileName = path.getAbsolutePath() + "\\static\\test.docx";String targetFileName = path.getAbsolutePath() + "\\static\\test.html";OutputStreamWriter outputStreamWriter = null;try {XWPFDocument document = new XWPFDocument(new FileInputStream(sourceFileName));XHTMLOptions options = XHTMLOptions.create();// 存放图片的文件夹options.setExtractor(new FileImageExtractor(new File(imagePath)));// html中图片的路径options.URIResolver(new BasicURIResolver("image"));outputStreamWriter = new OutputStreamWriter(new FileOutputStream(targetFileName), "utf-8");XHTMLConverter xhtmlConverter = (XHTMLConverter) XHTMLConverter.getInstance();xhtmlConverter.convert(document, outputStreamWriter, options);} finally {if (outputStreamWriter != null) {outputStreamWriter.close();}}return targetFileName;
}
转换成功后会生成对应的html文件,如果想在前端展示,直接读取文件转换为String返回给前端即可。
public static String readfile(String filePath) {File file = new File(filePath);InputStream input = null;try {input = new FileInputStream(file);} catch (FileNotFoundException e) {e.printStackTrace();}StringBuffer buffer = new StringBuffer();byte[] bytes = new byte[1024];try {for (int n; (n = input.read(bytes)) != -1;) {buffer.append(new String(bytes, 0, n, "utf8"));}} catch (IOException e) {e.printStackTrace();}return buffer.toString();
}
在富文本编辑器ckeditor中的显示效果:
三.html转换为word
实现思路就是先把html中的所有图片元素提取出来,统一替换为变量字符"${imgReplace}“,如果多张图片,可以依序排列下去,之后生成对应的doc文件(之前试过直接生成docx文件发现打不开,这个问题尚未找到好的解决方法),我们将其另存为docx文件,之后就可以替换变量为图片了:
public static String writeWordFile(String content) {String path = "D:/wordFile";Map<String, Object> param = new HashMap<String, Object>();if (!"".equals(path)) {File fileDir = new File(path);if (!fileDir.exists()) {fileDir.mkdirs();}content = HtmlUtils.htmlUnescape(content);List<HashMap<String, String>> imgs = getImgStr(content);int count = 0;for (HashMap<String, String> img : imgs) {count++;//处理替换以“/>”结尾的img标签content = content.replace(img.get("img"), "${imgReplace" + count + "}");//处理替换以“>”结尾的img标签content = content.replace(img.get("img1"), "${imgReplace" + count + "}");Map<String, Object> header = new HashMap<String, Object>();try {File filePath = new File(ResourceUtils.getURL("classpath:").getPath());String imagePath = filePath.getAbsolutePath() + "\\static\\";imagePath += img.get("src").replaceAll("/", "\\\\");//如果没有宽高属性,默认设置为400*300if(img.get("width") == null || img.get("height") == null) {header.put("width", 400);header.put("height", 300);}else {header.put("width", (int) (Double.parseDouble(img.get("width"))));header.put("height", (int) (Double.parseDouble(img.get("height"))));}header.put("type", "jpg");header.put("content", OfficeUtil.inputStream2ByteArray(new FileInputStream(imagePath), true));} catch (FileNotFoundException e) {e.printStackTrace();}param.put("${imgReplace" + count + "}", header);}try {// 生成doc格式的word文档,需要手动改为docxbyte by[] = content.getBytes("UTF-8");ByteArrayInputStream bais = new ByteArrayInputStream(by);POIFSFileSystem poifs = new POIFSFileSystem();DirectoryEntry directory = poifs.getRoot();DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);FileOutputStream ostream = new FileOutputStream("D:\\wordFile\\temp.doc");poifs.writeFilesystem(ostream);bais.close();ostream.close();// 临时文件(手动改好的docx文件)CustomXWPFDocument doc = OfficeUtil.generateWord(param, "D:\\wordFile\\temp.docx");//最终生成的带图片的word文件FileOutputStream fopts = new FileOutputStream("D:\\wordFile\\final.docx");doc.write(fopts);fopts.close();} catch (Exception e) {e.printStackTrace();}}return "D:/wordFile/final.docx";}//获取html中的图片元素信息public static List<HashMap<String, String>> getImgStr(String htmlStr) {List<HashMap<String, String>> pics = new ArrayList<HashMap<String, String>>();Document doc = Jsoup.parse(htmlStr);Elements imgs = doc.select("img");for (Element img : imgs) {HashMap<String, String> map = new HashMap<String, String>();if(!"".equals(img.attr("width"))) {map.put("width", img.attr("width").substring(0, img.attr("width").length() - 2));}if(!"".equals(img.attr("height"))) {map.put("height", img.attr("height").substring(0, img.attr("height").length() - 2));}map.put("img", img.toString().substring(0, img.toString().length() - 1) + "/>");map.put("img1", img.toString());map.put("src", img.attr("src"));pics.add(map);}return pics;}
OfficeUtil工具类,之前发现网上的写法只支持一张图片的修改,多张图片就会报错,是因为添加了图片,processParagraphs方法中的runs的大小改变了,会报ArrayList的异常,就和我们循环list中删除元素会报异常道理一样,解决方法就是复制一个新的Arraylist进行循环:
package com.example.demo.util; import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;import org.apache.poi.POIXMLDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow; /** * 适用于word 2007*/
public class OfficeUtil { /** * 根据指定的参数值、模板,生成 word 文档 * @param param 需要替换的变量 * @param template 模板 */ public static CustomXWPFDocument generateWord(Map<String, Object> param, String template) { CustomXWPFDocument doc = null;try { OPCPackage pack = POIXMLDocument.openPackage(template); doc = new CustomXWPFDocument(pack); if (param != null && param.size() > 0) { //处理段落List<XWPFParagraph> paragraphList = doc.getParagraphs(); processParagraphs(paragraphList, param, doc); //处理表格Iterator<XWPFTable> it = doc.getTablesIterator(); while (it.hasNext()) {XWPFTable table = it.next(); List<XWPFTableRow> rows = table.getRows(); for (XWPFTableRow row : rows) { List<XWPFTableCell> cells = row.getTableCells(); for (XWPFTableCell cell : cells) { List<XWPFParagraph> paragraphListTable = cell.getParagraphs(); processParagraphs(paragraphListTable, param, doc); } } } } } catch (Exception e) { e.printStackTrace(); } return doc; } /** * 处理段落 * @param paragraphList */ public static void processParagraphs(List<XWPFParagraph> paragraphList,Map<String, Object> param,CustomXWPFDocument doc){ if(paragraphList != null && paragraphList.size() > 0){ for(XWPFParagraph paragraph:paragraphList){//poi转换过来的行间距过大,需要手动调整if(paragraph.getSpacingBefore() >= 1000 || paragraph.getSpacingAfter() > 1000) {paragraph.setSpacingBefore(0);paragraph.setSpacingAfter(0);}//设置word中左右间距paragraph.setIndentationLeft(0);paragraph.setIndentationRight(0);List<XWPFRun> runs = paragraph.getRuns();//加了图片,修改了paragraph的runs的size,所以循环不能使用runsList<XWPFRun> allRuns = new ArrayList<XWPFRun>(runs);for (XWPFRun run : allRuns) {String text = run.getText(0); if(text != null){boolean isSetText = false; for (Entry<String, Object> entry : param.entrySet()) { String key = entry.getKey(); if(text.indexOf(key) != -1){ isSetText = true; Object value = entry.getValue(); if (value instanceof String) {//文本替换text = text.replace(key, value.toString()); } else if (value instanceof Map) {//图片替换text = text.replace(key, ""); Map pic = (Map)value; int width = Integer.parseInt(pic.get("width").toString()); int height = Integer.parseInt(pic.get("height").toString()); int picType = getPictureType(pic.get("type").toString()); byte[] byteArray = (byte[]) pic.get("content"); ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteArray); try { String blipId = doc.addPictureData(byteInputStream,picType); doc.createPicture(blipId,doc.getNextPicNameNumber(picType), width, height,paragraph);} catch (Exception e) { e.printStackTrace(); } } } } if(isSetText){ run.setText(text,0); } } } } } } /** * 根据图片类型,取得对应的图片类型代码 * @param picType * @return int */ private static int getPictureType(String picType){ int res = CustomXWPFDocument.PICTURE_TYPE_PICT; if(picType != null){ if(picType.equalsIgnoreCase("png")){ res = CustomXWPFDocument.PICTURE_TYPE_PNG; }else if(picType.equalsIgnoreCase("dib")){ res = CustomXWPFDocument.PICTURE_TYPE_DIB; }else if(picType.equalsIgnoreCase("emf")){ res = CustomXWPFDocument.PICTURE_TYPE_EMF; }else if(picType.equalsIgnoreCase("jpg") || picType.equalsIgnoreCase("jpeg")){ res = CustomXWPFDocument.PICTURE_TYPE_JPEG; }else if(picType.equalsIgnoreCase("wmf")){ res = CustomXWPFDocument.PICTURE_TYPE_WMF; } } return res; } /** * 将输入流中的数据写入字节数组 * @param in * @return */ public static byte[] inputStream2ByteArray(InputStream in,boolean isClose){ byte[] byteArray = null; try { int total = in.available(); byteArray = new byte[total]; in.read(byteArray); } catch (IOException e) { e.printStackTrace(); }finally{ if(isClose){ try { in.close(); } catch (Exception e2) { System.out.println("关闭流失败"); } } } return byteArray; }
}
我认为之所以word2003不支持图片替换,主要是因为处理2003版本的HWPFDocument对象被声明为了final,我们就无法重写他的方法了。
而处理2007版本的类为XWPFDocument,是可以继承的,通过继承XWPFDocument,重写createPicture方法即可实现图片替换,以下为对应的CustomXWPFDocument类:
package com.example.demo.util; import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlToken;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; /** * 自定义 XWPFDocument,并重写 createPicture()方法 */
public class CustomXWPFDocument extends XWPFDocument { public CustomXWPFDocument(InputStream in) throws IOException { super(in); } public CustomXWPFDocument() { super(); } public CustomXWPFDocument(OPCPackage pkg) throws IOException { super(pkg); } /** * @param ind * @param width 宽 * @param height 高 * @param paragraph 段落 */ public void createPicture(String blipId, int ind, int width, int height,XWPFParagraph paragraph) { final int EMU = 9525; width *= EMU; height *= EMU; CTInline inline = paragraph.createRun().getCTR().addNewDrawing().addNewInline(); String picXml = "" + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + " <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:nvPicPr>" + " <pic:cNvPr id=\"" + ind + "\" name=\"Generated\"/>" + " <pic:cNvPicPr/>" + " </pic:nvPicPr>" + " <pic:blipFill>" + " <a:blip r:embed=\"" + blipId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" + " <a:stretch>" + " <a:fillRect/>" + " </a:stretch>" + " </pic:blipFill>" + " <pic:spPr>" + " <a:xfrm>" + " <a:off x=\"0\" y=\"0\"/>" + " <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + " </a:xfrm>" + " <a:prstGeom prst=\"rect\">" + " <a:avLst/>" + " </a:prstGeom>" + " </pic:spPr>" + " </pic:pic>" + " </a:graphicData>" + "</a:graphic>"; inline.addNewGraphic().addNewGraphicData(); XmlToken xmlToken = null; try { xmlToken = XmlToken.Factory.parse(picXml); } catch (XmlException xe) { xe.printStackTrace(); } inline.set(xmlToken); inline.setDistT(0); inline.setDistB(0); inline.setDistL(0); inline.setDistR(0); CTPositiveSize2D extent = inline.addNewExtent(); extent.setCx(width); extent.setCy(height); CTNonVisualDrawingProps docPr = inline.addNewDocPr(); docPr.setId(ind); docPr.setName("图片" + ind); docPr.setDescr("测试"); }
}
以上就是通过POI实现html和word的相互转换,对于html无法转换为可读的docx这个问题,不是很好解决。
html和word的相互转换也可以通过 freemarker 模板的方式实现,这个是同事给的思路,我没有尝试,大家有兴趣的可以试试,缺点就是模板是固定的,不够灵活,不适用于经常变动的网页。
历经两年多又发现了一个新的解决方案,亲测可用,见第四部分。
四.html转换为word之前端实现
前端实现的方法比较灵活,也支持表格,echarts 的导出,使用 file-saver 插件实现。
在 vue 和 angular 下测试了都可以用,而后端只需要对图片和样式进行处理,转换和导出工作交给前端来做(后端同学露出了如释重负的笑容)。
java 代码实现
controller 实现:
@PostMapping("/article/htmlFormat")public Ret html(String html) throws Exception {return articleService.formatHtmlStyle(html);}
service 实现:
// 实现图片和样式处理的方法public Ret formatHtmlStyle(String html) {JSONArray picsArr = new JSONArray();// 缩小图片Document doc = Jsoup.parse(html);Elements elementsP = doc.getElementsByTag("p");for (int i = 0; i < elementsP.size(); i++) {Element element = elementsP.get(i);boolean hasImg = false;Elements elementsChildren = element.children();for (int j = 0; j < elementsChildren.size(); j++) {Element elementChild = elementsChildren.get(j);if (elementChild.nodeName().equals("img")) {hasImg = true;break;}}if (hasImg) {element.attr("style", "text-align: center ;");} else {element.attr("style","font-family: FangSong_GB2312 ;font-size:18px;text-indent: 2em ;line-height:34px;text-align:justify;");}}Elements elements = doc.getElementsByTag("img");for (int i = 0; i < elements.size(); i++) {Element element = elements.get(i);String src = element.attr("src");JSONObject picjo = new JSONObject();picjo.put("index", i);// 将网络图片转为 base64 格式picjo.put("src", CommonUtil.urlToBase64(src));picsArr.add(picjo);element.attr("src", "" + i);}Ret ret = Ret.create().setCodeAndMsg(200).set("html", doc.body().html()).set("pics", picsArr);return ret; }
注意事项:
1.这里的Ret就是一个结果封装类,不是重点,只要把 html 和 pics 返回即可。
2.html 中的图片路径是网络图片,需要转换为 base64 才能在 word 中显示。
CommonUtil 中的转换代码如下:
public static String urlToBase64(String imgUrl) {InputStream inputStream = null;ByteArrayOutputStream outputStream = null;byte[] buffer = null;try {// 创建URLURL url = new URL(imgUrl);// 创建链接HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("GET");conn.setConnectTimeout(5000);inputStream = conn.getInputStream();outputStream = new ByteArrayOutputStream();// 将内容读取内存中buffer = new byte[1024];int len = -1;while ((len = inputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, len);}buffer = outputStream.toByteArray();} catch (IOException e) {e.printStackTrace();} finally {if (inputStream != null) {try {// 关闭inputStream流inputStream.close();} catch (IOException e) {e.printStackTrace();}}if (outputStream != null) {try {// 关闭outputStream流outputStream.close();} catch (IOException e) {e.printStackTrace();}}}// 对字节数组Base64编码String base64 = "data:image/png;base64," + new BASE64Encoder().encode(buffer);return base64;}
vue 代码实现
1.安装 file-saver
npm install file-saver --save
bower install file-saver
如果提示 “bower不是内部或外部命令”,需要安装bower
npm install -g bower
安装 TypeScript 定义
npm install @types/file-saver --save-dev
2.使用
导入 saveAs
import { saveAs } from 'file-saver';
实现下载处理逻辑
downloadArticle: function() {var FileSaver = require('file-saver');var html = "这里是你的html内容";//var html = "<html>" + this.$refs.article.innerHTML + "</html>";var param = new URLSearchParams();param.append('html', html);// 调用上面的 java 接口获取处理后的html内容this.$axios({method: 'post',url: '/article/htmlFormat',data: param}).then((response) = > {const _static = {mhtml: {top: "Mime-Version: 1.0\nContent-Base: " + location.href + "\nContent-Type: Multipart/related; boundary=\"NEXT.ITEM-BOUNDARY\";type=\"text/html\"\n\n--NEXT.ITEM-BOUNDARY\nContent-Type: text/html; charset=\"utf-8\"\nContent-Location: " + location.href + "\n\n<!DOCTYPE html>\n<html>\n_html_</html>",head: "<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n<style>\n_styles_\n</style>\n</head>\n",body: "<body>_body_</body>"}};const dealhtml = response.data.html;const img = response.data.pics;let mhtmlBottom = "\n";for (let i = 0; i < img.length; i++) {const uri = img[i].src;const index = img[i].index;mhtmlBottom += "--NEXT.ITEM-BOUNDARY\n";mhtmlBottom += "Content-Location: " + index + "\n";mhtmlBottom += "Content-Type: " + uri.substring(uri.indexOf(":") + 1, uri.indexOf(";")) + "\n";mhtmlBottom += "Content-Transfer-Encoding: " + uri.substring(uri.indexOf(";") + 1, uri.indexOf(",")) + "\n\n";mhtmlBottom += uri.substring(uri.indexOf(",") + 1) + "\n\n";}mhtmlBottom += "--NEXT.ITEM-BOUNDARY--";// 整合html代码片段const fileContent = _static.mhtml.top.replace("_html_", _static.mhtml.body.replace("_body_", dealhtml)) + mhtmlBottom;// 导出const blob = new Blob([fileContent], {type: "application/msword;charset=utf-8"});saveAs(blob, `testImage.doc`);});
}
注意事项:
不要图省事在后端把 base64 写在 image 标签的 src 里面,这样会导致导出的word文档只有在切换为编辑视图后才能显示图片。
最终效果:
实现html和word的相互转换(带图片)相关推荐
- VUE使用docxtemplater导出word(带图片)
一.docxtemplater docxtemplater 是一种邮件合并工具,以编程方式使用并处理条件.循环,并且可以扩展以插入任何内容(表格.html.图像). npm 是安装 docxtempl ...
- wangEditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
在之前在工作中遇到在富文本编辑器中粘贴图片不能展示的问题,于是各种网上扒拉,终于找到解决方案,在这里感谢一下知乎中众大神以及TheViper. 通过知乎提供的思路找到粘贴的原理,通过TheViper找 ...
- poi导出数据到word,带图片且图片数量不确定(能确定数量范围,这里是3-20张)
注:有更好解决方法,参考:https://blog.csdn.net/m0_49605579/article/details/122583318 1.导入依赖 maven版: <dependen ...
- Java使用XDocReport导出Word(带图片)
XDocReport导出Word 简介 示例 实现方式 Maven依赖 Word模板制作 Word模板文字(四步) Word模板图片(五步) 具体实现 注意事项 结论 简介 这次的内容是关于Java实 ...
- Easypoi Excel导出和word导出带图片(图片不显示问题必须用字节)
Maven包 其他的包Excel导出会出现空指针问题 <dependency><groupId>cn.afterturn</groupId><artifact ...
- java 模板 word转pdf 可分页 带图片
java 模板 word转pdf 可分页 带图片 之前写过一个简单的案例,但是在项目中完全不能满足客户的需求,所以重新用啦一种方式来写,采用了word转换pdf的方式,这种经过不断研究,满足了可分页, ...
- java freemarker导出word 带图片,文件导出后图片无法使用office正常打开
问题记录:java freemark导出word 带图片,文件导出后图片无法使用office正常打开,解决之! 现象:wps打开正常,office如下 修改点: 图片${image1}标签前后保证无空 ...
- 基于freemarker(mht)方式导出带图片的富文本word
需求 批量将包含富文本的页面(含图片)导出为word的压缩包,并将每个页面的附件一同下载,下载的文件夹路径格式我就不展示了,具体页面如下 本次导出采用基于freemarker的word导出.大体上都是 ...
- java实现word导出(带图片)
java实现word导出(带图片) 转载地址:https://www.jianshu.com/p/98ed03044fe1
最新文章
- SignalR的另类实现技巧
- 【Linux 内核 内存管理】Linux 内核内存布局 ③ ( Linux 内核 动态分配内存 系统接口函数 | 统计输出 vmalloc 分配的内存 )
- 最新发布丨游戏市场“超预期”增长背景下,如何加速产品精品化 运营精细化?...
- exchange系列(四)如何保护exchange邮件服务器的安全
- OC_KVC与KVO简单介绍
- .NET 状态机Automatonymous快速入门
- luoguSP1805,POJ2559-Largest Rectangle in a Histogram【单调栈】
- [html] H5的哪些特性需要https支持呢?
- 幕后产品_使用Bitwarden密码管理器在幕后
- error C2065: 'assert' : undeclared identifier
- 「开源资讯」Sentinel Go 0.4.0 发布,支持热点流量防护能力
- UTC时间字符串转换为本地时间(北京)
- 电压跟随器的问答汇总
- 打通最后100米:苏宁小店如何成为家门口的“共享冰箱”
- mysql索引类型normal,unique,full text,索引方式btree索引和hash
- 优达学城 深度学习 任务3
- 八月,愿你生活不拥挤,笑容不刻意
- What is 虫洞攻击?
- Apollo学习笔记(22)Dijkstra算法
- ReportStudio入门教程(七十二) - 显示时间进度(进度条版)