gpt4 book ai didi

java - 使用 poi 添加图片到文档

转载 作者:行者123 更新时间:2023-12-01 06:15:27 25 4
gpt4 key购买 nike

我遇到了异常

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.toByteArray(Ljava/io/InputStream;)[B
at org.apache.poi.xwpf.usermodel.XWPFDocument.addPictureData(XWPFDocument.java:1198)
at org.apache.poi.xwpf.usermodel.XWPFRun.addPicture(XWPFRun.java:680)
at signature.Main.createFile(Main.java:85)
at signature.Main.listFilesForFolder(Main.java:52)
at signature.Main.main(Main.java:29)

尝试使用 apache POI 将图片添加到文档文件时

代码如下

                XWPFDocument docx = new XWPFDocument();
XWPFParagraph par = docx.createParagraph();
XWPFRun run = par.createRun();
run.setText(imageUrl);
File picture = new File("D:\\1.jpg");
FileInputStream in = new FileInputStream(picture);
run.addPicture(in, Document.PICTURE_TYPE_JPEG, "1", 100, 100);
FileOutputStream out = new FileOutputStream(f);
docx.write(out);
out.close();

最佳答案

有点晚了,但我找到了一个关于 POI 库的简短教程,可以帮助您将图片添加到文档中,希望它有帮助:http://developeriq.in/articles/2012/jul/03/handling-ms-word-documents-using-apache-poi/

关于java - 使用 poi 添加图片到文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26187371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com