`cells` -- Cell collection with A1 and (row, col) access

Overview

The cells module provides a collection of Cell objects representing spreadsheet cells, supporting both A1-style string keys and (row, col) integer indexing. It is accessed via Worksheet.cells and integrates with the Workbook root object for file I/O and worksheet management.

import aspose.cells_foss

wb = aspose.cells.Workbook()
ws = wb.worksheets[0]
ws.cells["A1"].value = "Revenue"
ws.cells[1, 1].value = 42

Constructor

The Cells class provides a collection of Cell objects with both A1-style and (row, col)-style access. It is exposed as the cells property on Worksheet instances and supports indexing via string keys like “A1” or integer tuples like (0, 0).

from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]
cells = worksheet.cells
NameTypeDescription
cellsCellsCell collection with A1 and (row, col) access
SaveFormatEnumEnum for controlling output format (XLSX, CSV, TSV, MARKDOWN, JSON)

Properties

The cells collection provides access to individual Cell objects via A1-style keys or (row, col) indices. Each Cell exposes formatting and content properties through its style and other read-only attributes.

NameTypeDescription
valuestrThe cell value (assign directly: ws.cells["A1"].value = x)
formulastrThe cell formula (assign directly: ws.cells["A2"].formula = "=SUM(A1:A5)")
styleStyleCell formatting: font, fill, borders, number format, alignment
commentstrThe cell comment
data_typestrThe cell data type

AutoFilter Properties

The AutoFilter object is accessed via worksheet.auto_filter. It provides properties to inspect and configure filtering behavior on a worksheet range.

PropertyTypeDescription
rangestrThe cell range to which the auto filter is applied (e.g., “A1:D10”).
filter_columnslistThe list of column filter settings.
sort_statedictThe current sort state configuration.

Example

The following example demonstrates basic cell manipulation and shape creation using Aspose.Cells FOSS. It sets cell values, applies font styling, and adds a rounded rectangle shape with text and fill formatting. This covers the Cell class for cell representation and the Shape class for drawing objects.

from aspose.cells_foss import Workbook, MsoDrawingType

# Create a new workbook and access the first worksheet
workbook = Workbook()
worksheet = workbook.worksheets[0]

# Set and style a cell
worksheet.cells["A1"].value = "Styled Cell"
style = worksheet.cells["A1"].get_style()
style.font.bold = True
style.font.color = "#FF0000"
worksheet.cells["A1"].apply_style(style)

# Add a rounded rectangle shape with text and fill
shape = worksheet.shapes.add(MsoDrawingType.ROUNDED_RECTANGLE, 1, 1, 5, 5)
shape.text = "Hello Shape"
shape.fill.fore_color = "90EE90"

# Save the workbook
workbook.save("example.xlsx")

See Also

The Cells class represents a collection of cells in a worksheet and supports both A1-style and (row, col)-style access. Related classes include Cell for individual cell operations and SparklineGroup for managing sparkline visual styles.