Documentation outlines multiple overloads for save method. All overloads are named same, just accepting different types. It is not clear how to select the correct overload image.png (18.2 KB)
Can you create an example of saving a Workbook as PDF to bytes?
@vdimov
Please try the following codes to set SaveFormat:
import aspose.cells
from io import RawIOBase
from aspose.cells import Workbook
from aspose.cells import SaveFormat
from aspose.pyio import BufferStream
workbook = Workbook("input.xlsx")
withio.BytesIO() as write_f:
workbook.save(write_f,SaveFormat.PDF)
data = write_f.read()
Ran the sample code on Windows and Linux. On windows works as expected. Running on Linux, Python v3.9, I get the following exception:
Exception: RuntimeError: Proxy error(CellsException): The type initializer for threw an exception.
Stack: …
File ‘/home/site/wwwroot/ConvertExcelToPdfNet/init.py’, line 29, in main
workbook.save(write_f, SaveFormat.PDF)
Unfortunately, the type initializer name is obfuscated with the square chars and is not clear what it is.
@vdimov
Please try the following code(aspose-cells-python 23.1.0) which works fine in our side(Windows 10 x64 Python 3.10,and Linux(Ubuntu 18.04,Python 3.6.9)) if there is still exception we suspect it may be an environmental issue.Thanks!
import aspose.cells
from aspose.cells import Workbook, SaveFormat
workbook = Workbook("input.xlsx")
with open("output.pdf", "wb+") as write_f:
workbook.save(write_f, SaveFormat.PDF)
file_bytes = write_f.read()
Looks like aspose-cells-python throws exceptions in Azure Functions Python runtime. Full stack/exception below
Result: Failure Exception: RuntimeError: Proxy error(CellsException): The type initializer for ‘’ threw an exception. Stack: File “/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py”, line 452, in _handle__invocation_request call_result = await self._loop.run_in_executor( File “/usr/local/lib/python3.9/concurrent/futures/thread.py”, line 58, in run result = self.fn(*self.args, **self.kwargs) File “/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py”, line 718, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File “/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py”, line 215, in _raw_invocation_wrapper result = function(**args) File “/home/site/wwwroot/function_app.py”, line 28, in test_function workbook.save(write_f, SaveFormat.PDF)
@vdimov
What is your OS environment and python version,3.9.? then we will try to setup the same environment to reproduce your problem. In addition, is there a problem running the following code in your environment?
I can successfully export xls => pdf on Windows 10 by both passing in an output file and exporting to a stream.
To make sure Aspose working in the target environment, I tested another method.
Test steps: load xlsx file into a Workbook, get fonts from loaded workbook. That is successful. Once I try to export to PDF, I get exception. Detailed log below:
2023-01-27T14:55:01Z [Information] Platform: CPython
2023-01-27T14:55:03Z [Information] [Aspose.Cells.Font [ Calibri; 11; Regular; Color [A=255, R=0, G=0, B=0] ], Aspose.Cells.Font [ Arial; 10; Regular; Color [A=255, R=0, G=0, B=0] ], Aspose.Cells.Font [ Georgia; 14; Bold; Color [A=255, R=72, G=135, B=178] ],…]
2023-01-27T14:55:03Z [Information] /home/site/wwwroot/assets/documents/template.xlsx
2023-01-27T14:55:03Z [Information] Proxy error(CellsException): The type initializer for ‘’ threw an exception.
2023-01-27T14:55:03Z [Information] Traceback (most recent call last):
File “/home/site/wwwroot/function_app.py”, line 38, in test_function
@vdimov
We have encapsulated System.Drawing.Common in our product, and we initially estimate that it is not supported on your platform because converting to a PDF file requires System.Drawing.Common.
Question before we dig into creating custom Azure Funciton image to include the additional library - will this new library solve the issue or is it just for debugging?
@vdimov
We use System.drawing.common for drawing. In Linux, System.drawing.common depends upon libgdiplus. We encountered similar issue on another newly installed Linux machine. However it was resolved after installing libgdiplus on it. So please try it.
Please note, libgdiplus is compulsory on Linux, which depends on many other libraries. Moreover, it is not appropriate to include so many dependent libraries (dependencies) in our released package as this may increase the file size.
I was evaluating the aspose-cells-python package for my employer.
We were interested in exporting Excel data to pictures using the workbook.save method
Initial tests looked very promising. But, we could not get it work on Azure Functions - mainly because of the aforementioned errors.
We are not in a position to us a custom image for our Azure Functions at this point.
This was a nice library . But, sadly we cannot pursue with this any more.
We are sorry but as we told, libgdiplus is compulsory for the rendering tasks. It is not appropriate to include dependencies in our released package for now.
Should you have further queries or comments, feel free to write us back.
Hello @amjad.sahi,
I appreciate your quick response. I understand your challenges.
As a though experiment -
Do you think it would be possible to have an extra PIP package that downloads the libgdiplus ? Your existing package aspose-cells-python remains unchanged. This would help users who are on Azure Functions.
@sau002
We plan to replace System.Drawing.Common with SkiaSharp, which has better cross-platform capabilities. We plan to release the new version before April 20th and hope that it will meet your needs. Once we release the new version, we will notify you as soon as possible!