gpt4 book ai didi

java.lang.IllegalAccessError : tried to access method org. org.apache.poi.openxml4j.opc.ZipPackage 类中的 apache.poi.util.POILogger.log

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:24 26 4
gpt4 key购买 nike

我已经使用 apache poi 完成了 Excel 工作表的读取和写入。但是如果我尝试使用相同的 apache poi 下载 ms-word,则会抛出以下错误。java.lang.IllegalAccessError:尝试从类 org.apache.poi.openxml4j.opc.ZipPackage 访问方法 org.apache.poi.util.POILogger.log(ILjava/lang/Object;)V

     <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.13</version>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.13</version>
</dependency>

esp.setContentType("application/msword");

    resp.setHeader("Content-Disposition", "attachment;filename=\"" + "xx.docx" + "\"");

XWPFDocument document= new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();

paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run=paragraph.createRun();

run.setText("The endeavour started by Mohtashim, an AMU " +
"alumni, who is the founder and the managing director " +
"of Tutorials Point (I) Pvt. Ltd. He came up with the " +
"website tutorialspoint.com in year 2006 with the help" +
"of handpicked freelancers, with an array of tutorials" +
" for computer programming languages. ");

OutputStream outputStream = resp.getOutputStream();
PrintStream stream = new PrintStream(outputStream);
document.write(stream);

请给我解决这个问题

最佳答案

我使用他的 Maven 依赖项并编写我的测试代码

这是我的代码👇

import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

public class SampleWord {

public static void main(String[] args) throws Exception{
XWPFDocument document= new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();

paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run=paragraph.createRun();

run.setText("The endeavour started by Mohtashim, an AMU " +
"alumni, who is the founder and the managing director " +
"of Tutorials Point (I) Pvt. Ltd. He came up with the " +
"website tutorialspoint.com in year 2006 with the help" +
"of handpicked freelancers, with an array of tutorials" +
" for computer programming languages. ");


FileOutputStream fileOut = new FileOutputStream("/Users/chenpengye/Documents/excel/test/test.docx");


document.write(fileOut);

document.close();

}

}

但是,没有出现任何错误;

关于java.lang.IllegalAccessError : tried to access method org. org.apache.poi.openxml4j.opc.ZipPackage 类中的 apache.poi.util.POILogger.log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34630209/

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