How to Get Started with Aspose.Cells FOSS for Python

How to Get Started with Aspose.Cells FOSS for Python

aspose-cells-foss for Python is a free, MIT-licensed library for creating, reading, and converting spreadsheet files — no Microsoft Office required, no native extensions, pure Python from PyPI.

Step-by-Step Guide

Step 1: Install the Package

Install from PyPI with pip:

pip install aspose-cells-foss>=26.3.1

Verify the install:

from aspose.cells_foss import Workbook
print("aspose-cells-foss is ready.")

Step 2: Import Required Classes

from aspose.cells_foss import Workbook, SaveFormat

Step 3: Create a Workbook and Write Data

Use Workbook() to create a new workbook. Add a worksheet with add_worksheet(), then access its cell grid via the cells property and use Cells.cell(row, col) to get a Cell. Set values with Cell.put_value():

from aspose.cells_foss import Workbook, SaveFormat

wb = Workbook()
ws = wb.add_worksheet("Sales")

cells = ws.cells
cells.cell(0, 0).put_value("Product")
cells.cell(0, 1).put_value("Revenue")
cells.cell(1, 0).put_value("Widget A")
cells.cell(1, 1).put_value(12500)
cells.cell(2, 0).put_value("Widget B")
cells.cell(2, 1).put_value(8750)

wb.save("sales.xlsx", SaveFormat.XLSX)
print("sales.xlsx written.")

Step 4: Read the Workbook Back

Load an existing file by passing the file path to Workbook(file_path). Use get_worksheet() by index or name, then read cell values via the value property:

from aspose.cells_foss import Workbook

wb = Workbook("sales.xlsx")
ws = wb.get_worksheet(0)
cells = ws.cells

print(f"A1: {cells.cell(0, 0).value}")
print(f"B2: {cells.cell(1, 1).value}")

Step 5: Save to Other Formats

Workbook.save() supports multiple formats via SaveFormat. Use SaveFormat.CSV for comma-separated output and SaveFormat.MARKDOWN for Markdown tables:

from aspose.cells_foss import Workbook, SaveFormat

wb = Workbook("sales.xlsx")
wb.save("sales.csv", SaveFormat.CSV)
wb.save("sales.md", SaveFormat.MARKDOWN)
print("CSV and Markdown exports written.")

Common Issues and Fixes

ModuleNotFoundError: No module named 'aspose' Install the package in the active virtual environment: pip install aspose-cells-foss. Confirm with pip show aspose-cells-foss.

FileNotFoundError when loading a workbook Use pathlib.Path to build portable paths: Workbook(str(Path("data") / "file.xlsx")).

Cell value returns None after reading The cell is empty or out of range. Use Cell.is_empty() to check before reading value.

CSV output contains only the first sheet save() with SaveFormat.CSV exports the active worksheet only. Use set_active_worksheet() to select the sheet you want to export before saving.

XLSX file is not opened by Excel Ensure you pass SaveFormat.XLSX explicitly. Without it the format is inferred from the file extension; if the path has no .xlsx extension the output may not be valid.

Frequently Asked Questions

Does aspose-cells-foss require Microsoft Office?

No. The library reads and writes spreadsheet files natively in pure Python without any dependency on Microsoft Office, COM automation, or Windows APIs.

Which Python versions are supported?

Python 3.7 or later. The package runs on Windows, macOS, Linux, and Docker containers.

Is the library free for commercial use?

Yes. It is released under the MIT License. You may use, modify, and redistribute it for any purpose, including commercial applications.

How do I iterate over all cells in a sheet?

Use Cells.iter_rows() to iterate row by row:

from aspose.cells_foss import Workbook

wb = Workbook("data.xlsx")
ws = wb.get_worksheet(0)
for row in ws.cells.iter_rows(0, None, 0, None, values_only=True):
    print(row)

Which formats can I save to?

SaveFormat supports XLSX, CSV, TSV, MARKDOWN, and JSON. Use SaveFormat.from_extension(file_path) to detect the format automatically from a file path.

See Also