How to Load Files with Aspose.Cells FOSS

How to Load Files with Aspose.Cells FOSS

Problem

Load spreadsheet files (XLSX, CSV) into Aspose.Cells FOSS for programmatic manipulation. The Workbook class accepts a file path and returns an in-memory workbook ready for reading or editing.

from aspose.cells_foss import Workbook

# Load an XLSX file
workbook = Workbook("input.xlsx")
worksheet = workbook.worksheets[0]

Prerequisites

To load files using Aspose.Cells FOSS in Python, ensure you have Python 3.7 or later installed. Install the library using pip with the command pip install aspose-cells-foss>=26.3.1. After installation, import the library using from aspose.cells_foss import Workbook.

  • Python 3.7 or later
  • pip package manager
  • aspose-cells-foss>=26.3.1 installed via pip
  • Basic understanding of Python file handling

Loading the File

Aspose.Cells FOSS loads spreadsheet data from file paths using the Workbook class. Pass a local file path string directly to the constructor. Stream loading (e.g., io.BytesIO) is not supported — pass a file path string only. To load CSV files, use the load_csv_workbook() convenience function.

from aspose.cells_foss import Workbook

# Load from file path (XLSX only)
workbook = Workbook("data.xlsx")

When loading CSV files, use the load_csv_workbook() function which creates and returns a new Workbook populated with the CSV data.

Code Example

This example demonstrates loading an XLSX file and a CSV file, then reading a cell value from each.

from aspose.cells_foss import Workbook, load_csv_workbook

# Load an XLSX workbook from a file path
workbook = Workbook("input.xlsx")
worksheet = workbook.worksheets[0]

# Read a cell value using the .value property
val = worksheet.cells["A1"].value
print(f"A1 value: {val}")

# Load a CSV file using load_csv_workbook
csv_workbook = load_csv_workbook("data.csv")
csv_worksheet = csv_workbook.worksheets[0]

# Read from the CSV-sourced workbook
csv_val = csv_worksheet.cells["A1"].value
print(f"CSV A1 value: {csv_val}")

Supported Formats

Aspose.Cells FOSS accepts XLSX and CSV files as input.

FormatExtensionNotes
XLSX.xlsxStandard Office Open XML format; use Workbook("file.xlsx")
CSV.csvComma-separated values; use load_csv_workbook("file.csv")

See Also

 English