Samples for Aspose.Cells for Python via .NET

Can you please provide me with examples of using Aspose.Cells for .NET in a python file? I also could not install this package - so I unzipped “aspose_cells_python-24.11.0-py3-none-win_amd64.whl” file manually and installed it in the same folder as my python test script file.

Any and all help with an installation starting point and code samples that work would be very helpful. Thank you.

@nvartak

Can you please specify the exact issues you encountered during the installation of Aspose.Cells for Python via .NET?

I did not seem to finish the pip install

It said downloading aspose_cells_python-24-11.0-py3-none-win_amd64.whl … etc. and then in a lower line: 3.4 of 62.2 etc. eta 0:01:16. And it stayed there for more than 30 minutes! I can attach a screenshot if you will give me a link to upload it

@nvartak
About how to install Aspose.Cells for Python via .NET, please refer to the following document:

About how to use Aspose.Cells for Python via .NET, please refer to developer guide:

@nvartak
Normally, we use pip install aspose-cells-python to install the latest version. If the installation fails due to network delays or other reasons, you can also download a specific version here for local installation.

After multiple tries, I got Aspose.Cells for Python via .NET installed here: “C:\Users<myprofilename>\AppData\Local\Programs\Python\Python313\Lib\site-packages\aspose\assemblies\cells”.

However, when I try to code “import aspose.cells” or “from aspose.cells import License, Workbook” in my Python file which exists here: “C:\Users<myprofilename>\Documents\xyz\abc\bot_aspose_test.py”, I get warning in VS Code for this file.

What am I doing wrong? Please note that I am not an Admin on my laptop and unable to register any dll or put it in environment path variable.

@nvartak
1.Please first check if aspose-cells-python version 24.11 is correctly installed by running
pip list aspose-cells-python, as Python 3.13 is supported starting from version 24.11.

2.Also, could you specify the exact warning message you are seeing?

3.Finally, if you have confirmed that Aspose.Cells for Python 24.11 is correctly installed, you can run examples from PyPI in ipython to verify.

4.Here is the step-by-step explanation of how I installed and tested Aspose.Cells for Python to support Python 3.13:.

4.1 Check installed Python versions using py -0:

PS C:\Users\Me> py -0
 -V:3.13 *        Python 3.13 (64-bit)
 -V:3.12          Python 3.12 (64-bit)
 -V:3.10          Python 3.10 (64-bit)

4.2 Install Aspose.Cells for Python under Python 3.13:

PS C:\Users\Me> py -3.13 -m pip install aspose-cells-python

4.3 Test installation:

PS C:\Users\Me> py -3.13 C:\Users\Me\PycharmProjects\pythonProject\venv\tmp\test3.13.py
24.11

test3.13.py.7z (926 Bytes)

Hope helps a bit!

I have tested and installed Python 3.13 correctly as seen below: C:\Users<myprofilename>>py -0
-V:3.13 * Python 3.13 (64-bit)
-V:3.12-32 Python 3.12 (32-bit)
-V:3.6-32 Python 3.6 (32-bit)

But when I run this cmd:

C:\Users<myprofilename>>py -3.13 “C:\Users<myprofilename>\AppData\Local\Programs\Python\Python313\test_script_from_aspose\test3.13.py”

a new cmd window pops open and closes very quickly and I hardly have the time to see the result!!!

I have also confirmed that 24.11.0 version of aspose-cells-python is installed - in this case also, a new window pops up and closes - fortunately, I was able to get a quick snapshot before it closed. Why is this happening?

I typed cmd: py -3.13 -m pip install aspose-cells-python

The message said: requirement already satisfied: aspose-cells-python in .\appdata\local\programs\python\python313\lib\site-packages (24.11.0)

@nvartak,

Thanks for providing details.

We will be looking into it and get back to you soon.

Could you please capture a screenshot and attach it here as well (if possible). This may help a bit.

I am attaching a screenshot of your test file inside VS Code.
Python_error_1.png (55.0 KB)

@nvartak
By testing with the following sample code, we can find that there are no error prompts in Pycharm. There will be error prompts in the VS code, but it does not affect the program’s operation. Running the program directly can get correct results. We need to further investigate the reasons for the error message, and we will notify you promptly once there is an update. Please refer to the attachment.
vs_code.png (22.5 KB)
Pycharm.png (81.6 KB)
pivotTable_test_out.zip (9.3 KB)

