Spreadsheet Operations with Aspose.Cells FOSS

Overview

Aspose.Cells FOSS enables core spreadsheet data operations in Python, including reading, writing, and manipulating cell values, formulas, and styles. It supports CSV import/export via CSVHandler, cell-level value handling per ECMA-376 via CellValueHandler, and encryption workflows using AgileEncryptionParameters and CFB-based readers/writers.

This page covers operations for cell value parsing and formatting, CSV file handling, and encryption setup, ideal when migrating from openpyxl or integrating spreadsheet logic into Python workflows without external dependencies. Key classes include Cell, CSVHandler, CellValueHandler, AgileEncryptionParameters, CFBReader, and CFBWriter.

Working with Data

Aspose.Cells FOSS provides core data manipulation capabilities through the Cell, AutoFilter, and CSVHandler classes. Developers can read, write, and modify cell values, formulas, and styles, apply filters to ranges, and import/export data in CSV format using documented methods from the API surface.

Reading Cell Data

Use the Cell class to retrieve cell values and formulas. Access the value and formula properties after obtaining a Cell instance from a worksheet’s cells collection.

import aspose.cells_foss

workbook = aspose.cells.Workbook()
worksheet = workbook.worksheets[0]
cell = worksheet.cells.get('A1')
cell_value = cell.value
print(cell_value)

Writing Cell Data

Assign values or formulas to cells using the value and formula properties on a Cell instance.

import aspose.cells_foss

workbook = aspose.cells.Workbook()
worksheet = workbook.worksheets[0]
cell = worksheet.cells.get('A1')
cell.value = "Hello, Aspose.Cells FOSS!"
cell.formula = "=SUM(1,2)"

Modifying Data with AutoFilter

Apply or inspect auto filters using the AutoFilter class. Access the AutoFilter instance from a worksheet and use range to define the filtered range or filter_columns to inspect applied filters.

import aspose.cells_foss

workbook = aspose.cells.Workbook()
worksheet = workbook.worksheets[0]
auto_filter = worksheet.auto_filter
auto_filter.range = "A1:C10"
filter_cols = auto_filter.filter_columns

Importing and Exporting CSV Data

Use CSVHandler to load or save workbook data as CSV. Static methods like load_csv() and save_csv() handle file-based CSV operations with optional configuration via CSVLoadOptions and CSVSaveOptions.

import aspose.cells_foss

workbook = aspose.cells.Workbook()
aspose.cells.CSVHandler.load_csv(workbook, 'data.csv')
aspose.cells.CSVHandler.save_csv(workbook, 'output.csv', None)

Code Examples

Aspose.Cells FOSS enables core spreadsheet operations in Python using classes like Workbook, Worksheet, Cell, and AutoFilter. The following examples demonstrate loading CSV data, setting cell values, and applying basic formatting using only documented API methods.

import aspose.cells_foss

# Load CSV data into a workbook
workbook = aspose.cells.Workbook()
aspose.cells.CSVHandler.load_csv(workbook, "data.csv", None)

# Access the first worksheet and set a cell value
worksheet = workbook.worksheets[0]
cell = worksheet.cells.get("A1")
cell.value = "Updated Value"

# Save the workbook as XLSX
workbook.save("output.xlsx")
import aspose.cells_foss

# Create a new workbook and worksheet
workbook = aspose.cells.Workbook()
worksheet = workbook.worksheets[0]

# Write values and set up an autofilter on a range
worksheet.cells.get("A1").value = "Aligned Text"
worksheet.auto_filter.range = "A1:C10"

# Save the result
workbook.save("filtered.xlsx")

Notes and Best Practices

When using Aspose.Cells FOSS in Python, manage memory efficiently by disposing Workbook instances after use, especially when processing large files. Avoid holding multiple Workbook objects in memory simultaneously to prevent excessive resource consumption.

  • Use Workbook.save() with explicit file paths to avoid unintended in-memory buffering.
  • Prefer CSVLoadOptions and CSVSaveOptions for high-throughput text-based workflows over binary formats.
  • Limit use of AutoFilter and complex styling on large ranges, as these operations increase memory footprint.
  • Ensure Workbook objects are not retained longer than necessary; release references promptly after operations complete.

See Also

Aspose.Cells FOSS provides core spreadsheet operations through classes like Workbook, Worksheet, Cell, AutoFilter, and CSVHandler. For related workflows, see the guides below.