0

I am getting an exception and I can't find the reason of it. The exception I get is :

Caused by: java.lang.IllegalAccessError: class com.spire.xls.packages.sprRFA (in module spire.xls.free) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to module spire.xls.free

@FXML
public void OnCreateFile(ActionEvent actionEvent) {

    String po1 = Word.getText();
    String[] ss1 = po1.split(" ");
    String po2 = Output.getText();
    String[] ss2 = po2.split(" ");


    Workbook workbook = new Workbook();

    Worksheet sheet = workbook.getWorksheets().get(0);
    sheet.insertArray(ss1, 0, 0, true);
    sheet.insertArray(ss2, 0, 1, true);

    workbook.saveToFile("dictionary.xlsx", ExcelVersion.Version2016);
}

Any help? Also would like to know is there any other way to export array in Excel document using Java.

Mutastak
  • 1
  • 1
  • Please have a look at [Apache POI](https://poi.apache.org/). This is the library we are using to create excel documents – wartoshika Jun 07 '22 at 20:03
  • The error is related to [this question](https://stackoverflow.com/questions/50251798/what-is-an-illegal-reflective-access) – wartoshika Jun 07 '22 at 20:06
  • Also similar to [this question](https://stackoverflow.com/questions/68225921/olp-cli-error-java-base-does-not-export-sun-security-util-to-unnamed-module-und). You can contact the maintainers of the spire library and ask them to fix it to work with recent Java versions in a modular runtime environment. In the meantime, the command line switches demonstrated in the related questions might allow you to get the application to execute. – jewelsea Jun 07 '22 at 20:41
  • POI is an alternative library, if you choose to look into using it there is [some discussion about doing so in a JavaFX application in this answer](https://stackoverflow.com/questions/70284441/troubleshooting-with-export-tableview-to-excel-javafx/70284638#70284638), though it is not a complete tutorial on integrating POI into a JavaFX application. – jewelsea Jun 07 '22 at 20:44
  • A simpler alternative might be to export to a CSV file rather than a spreadsheet. Excel can easily read CSV files. If you choose to do this, you could do this without an external library, but it would probably be best to find a good Java CSV library and use that. – jewelsea Jun 07 '22 at 20:46
  • perhaps you can use this --add-opens=java.base/java.lang.reflect=ALL-UNNAMED – Jawad El Fou Jun 07 '22 at 23:38
  • 1
    @JawadElFou I'm guessing that should read `--add-opens java.base/java.lang.reflect=spire.xls.free` because that is the name of the module being used, it is not an unnamed module. I didn't try this to verify it would work, likely it would from the previously linked answers. – jewelsea Jun 08 '22 at 01:10
  • @jewelsea you are most probably right. – Jawad El Fou Jun 08 '22 at 04:44

1 Answers1

-1

This thread might be of help:https://www.e-iceblue.com/forum/illegal-access-error-when-instantiating-workbook-t10921.html

James
  • 69
  • 2