Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Feb 08, 2022 3:12 am

I want to convert an excel file to a PDF but I get an error when I instantiate the Workbook class.

Code: Select all
import java.io.IOException;

import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

public class ExcelConversion {

   public void convert() throws IOException {
      
      Workbook workbook = new Workbook();
        workbook.loadFromFile("yes.xlsx");

        //Save as PDF document
        workbook.saveToFile("ExcelToPDF.pdf",FileFormat.PDF);
      
   }
}


java.lang.IllegalAccessError: class com.spire.xls.packages.sprRFA (in unnamed module @0xfe48b45) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module

I'm using spire.xls.free version 5.1.0 with the intention of purchasing the product if it works.

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Tue Feb 08, 2022 6:08 am

Hello,

Thanks for your inquiry!

To help us better investigate in your issue, please provide us with the following information. Thanks in advance!

1. Your JDK version (E.g. oracle JDK 1.8.0_271).
2. Your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese).
3. The file you were using (yes.xlsx).
4. Your project type (E.g. spring boot project).

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 08, 2022 6:21 am

Hi, my JDK version is Java 11, I'm using an M1 Mac running on OS Monterey, and the project is springboot. The error occurs during the Workbook instantiation, before Workbook#loadFromFile is called so I don't think it's an issue with the excel file I am trying to load.

these are my dependencies and repositories:
Code: Select all
<dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
         <groupId>com.hynnet</groupId>
         <artifactId>pdfjet</artifactId>
         <version>5.75</version>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.apache.poi</groupId>
         <artifactId>poi</artifactId>
         <version>5.1.0</version>
      </dependency>
      <dependency>
         <groupId>org.apache.poi</groupId>
         <artifactId>poi-ooxml</artifactId>
         <version>5.1.0</version>
      </dependency>
      <dependency>
         <groupId>org.apache.pdfbox</groupId>
         <artifactId>pdfbox</artifactId>
         <version>2.0.25</version>
      </dependency>
      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
       </dependency>
       <dependency> 
          <groupId>org.json</groupId> 
          <artifactId>json</artifactId> 
          <version>20180130</version> 
      </dependency>
      <dependency>
          <groupId>com.github.javadev</groupId>
          <artifactId>underscore</artifactId>
          <version>1.73</version>
      </dependency>
      <dependency>
         <groupId>net.sf.jasperreports</groupId>
         <artifactId>jasperreports</artifactId>
         <version>6.18.1</version>
      </dependency>
      <dependency>
          <groupId>e-iceblue</groupId>
          <artifactId>spire.xls.free</artifactId>
          <version>5.1.0</version>
      </dependency>
   </dependencies>
   <repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
   </repositories>

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Tue Feb 08, 2022 7:38 am

Hello,

Thanks for sharing more information!

I simulated a simple project and run it on Mac Monterey with JDK 11.0.2, but did not reproduce your issue. Here I also attached the jar file I tested with.
system.png
system.png (66.65 KiB) Viewed 6089 times

Could you please provide us with the project or jar file you were testing for further investigate? Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 08, 2022 8:28 am

Hi, I wasn't able to look inside the jar file you provided, but here is the class that I was using for testing. It's a Springboot RestController so it doesn't interact with any other classes in the project.
Attachments
ExcelConversion.java.zip
(566 Bytes) Downloaded 493 times

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Tue Feb 08, 2022 10:05 am

Hello,

Thanks for sharing more information!

I simulated a Spring Boot project according to your maven information. But this project still can run successfully in MAC. Here I attached my whole project.

You can also try our latest Spire.Xls for java 5.1.5 to see if the issue still exists. Or please provide us with a simple project ti reproduce your issue. Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
Attachments
testFreeXls.zip
(120.35 KiB) Downloaded 494 times
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Feb 09, 2022 3:25 am

Hi, I'm still unable to get my project to work, so I created a simple example of what I'm currently doing and attached it here.
Attachments
demo.zip
(87.67 KiB) Downloaded 468 times

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Wed Feb 09, 2022 6:52 am

Hello,

Thanks for sharing your project.

Sorry that I still cannot reproduce the Illegal issue you mentioned by the project you provided. Did you try the project I attached in the last post?

Besides, could you please provide us with the detail step that you tested with? Here I also attached my steps. You can also send us a video via email(support@e-iceblue.com). Thanks in advance.

step.png
step.png (88.2 KiB) Viewed 6076 times

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Feb 09, 2022 9:47 am

Hi, I downloaded the jar file that you sent me but I'm not able to view freeDoc.class or any of the jar files inside. How I'm currently running my spring project is directly calling
./mvnw spring-boot:run
from the command line (I'm not compiling it to an artifact). I then use
curl localhost:8080/excel-pdf
whereby I run into the IllegalAccessError:
Code: Select all
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.IllegalAccessError: class com.spire.xls.packages.sprRFA (in unnamed module @0xfe48b45) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0xfe48b45] with root cause

java.lang.IllegalAccessError: class com.spire.xls.packages.sprRFA (in unnamed module @0xfe48b45) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0xfe48b45
   at com.spire.xls.packages.sprRFA.spr  (Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.spire.xls.packages.sprRFA.spr  (Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.spire.xls.packages.sprRFA.<init>(Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.spire.xls.packages.sprksa.<init>(Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.spire.xls.packages.sprHTa.<init>(Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.spire.xls.core.spreadsheet.XlsWorkbook.<init>(Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.spire.xls.Workbook.<init>(Unknown Source) ~[spire.xls.free-5.1.0.jar:5.1.0]
   at com.example.demo.DemoApplication.getPdf(DemoApplication.java:23) ~[classes/:na]

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Thu Feb 10, 2022 5:38 am

Hello,

I tested your project with "./mvnw" method, but still cannot reproduce the issue, the project can run normally and generate the PDF file. So I do more search about the issue "module java.base does not export sun.security.action to unnamed module" you mentioned and found that this issue may be related to the JDK version.(According to this:https://stackoverflow.com/questions/66690687/im-starting-to-learn-spring-boot-and-i-run-into-this-error)
result.png
result.png (86.78 KiB) Viewed 6055 times


Could you please provide us with the JDK version of your Mac to help us reproduce your environment? Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu Feb 10, 2022 6:24 am

Hi, thanks for your response, this is what I get when I run java-version:

java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Thu Feb 10, 2022 7:11 am

Hello,

Thanks for your feedback!

Kindly note that in your project, you have set the target running JDK version to JavaSE-11. But since the JDK version of your Mac is JavaSE-17, the difference between these two cause the Illegal issue you meet. Please remove the JavaSE-17, and then download and set the JavaSE-11 to your Mac, and then the issue will not exist anymore.

YourProjectSetting.png
YourProjectSetting.png (17.73 KiB) Viewed 6050 times


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu Feb 10, 2022 7:52 am

Hi, thank you so much for your help! I had some issues installing Java 11 due to ARM architecture, but I managed to fix them and get the library to work :D Now i just need to figure out how to convert pdf back to excel... if all goes well, my company will be purchasing the full version of this software.

yangiiyu
 
Posts: 12
Joined: Mon Feb 07, 2022 7:00 am

Thu Feb 10, 2022 8:07 am

Hello,

You are welcome!

If you encounter any issues related to our product in the future, just feel free to contact us.

Have a nice day!

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.XLS