We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

java.lang.ExceptionInInitializerError when initializing working in Cells for Python

I have a working example that I am trying to push to AWS Lambda serverless function. The AWS runtime (Python3.7) has OpenJDK 1.8 installed and the JVM appears to be running. FYI, I am currently using an evaluation copy – could this be related to licensing.

Here are the container specs:

openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)

The aspose version is 21.9.

Here is a sample of the associated python code:
import os

import jpype
def init_jvm():
    if jpype.isJVMStarted():
        return
    # jpype.startJVM()
    stream = os.popen('java -version')
    output = stream.read()
    jpype.startJVM(jpype.getDefaultJVMPath())
    # you can then access to the basic java functions
    jpype.java.lang.System.out.println("hello world")
    print(output)
init_jvm()

from asposecells.api import Workbook

#the code fails at the next line
workbook0 = Workbook()

@billdaigle,
We have tried an Aspose.Cells related scenario and were able to accomplish it without any error. You may follow these steps and see if your issue is resolved or not. Here are the environment details and steps which are followed:

Ubuntu

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal

Java

java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)

Python

Python 3.8.10

Installing Aspose-Cells

pip install aspose-cells
pip install JPype1

Please note that aspose-cells 21.9.0 has requirement JPype1>=1.2.1

Sample Code

import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook, EncryptionType

# Load XLSX workbook
wb = Workbook("workbook.xlsx")

# Password protect Excel file
wb.getSettings().setPassword("1234")

# Encrypt by specifying the encryption type
wb.setEncryptionOptions(EncryptionType.XOR, 40)

# Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider)
wb.setEncryptionOptions(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128)

# Save Excel file
wb.save("workbook-encrypted.xlsx")

jpype.shutdownJVM()

Here are the input and output files for your reference:
workbook-encrypted.xlsx.zip (9.2 KB)
workbook.xlsx.zip (6.6 KB)

Also please refer to the solution shared by another user here for your reference.

Thank you for the response. I struggled with this for a bit before finding an amazon container that worked for me. Amazon uses centos based machines and for some reason I was unable to get it running with Java 8. I ended up creating my own custom container with Java 11 installed on an AWS python 3.8 image. Just in case someone else runs into the same issue, I attached a working sample.

AsposeCellsPythonAwsLambdaSample.zip (3.4 KB)

@billdaigle,
Thanks for sharing the working sample. It will help others with similar scenario as yours.