开发者社区> 问答> 正文

poi3.14的版本问题

3.14时getAllPictures().get(id).getPackageRelationship()方法已经过时,之后的版本就没有了,请问用什么方法替代了?

展开
收起
陌然浅笑-支 2022-04-18 09:04:26 3337 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。

    2000元阿里云代金券免费领取,2核4G云服务器仅664元/3年,新老用户都有优惠,立即抢购>>>

    您好,当然有的。如下为源码:其中,imgFile就是图片的路径,直接传入一个能访问的图片地址就行了。

    public class SimpleImages {
    
        public static void main(String[] args) throws IOException, InvalidFormatException {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p = doc.createParagraph();
    
            XWPFRun r = p.createRun();
    
            for(String imgFile : args) {
                int format;
    
                if(imgFile.endsWith(".emf")) format = XWPFDocument.PICTURE_TYPE_EMF;
                else if(imgFile.endsWith(".wmf")) format = XWPFDocument.PICTURE_TYPE_WMF;
                else if(imgFile.endsWith(".pict")) format = XWPFDocument.PICTURE_TYPE_PICT;
                else if(imgFile.endsWith(".jpeg") || imgFile.endsWith(".jpg")) format = XWPFDocument.PICTURE_TYPE_JPEG;
                else if(imgFile.endsWith(".png")) format = XWPFDocument.PICTURE_TYPE_PNG;
                else if(imgFile.endsWith(".dib")) format = XWPFDocument.PICTURE_TYPE_DIB;
                else if(imgFile.endsWith(".gif")) format = XWPFDocument.PICTURE_TYPE_GIF;
                else if(imgFile.endsWith(".tiff")) format = XWPFDocument.PICTURE_TYPE_TIFF;
                else if(imgFile.endsWith(".eps")) format = XWPFDocument.PICTURE_TYPE_EPS;
                else if(imgFile.endsWith(".bmp")) format = XWPFDocument.PICTURE_TYPE_BMP;
                else if(imgFile.endsWith(".wpg")) format = XWPFDocument.PICTURE_TYPE_WPG;
                else {
                    System.err.println("Unsupported picture: " + imgFile +
                            ". Expected emf|wmf|pict|jpeg|png|dib|gif|tiff|eps|bmp|wpg");
                    continue;
                }
    
                r.setText(imgFile);
                r.addBreak();
                r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels
                r.addBreak(BreakType.PAGE);
            }
    
            FileOutputStream out = new FileOutputStream("images.docx");
            doc.write(out);
            out.close();
            doc.close();
        }
    
    
    }
    
    2022-05-15 11:00:10
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载
http://www.vxiaotou.com