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.

Wed Apr 17, 2024 10:42 pm

I am attempting to initialize a workbook using the provided examples in a Python Lambda function. The Spire.XLS library has been installed from the Linux wheel file, and I have version 1.7.4 of plum-dispatch installed. However, when the function is triggered, it results in the following runtime error:

[ERROR] SpireException: TypeInitialization_Type_NoTypeAvailable: at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x153
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0x9
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.InitializeCollections() + 0xdd
at Spire.Xls.Core.Spreadsheet.XlsWorksheet..ctor(Object) + 0x82
at Spire.Xls.Core.Spreadsheet.Collections.XlsWorksheetsCollection.Add(String) + 0x190
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.spra(Int32) + 0x461
at Spire.Xls.Workbook..ctor() + 0x44
at Spire.Xls.AOT.NLWorkbook.CreateWorkbook(IntPtr) + 0x4c
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 10, in handler
    workbook = Workbook()
  File "/var/task/plum/function.py", line 642, in __call__
    return self.f(self.instance, *args, **kw_args)
  File "/var/task/plum/function.py", line 592, in __call__
    return _convert(method(*args, **kw_args), return_type)
  File "/var/task/spire/xls/Workbook.py", line 18, in __init__
    intPtr = CallCFunction(GetDllLibXls().Workbook_CreateWorkbook)
  File "/var/task/spire/xls/common/__init__.py", line 109, in CallCFunction
    raise SpireException(info)

Any help in resolving this would be appreciated.

mahtab.movahedian
 
Posts: 2
Joined: Wed Apr 17, 2024 10:23 pm

Thu Apr 18, 2024 9:44 am

Hi,

Thanks for your inquiry.
Please offer the following messages to help us do further investigation
1) The complete code.
2) The version of linux, such as Ubuntu 20.04

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Thu Apr 18, 2024 2:48 pm

This is the code, running in Amazon Linux and Python 3.11:
Code: Select all
from spire.xls import *
from spire.xls.common import *
import sys
import os


def handler(event, context):
    print(os.getcwd())
    print("creating workbook...")
    workbook = Workbook()
    print("workbook created")


and the error is
Traceback (most recent call last):
File "/home/ec2-user/test.py", line 4, in <module>
workbook = Workbook()
^^^^^^^^^^
File "/home/ec2-user/.local/lib/python3.11/site-packages/plum/function.py", line 642, in __call__
return self.f(self.instance, *args, **kw_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ec2-user/.local/lib/python3.11/site-packages/plum/function.py", line 592, in __call__
return _convert(method(*args, **kw_args), return_type)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ec2-user/.local/lib/python3.11/site-packages/spire/xls/Workbook.py", line 18, in __init__
intPtr = CallCFunction(GetDllLibXls().Workbook_CreateWorkbook)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ec2-user/.local/lib/python3.11/site-packages/spire/xls/common/__init__.py", line 109, in CallCFunction
raise SpireException(info)
spire.xls.common.SpireException: TypeInitialization_Type_NoTypeAvailable: at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x153
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0x9
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.InitializeCollections() + 0xdd
at Spire.Xls.Core.Spreadsheet.XlsWorksheet..ctor(Object) + 0x82
at Spire.Xls.Core.Spreadsheet.Collections.XlsWorksheetsCollection.Add(String) + 0x190
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.spra(Int32) + 0x461
at Spire.Xls.Workbook..ctor() + 0x44
at Spire.Xls.AOT.NLWorkbook.CreateWorkbook(IntPtr) + 0x4c
Exception ignored in: <function Workbook.__del__ at 0x7f6e6960cd60>
Traceback (most recent call last):
File "/home/ec2-user/.local/lib/python3.11/site-packages/spire/xls/Workbook.py", line 23, in __del__
CallCFunction(GetDllLibXls().Workbook_Dispose, self.Ptr)
^^^^^^^^
File "/home/ec2-user/.local/lib/python3.11/site-packages/spire/xls/common/SpireObject.py", line 27, in Ptr
return self._ptr
^^^^^^^^^
AttributeError: 'Workbook' object has no attribute '_ptr'

mahtab.movahedian
 
Posts: 2
Joined: Wed Apr 17, 2024 10:23 pm

Fri Apr 19, 2024 10:16 am

Hi,

Thanks for your feedback.
I attempted to test your scenario in AWS through Python Lambda function, but there an exception(Unable to import module 'lambda_function': No module named 'spire') are thrown. I think the reason of the exception is caused by my operation error.

I wrote my test steps in a word document and attached it in attachment. Due to I don't know much about AWS. Could you give me some help to reproduce your scenario. Thanks in advance.

Sincerely
Abel
E-iceblue support team
Attachments
testStep.zip
(505.28 KiB) Downloaded 384 times
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS