具体报错为
Exception in thread "main" java.lang.IllegalAccessError: class com.spire.office.packages.sprkzh (in unnamed module @0x21507a04) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x21507a04
at com.spire.office.packages.sprkzh.spr▃┢(Unknown Source)
at com.spire.office.packages.sprkzh.spr┽┍(Unknown Source)
at com.spire.office.packages.sprkzh.<init>(Unknown Source)
at com.spire.office.packages.sprfqg.<init>(Unknown Source)
at com.spire.office.packages.sprhqg.<init>(Unknown Source)
at com.spire.xls.core.spreadsheet.XlsWorkbook.<init>(Unknown Source)
at com.spire.xls.Workbook.<init>(Unknown Source)
at Copy2.main(Copy2.java:6)
代码为
import com.spire.xls.*;
public class Copy2 {
public static void main(String[] args) {
//加载文档1,并获取第一张工作表
Workbook wb1 = new Workbook();
wb1.loadFromFile("test1.xlsx");
Worksheet sheet1 = wb1.getWorksheets().get(0);
//加载文档2,获取第三张工作表,并将文档1中的工作表内容复制到该工作表
Workbook wb2 = new Workbook();
wb2.loadFromFile("test2.xlsx");
Worksheet sheet2 = wb2.getWorksheets().get(2);
sheet2.setName("Copied");
sheet2.copyFrom(sheet1);
//保存文档
wb2.saveToFile("Copy2.xlsx",FileFormat.Version2013);
}
}
我多使用的为IntelliJIdea2021.2,jdk-17.0.1,使用的使用免费的Spire.office for Java包,
pom.xml文件为
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.office.free</artifactId>
<version>5.3.1</version>
</dependency>
</dependencies>
我很喜欢这个包的功能,希望在试用成功之后购买正式版,但是现在我希望我能解决这个问题,真的很重要。感谢您的回答