import aspose.cells
from aspose.cells import Workbook
from aspose.cells.pivot import PivotFieldType

#  Instantiating a Workbook object
workbook = Workbook()
#  Obtaining the reference of the newly added worksheet
sheet = workbook.worksheets[0]
cells = sheet.cells
#  Setting the value to the cells
cell = cells.get("A1")
cell.put_value("Sport")
cell = cells.get("B1")
cell.put_value("Quarter")
cell = cells.get("C1")
cell.put_value("Sales")
cell = cells.get("A2")
cell.put_value("Golf")
cell = cells.get("A3")
cell.put_value("Golf")
cell = cells.get("A4")
cell.put_value("Tennis")
cell = cells.get("A5")
cell.put_value("Tennis")
cell = cells.get("A6")
cell.put_value("Tennis")
cell = cells.get("A7")
cell.put_value("Tennis")
cell = cells.get("A8")
cell.put_value("Golf")
cell = cells.get("B2")
cell.put_value("Qtr3")
cell = cells.get("B3")
cell.put_value("Qtr4")
cell = cells.get("B4")
cell.put_value("Qtr3")
cell = cells.get("B5")
cell.put_value("Qtr4")
cell = cells.get("B6")
cell.put_value("Qtr3")
cell = cells.get("B7")
cell.put_value("Qtr4")
cell = cells.get("B8")
cell.put_value("Qtr3")
cell = cells.get("C2")
cell.put_value(1500)
cell = cells.get("C3")
cell.put_value(2000)
cell = cells.get("C4")
cell.put_value(600)
cell = cells.get("C5")
cell.put_value(1500)
cell = cells.get("C6")
cell.put_value(4070)
cell = cells.get("C7")
cell.put_value(5000)
cell = cells.get("C8")
cell.put_value(6430)
pivotTables = sheet.pivot_tables
#  Adding a PivotTable to the worksheet
index = pivotTables.add("=A1:C8", "E3", "PivotTable2")
#  Accessing the instance of the newly added PivotTable
pivotTable = pivotTables[index]
#  Unshowing grand totals for rows.
pivotTable.row_grand = False
#  Draging the first field to the row area.
pivotTable.add_field_to_area(PivotFieldType.ROW, 0)
#  Draging the second field to the column area.
pivotTable.add_field_to_area(PivotFieldType.COLUMN, 1)
#  Draging the third field to the data area.
pivotTable.add_field_to_area(PivotFieldType.DATA, 2)
#  Saving the Excel file
workbook.save("pivotTable_test_out.xlsx")

Thank you. With some modifications, I was able to run the code and generate both the Excel file as well as the JSON file.

Where would I look up costs for using aspose-cells-python for a development and server license?

@nvartak
Please visit the following link to purchase related products. You can also check the Purchase section at the top of the page for more information.

For information about License, please refer to the following document.

Thank you. We have a current & valid Aspose.Total.NET license which I tried to use using the information provided in the licensing link, but it gave me this error in PyCharm debugger:

File “C:\Program Files\JetBrains\PyCharm 2024.3\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py”, line 18, in execfile
exec(compile(contents+“\n”, file, ‘exec’), glob, loc)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\myusername\Documents\mytestscriptfile.py”, line 12
license.set_license(“C:\Users<myusername>\Documents\Aspose.Total.NET.lic”);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
python-BaseException

@nvartak,

Since you are trying to use Aspose.Total for .NET license with Aspose.Cells for Python via .NET API, so you will get error as this license is not valid for Aspose.Cells for Python APIs, this license is valid for Aspose.Total for .NET APIs. You would either need to have Aspose.Total for Python via .NET license to work with all Aspose.Total for Python via .NET APIs or Aspose.Cells for Python via .NET license to work with Aspose.Cells for Python via .NET API.

@nvartak ,

The first backslash in license path string is being interpreted as a special character. In fact, because it’s followed by a “U”, it’s being interpreted as the start of a Unicode code point.

Please add ‘r’ before the license path.

license.set_license(r"C:\Users<myusername>\Documents\Aspose.Total.NET.lic");

Then if your license is not for Aspose.Cells for Python via .NET, an exception will occur indicating that “The license is not valid for this product.”

Thank you, Peyton Xu.

@nvartak,

You are welcome. If you have any more questions or feedback, don’t hesitate to reach out to us again.