poi word 表格插入图片
可能3.8,3.9是存在你所说的图片插入表格无法显示的问题,但是我现在用的是4.0.1,已经没有改问题,用的run.addpicture()方法;可以正常显示,正在思考如何做样式。
-
File outFile = new File("D:\\computer-b63781b9\\cloud\\Desktop\\create_table.docx"); -
FileInputStream in = new FileInputStream(new File("D:\\data\\guns-lite\\runtime\\upload\\08#A101#IMG_20180220_190720R.jpg")); -
FileOutputStream out = new FileOutputStream(outFile); -
XWPFDocument docx = new XWPFDocument(); -
-
XWPFTable table = docx.createTable(1,1); -
XWPFTableRow row = table.getRow(0); -
XWPFTableCell cell = row.getCell(0); -
XWPFParagraph newPara = cell.addParagraph(); -
XWPFRun imageCellRunn = newPara.createRun(); -
XWPFPicture pic = imageCellRunn.addPicture(in, XWPFDocument.PICTURE_TYPE_PNG, "1.png", Units.toEMU(200), Units.toEMU(200)); -
imageCellRunn.addBreak(); -
-
in.close(); -
docx.write(out); -
out.close();

浙公网安备 33010602011771号