-
2021-02-03 15:19:41
导出word文档的过程中因为文档信息展示需要,要在指定位置插入图片,遇到的一系列问题整理:
POI框架在处理Excel文档方面功能的确很强大,但是在处理word文档方面就略显劣势,使用poi在文档中插入图片时打开文档提示有错误或者图片不显示甚至文档直接打不开,这个问题一方面和office版本有关系,另一方面POI自出生那天起在处理word文档方面就带有缺陷,直至今天在最新版本的代码中仍然没有把这个bug优化。
下面是我遇到的问题:
其实这个问题如果你不在意的话也不算是什么大问题,点击“是”然后另存为新文档这个问题就会消失,但是真正拿出去用或是自己较真的话还真是一个挺头疼的问题。
先说一下造成这个问题的原因吧(个人理解不一定准确),poi向word插入图片首先是以xml形式写进去的,如果你把.doc文件转换成xml格式文件你会发现所有的文字、图片、表格等信息都是以xml数据格式存储,生成的文档之所以会报错就是因为poi自带的生成图片的方法中图片的xml头文件是错的。
知道问题的原因了那就试着去重写他的方法就好了,网上也有很多大神已经重写好的,不过大多重写的是create方法,createpicture只能在文章末尾添加图片,不能满足我的需求。
下面是addpicture方法:
//添加图片重写addPicture方法 public static void addPictureRewrite(XWPFRun xwpfRun, String embed, int id, int width, int height) throws XmlException { final int EMU = 9000; width *= EMU; height *= EMU; CTInline ctInline = xwpfRun.getCTR().addNewDrawing().addNewInline(); String pictureXml ="<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=\"" + id + "\" name=\"Generated\"/>" + " <pic:cNvPicPr/>" + " </pic:nvPicPr>" + " <pic:blipFill>" + " <a:blip r:embed=\"" + embed + "\" 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>"; XmlToken xmlToken = XmlToken.Factory.parse(pictureXml); ctInline.set(xmlToken); ctInline.setDistT(0); ctInline.setDistB(0); ctInline.setDistL(0); ctInline.setDistR(0); CTPositiveSize2D ct = ctInline.addNewExtent(); ct.setCx(width); ct.setCy(height); CTNonVisualDrawingProps docPic = ctInline.addNewDocPr(); docPic.setId(id); docPic.setName("Picture " + id); docPic.setDescr("Generated"); }
方法调用:
//这里都是零星的代码段,完整代码没有贴出来,只是简单示意怎么调用重写后的方法 InputStream is = new FileInputStream(path); XWPFDocument doc = new XWPFDocument(is); //获取表格对象 List<XWPFTable> tables = doc.getTables(); //获取表格模板 XWPFTable tabel = tables.get(index); //获取表格 rows = tabel.getRows(); cells = rows.get(i).getTableCells(); //遍历这一行单元格 for (int j = 0; j < cells.size(); j++) { //判断该单元格内容是否是需要替换的图片 if (imgMatcher(cells.get(i).getText()).find()) { params1.put("picture", list.get(i)); replaceInImg(cells.get(i), params1, doc); continue; } } XWPFParagraph parag = cell.addParagraph(); XWPFRun run = para.createRun(); String picId = doc.addPictureData(is, XWPFDocument.PICTURE_TYPE_JPEG); //addPict方法调用 addPictureRewrite(run, picId, XWPFDocument.PICTURE_TYPE_JPEG, 450, 300);
最后还遇到一个挺离谱的事,在重写addPicture方法之后添加第二张图片,那个问题又出现了,各种方式都没排查出来是什么问题,在快要放弃的时候试着把模板重新写了一个,问题竟然消失了,最后竟然是模板的问题,因为文件模板是客户给的,文件后缀是.doc,后面拿过来之后直接把文件后缀改成了.docx看似没问题的操作,其实文档的数据格式差别还是很大的,又兴趣可以把这两个后缀的文档分别转换成xml格式研究一下。
更多相关内容 -
基于poi导出word以及图片
2019-05-13 17:22:581、poi版本3.13 2、可进行表格替换。复制、图片导出 3、可直接运行 -
poi导出数据到word,带图片且图片数量不确定(能确定数量范围,这里是3-20张)
2021-11-25 15:12:24org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.1</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> &1.导入依赖
maven版:<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.1</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.1</version> </dependency> <dependency> <groupId>org.jxls</groupId> <artifactId>jxls</artifactId> <version>2.6.0</version> <exclusions> <exclusion> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.jxls</groupId> <artifactId>jxls-poi</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>fr.opensagres.xdocreport.core</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>fr.opensagres.xdocreport.document</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>fr.opensagres.xdocreport.template</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>fr.opensagres.xdocreport.document.docx</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>fr.opensagres.xdocreport.template.freemarker</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.23</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> </dependency>
gradle版:
compile "fr.opensagres.xdocreport:fr.opensagres.xdocreport.core:2.0.2" compile "fr.opensagres.xdocreport:fr.opensagres.xdocreport.document:2.0.2" compile "fr.opensagres.xdocreport:fr.opensagres.xdocreport.document.docx:2.0.2" compile "fr.opensagres.xdocreport:fr.opensagres.xdocreport.template:2.0.2" compile "fr.opensagres.xdocreport:fr.opensagres.xdocreport.template.freemarker:2.0.2" compile "org.freemarker:freemarker:2.3.23" compile "commons-io:commons-io:2.5" compile "org.apache.poi:poi:3.14" compile "org.apache.poi:poi-ooxml:3.14"
2.创建导出模板
纯文字使用${}占位,图片使用建立初始化图片并添加书签的方式占位,
书签名就是datamap的键名,多张图片添加多个书签
3.编写代码(这里使用浏览器下载方式导出)
(1)导出工具方法/** * 导出工具方法 * // * * // * @param response 相应头 * // * @param map 集合外数据 * // * @param list 遍历数据 * // * @param fileName 文件名称(带后缀) * // * @return 是否导出成功 * // * @throws IOException * // * @throws XDocReportException */ public static void exportFile ( HttpServletResponse response, Map<String, File> fileDataMap, String fileName, Map<String, Object> map, List<Object> list) throws IOException, XDocReportException { // 获取Word模板,模板存放路径在项目的resources目录下 // 这里的Kit为当前工具方法的类名,如果不是静态方法可以直接用this InputStreamins= Kit.class.getResourceAsStream(fileName); // 注册xdocreport实例并加载FreeMarker模板引擎 IXDocReportreport=XDocReportRegistry.getRegistry().loadReport(ins, TemplateEngineKind.Freemarker); // 创建xdocreport上下文对象 IContext context = report.createContext(); //添加文本数据 if (map != null) { for (String s : map.keySet()) { context.put(s, map.get(s)); } } //添加循环表格数据(需要自行添加,模板对应加上关键字) if (list != null) { context.put("resultList", list); // 创建字段元数据 FieldsMetadata fm = report.createFieldsMetadata(); // Word模板中的表格数据对应的集合类型 fm.load("resultList", Object.class, true); } FieldsMetadata metadata = report.createFieldsMetadata(); // 替换word模板中的动态图片 if (fileMap != null) { for (String s : fileMap.keySet()) { IImageProvider zp = new FileImageProvider((fileMap.get(s)), true); zp.setSize(130F, 130F); metadata.addFieldAsImage(s); report.setFieldsMetadata(metadata); context.put(s, zp); } } // 浏览器端下载 response.setCharacterEncoding("utf-8"); response.setContentType("application/msword"); response.setHeader( "Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8")))); report.process(context, response.getOutputStream()); }
(2)业务逻辑代码
try{ Map<String, File> fileMap = null; Map<String, Object> exportMap = new hashMap(); exportMap.put("???","data"); int num = 1; //由于poitl和导入功能用的poi版本冲突,无法用,这里使用IXDocReport对象做导出 //可以循环添加,键名可以拼接为img1,img2,img3。。。,模板书签名对应 //需要导出的文件集合,对接实际业务service List<File> list = new arrayList(); if(list != null) { fileMap = new hashMap(); for (File f : list) { fileMap.put("img" + num , f); num ++; } } Kit.exportFile(response, fileMap, "模板名称.docx", exportMap, null); } catch (Exception e) { e.printStackTrace(); }
(3)因为我们业务文件接口返回的是byte数组,所以这里提供一个byte数组转File对象的方法(网上c的)
/** * byte数组转file对象工具方法(中方法) * * @param inputStream * @param name * @param ext * @param tmpDirFile * @return * @throws IOException */ public static File createTmpFile( InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException { File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile); resultFile.deleteOnExit(); FileUtils.copyToFile(inputStream, resultFile); return resultFile; } /** * byte数组转file对象工具方法 * * @param bytes 文件byte数组 * @param fileType 输出文件类型 * @return file对象 * @throws IOException io异常 */ public static File bytesToFile(byte[] bytes, String fileType) throws IOException { return createTmpFile( new ByteArrayInputStream(bytes), UUID.randomUUID().toString(), fileType, Files.createTempDirectory("tempFile").toFile()); }
4.那么问题来了,图片数量不定怎么确定初始化图片再添加书签呢,困扰了很久,最后直接用20张纯白图片(这里采用微信截图,截了很小一张,100张也没有几k,全都添加对应书签,不够20张也看不出来,缺点是不满20张会空一行出来),弄好后调用方法点击导出ok
注:方法思路由该贴而来
https://blog.csdn.net/plxddyxnmd/article/details/109129838
-
java导出图片到word文档
2018-07-30 10:56:43java:多个图片导出到word文档里显示,用于打印图片导出 -
springboot整合POI导出word(文字加图片)
2022-04-06 11:16:45springboot整合POI导出word(文字加图片)1、引入Poi依赖
<dependency> <groupId>com.deepoove</groupId> <artifactId>poi-tl</artifactId> <version>1.8.2</version> </dependency>
2、设置word模板
注意"{{}}"为中文模式下符号,图片占位{{@pic}},文字为{{text}}。3、(工具类)Utils
import com.deepoove.poi.XWPFTemplate; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileOutputStream; import java.net.URLEncoder; import java.util.Map; public class ExportWordUtils { public static void exportWord(String templatePath, String temDir, String fileName, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) { if (!temDir.endsWith("/")) { temDir = temDir + File.separator; } File dir = new File(temDir); if (!dir.exists()) { dir.mkdirs(); } try { XWPFTemplate doc = XWPFTemplate.compile(templatePath).render(params); String tmpPath = temDir + fileName;//新文件路径 FileOutputStream fos = new FileOutputStream(tmpPath); doc.write(fos); fos.flush(); fos.close(); doc.close(); } catch (Exception e) { e.printStackTrace(); } finally { //delFileWord(temDir,fileName);//这一步看具体需求,要不要删 } } public static void delFileWord(String filePath, String fileName){//删除文件 File file =new File(filePath+fileName); File file1 =new File(filePath); file.delete(); file1.delete(); } }
4、Controller
import com.deepoove.poi.data.PictureRenderData; import com.qh.makeword.utils.ExportWordUtils; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.HashMap; import java.util.Map; @Controller public class WordController { @RequestMapping("/export") public void export(HttpServletRequest request, HttpServletResponse response) throws IOException { Map<String,Object> params = new HashMap<>(); //key值与模板中的占位符一致 params.put("id","2020212345"); params.put("name","李四"); params.put("Image", new PictureRenderData(100, 140, new ClassPathResource("static/1.jpg").getFile().getPath())); ClassPathResource oldDoc = new ClassPathResource("word/export.docx"); //一行代码 ExportWordUtils.exportWord(oldDoc.getFile().getPath(),"newWord/","new.docx",params,request,response); } }
5、文件放置
export.docx为模板,1.jpg为插入模板的图片
6、运行结果
参考:
https://blog.csdn.net/weixin_43694038/article/details/106123534?spm=1001.2014.3001.5506https://blog.csdn.net/qq_41938882/article/details/89445678?utm_source=app&app_version=5.3.0&code=app_1562916241&uLinkId=usr1mkqgl919blen
-
apache poi 导出excel、word
2019-03-17 13:35:17apache poi 导出excel、word,替换word内容,导出word-文本、图片、表格 -
poi导出word例子(图片)
2015-11-23 17:23:23poi导出word例子(图片) -
JAVA POI:导出数据与图片到word中
2020-03-25 22:49:13导出数据与图片到word中,插入等比例图片!!!一、效果二、准备1.引入poi的依赖2.准备word模板三、代码实现1.WordService代码2.WordController3.工具类FileUtil四、总结参考: 一、效果 话不多说,先看效果: 二、...导出数据与图片到word中,插入等比例图片!!!
一、效果
话不多说,先看效果:
二、准备
1.引入poi的依赖
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>ooxml-schemas</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>com.deepoove</groupId> <artifactId>poi-tl</artifactId> <version>1.0.0</version> </dependency>
2.准备word模板
使用poi导出word需要准备一份word模板,变量用{{变量}}标识,在代码中会将这些变量替换为需要的数据
三、代码实现
本是使用springboot搭建的项目环境,由于是给浏览器用户导出word,所以代码分为service与controller两部分:
1.WordService代码
/** * @param data :需要替换的模板中的变量键值对 * @param TemplatePath :word模板在项目中的路径 * @param pictureTag :要替换为图片的变量名 * @param wordName :生成的word名称 * @param request * @param response * @throws IOException */ public void downWord(Map<String, Object> data, String TemplatePath, List<String>pictureTag,String wordName, HttpServletRequest request, HttpServletResponse response) throws IOException { try { ClassPathResource template = new ClassPathResource(TemplatePath); String projectPath = System.getProperty("user.dir"); //获取当前项目所在路径 //创建一个临时模板,放在系统上(这步很无奈) File file = new File(projectPath+SEPARATER+"template.docx"); InputStream templateInputStream = template.getInputStream(); FileUtils.copyInputStreamToFile(templateInputStream,file); XWPFTemplate xwpfTemplate = XWPFTemplate.compile(file); Configure config = xwpfTemplate.getConfig(); //设置处理策略,这一步很重要,本人在这个坑上跌了很久!!! for (String tag:pictureTag ) { config.customPolicy(tag,new PictureRenderPolicy()); } //将数据递交给模板处理 xwpfTemplate.render(data); String docName = wordName + ".docx"; File targetFile = new File(docName); FileOutputStream out = new FileOutputStream(targetFile); xwpfTemplate.write(out); out.flush(); out.close(); xwpfTemplate.close(); // 下载输出到浏览器 FileUtil.downFile(request,response,docName,targetFile); FileUtil.deleteDir(targetFile.getPath()); } catch (Exception e) { log.info("文件生成失败:"+e.getMessage()); throw e; } }
2.WordController
public void exportData(PatrolWordDto dto,HttpServletRequest request, HttpServletResponse response) throws Exception { List<String> pictureTag =new ArrayList<>(); Map<String,Object>data =new HashMap<>(); //需要填充的数据,key为模板中的变量 data.put("projectId",dto.getProjectId()); data.put("patrolTypeId",dto.getPatrolTypeId()); data.put("inspector",dto.getInspector()); data.put("date",dto.getDate()); data.put("beginTime",dto.getBeginTime()); data.put("content",dto.getContent()); data.put("result",dto.getResult()); data.put("endTime",dto.getEndTime()); data.put("note",dto.getNote()); //这里是前台传给我的查询图片的id String[] files = dto.getFiles().split("-"); int num =files.length; String templatePath=null; //因为图片数量不确定,设计了多种模板处理 for (int i=0;i<num;i++){ //这里我是从数据库获取图片路径 String photoPath = wordService.getPhotoPath(files[i]); //这个类完全是为了获取图片长宽 BufferedImage bufferImg = ImageIO.read(new File(photoPath)); // 获取的长宽数值较大,避免插入图片过大,我等比例缩小了10倍 int width = bufferImg.getWidth()/10; int height = bufferImg.getHeight()/10; PictureRenderData pictureRenderData = new PictureRenderData(width, height,photoPath); data.put("image"+(i+1),pictureRenderData); //标识出其中的图片变量,需要特殊处理 pictureTag.add("image"+(i+1)); } // 对应三种数量图片的模板路径 switch (num){ case 1:templatePath= "files/download/template/patroltemplate1.docx";break; case 2:templatePath= "files/download/template/patroltemplate2.docx";break; case 3:templatePath= "files/download/template/patroltemplate3.docx";break; } wordService.downWord(data,templatePath,pictureTag,"patrol",request,response); }
3.工具类FileUtil
/** * 下载文件到浏览器 * @param request * @param response * @param filename 要下载的文件名 * @param file 需要下载的文件对象 * @throws IOException */ public static void downFile(HttpServletRequest request, HttpServletResponse response, String filename, File file) throws IOException { // 文件存在才下载 if (file.exists()) { OutputStream out = null; FileInputStream in = null; // 1.读取要下载的内容 in = new FileInputStream(file); // 2. 告诉浏览器下载的方式以及一些设置 // 解决文件名乱码问题,获取浏览器类型,转换对应文件名编码格式,IE要求文件名必须是utf-8, firefo要求是iso-8859-1编码 String agent = request.getHeader("user-agent"); if (agent.contains("FireFox")) { filename = new String(filename.getBytes("UTF-8"), "iso-8859-1"); } else { filename = URLEncoder.encode(filename, "UTF-8"); } // 设置下载文件的mineType,告诉浏览器下载文件类型 String mineType = request.getServletContext().getMimeType(filename); response.setContentType(mineType); // 设置一个响应头,无论是否被浏览器解析,都下载 response.setHeader("Content-disposition", "attachment; filename=" + filename); // 将要下载的文件内容通过输出流写到浏览器 out = response.getOutputStream(); int len = 0; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } if (out != null) { out.close(); } if (in != null) { in.close(); } } } /** * 递归删除目录下的所有文件及子目录下所有文件 * * @param filePath 将要删除的文件目录路径 * @return boolean Returns "true" if all deletions were successful. * If a deletion fails, the method stops attempting to * delete and returns "false". */ public static boolean deleteDir(String filePath) { File dir = new File(filePath); if (dir.isDirectory()) { String[] children = dir.list(); //递归删除目录中的子目录下 for (int i = 0; i < children.length; i++) { boolean success = deleteDir(filePath + File.separator + children[i]); if (!success) { return false; } } } // 目录此时为空,可以删除 return dir.delete();
然后直接在浏览器访问controller的路径并传参就可以直接下载导出的word了,本人的项目路径是酱紫的:
http://127.0.0.1:8080/exportPatrolWord?projectId=sada&patrolTypeId=asd&inspector=asd&date=asd&beginTime=asd&endTime=asd&content=asd&result=asd&files=1¬e=asd
四、总结
本人也是被项目逼着翻了很多博客找到的代码,本来以为拿来能直接用,结果还有暗坑。主要有两个:
1.下载出来的word中本该是图片的地方是一串字符。调试看源码才发现默认的数据处理策略是TextRenderPolicy,这样就会对图片数据错误处理,结果就是把图片类的类名输出,而不是把图片输出,所以在递交模板数据前一定要配置对于图片标签用PictureRenderPolicy进行处理。for (String tag:pictureTagRenderPolicy()) { config.customPolicy(tag,new PictureRenderPolicy()); }
2.项目在idea中能运行,打包发布到linux后报异常。主要原因是打包成jar后,程序无法直接读取放在jar包中的word模板文件,只能获取到资源文件的二进制流。所以我不得已新建了一个file,然后将流复制到新文件中,使用该文件作为模板。只是这样会造成资源浪费,每次都会重新复制模板文件,所以最好是在项目初始化时进行该操作即可。各位大佬有更好的办法麻烦指点,谢谢!
ClassPathResource template = new ClassPathResource(TemplatePath); File file = new File(projectPath+SEPARATER+"template.docx"); InputStream templateInputStream = template.getInputStream(); FileUtils.copyInputStreamToFile(templateInputStream,file);
参考:
-
Apache poi 根据word模板生成word报表 替换 循环列表 图片
2020-03-11 14:52:26Apache poi 根据word模板生成word报表 替换 循环列表 图片,代码调试过了,修改相应的图片位置,word模板路径即可运行 -
poi 导出word,导出图片解决方法
2021-03-03 10:37:13/***写入图片*@paramdocument*@parampicName*@paramwidth*@paramheight*@paramalignment*/privatevoidWriteImage(CustomXWPFDocumentdocument,StringpicName,intwidth,intheight,ParagraphAlignmen... -
POI生成图表并导出word文档的基本操作
2022-04-20 17:49:59这篇文章主要介绍POI生成图表并导出word文档的基本操作。主要介绍三种图表:折线图、柱状图、饼状图。 一、效果展示 使用Java和POI技术生成的折线图,柱状图,饼状图的效果如下图所示: 二、环境准备 主要使用的... -
java使用poi根据word模板生成word(图片及文字).zip
2020-08-21 16:09:19java 使用poi根据模版导出word文件 将文件中的标签替换成文字或者文件 文件中标签用{xxxx}生成新文件 -
POI使用word模板文件循环输出行并导出word
2018-08-12 23:40:38一个使用Apache的poi使用word模板循环输出表格行并导出的例子 -
POI导出简单的带有图片的Word文档
2018-03-01 20:49:03由于导出的文档中需要插入图片,因此需要新建类来处理由于插入图片引进的错误即“导出的word文档在打开时会报内容出现错误,无法打开文件” 新建处理类为: import org.apache.poi.xwpf.usermodel.XWPFDocument; ... -
【操作word】Java + POI导出富文本的内容到word文档
2022-01-13 15:57:33这里先给出用于测试的富文本内容数据: 如何将富文本内容导出到word文档 采用poi将富文本内容导出到word文档 这是有背景颜色的div内容 这是base64编码后的图片 首先将图片转换成base64编码,然后把编码赋值到上面的... -
Java POI导出(图片,文字,表格)word文档
2019-04-22 10:30:22这里的教程,针对导出带有图片、文字、表格的Word文档 1.话不多说 先添加依赖 <dependency> <groupId>com.deepoove</groupId> <artifactId>poi-tl</artifact... -
POI导出word工具类
2022-03-08 15:59:251:导出07版word(docx) 2:支持文本、图片、表格、页脚、纸张大小、纸张方向、页边距 3:方便扩展 4:使用实例 (在 类WordExporter 的main方法中) -
java poi设置生成的word的图片为上下型环绕以及其位置的实现
2020-08-25 15:50:44主要介绍了java poi设置生成的word的图片为上下型环绕以及其位置的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧 -
JAVA根据word模版使用poi导出word文档,包含图片、文字
2021-02-24 14:17:45模版word文件 生成的word文件 代码 //自己使用做下简单的封装即可 public static void main(String[] args) { //示例数据 Map<String, Object> map = new HashMap<>(); map.put("name", "李四1");... -
java使用poi导出word并且带图片
2019-12-04 15:27:28最近在开发中有按照模板导出word的需求,并且把echarts图例附到word里,我开始使用freework取ftl模板的,不过由于转换麻烦,需定义好格式xml再转为ftl文件所以改为使用poi取word模板直接赋值的方式,并且通过拼接... -
使用POI导出word文档
2021-07-16 16:18:02使用POI导出word文档 步骤一、创建一个需要导出的word文档模板。将表里需要填充的数据对应好要填充的键最后在表的最前方加入一个书签(一个table一个书签) 步骤二、工具类 public class WordExport { /** 内部... -
POI实现导出word文件【内容包括文本,表格,图片】
2022-05-17 09:25:12POI生成word文件 -
java poi 导出word文档数据含图片导出(占位符方式)
2022-03-03 09:21:12java poi 导出word文档数据含图片导出(占位符方式),图片怎么导出 -
Java POI 导出WORD文档,图片导出在指定位置
2021-03-08 20:45:17//end this //自动生成对应文本内容后,下面代码生成图片内容 //查找word文档内所有的table Iterator tables = doc.getTablesIterator(); //跳过第一个table for(int i = 0;i ;i++) { tables.hasNext(); tables.... -
poi导出多条数据雷达图RADAR到ppt
2018-09-03 17:08:35poi 3.17 资料为 demo + 模板 + 数据类 java 导出多数据 雷达图图表 到ppt -
Java POI导出Word文档详解
2019-08-28 14:58:06一、POI 生成导出Word样式 二、详细代码 pom.xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version... -
使用java Apache poi 根据word模板生成word报表例子
2018-03-24 16:34:02使用java Apache poi 根据word模板生成word报表 仅支持docx格式的word文件,大概是word2010及以后版本,doc格式不支持。 使用说明:https://blog.csdn.net/u012775558/article/details/79678701 -
Java POI读取word生成
2019-04-24 16:13:22使用java poi模板生成word文件,方便数据的展示。规范数据在word的排版。 -
poi 将echar报表生成到word table表格中
2017-09-13 12:46:29poi 将echar报表生成到word table表格中,类似与word文档中的生成图片,对于导出 word文档的报表是个不错的实例 -
POI生成word文档
2019-01-18 15:46:16最近在做一个出卷系统,需要通过试卷模板从数据库中抽取题目,然后按照模板的样式生成完整的试卷,包括试卷格式的排版和图片的写入。这是用POI模板生成word文档。里面包括完整代码和所需jar包。