Worksheet — Single sheet in an Aspose.Cells FOSS Workbook

Overview

Worksheet represents a single sheet within a Workbook. It provides access to the cell collection, chart collection, picture collection, shapes collection, and the auto-filter for that sheet. Worksheets are accessed by index or name from workbook.worksheets.

from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]

worksheet.cells["A1"].value = "Hello"
worksheet.cells["A2"].formula = "=A1"
workbook.save("output.xlsx")

Properties

NameTypeDescription
namestrThe worksheet tab name. Assign to rename the sheet.
cellsCellsThe cell collection for this sheet. Supports A1-style and (row, col) indexing.
chartsChartCollectionThe collection of charts embedded in this sheet.
shapescollectionThe collection of shapes (text boxes, pictures, rectangles, etc.) in this sheet.
auto_filterAutoFilterThe auto-filter object for this sheet. Use auto_filter.range to set the filter range.

Methods

MethodReturn TypeDescription
protect(password=None)NonePassword-protects the worksheet, preventing edits.
unprotect(password=None)NoneRemoves protection from the worksheet.

Example

The following example creates a worksheet, sets values and a formula, applies a style to a header cell, and saves the workbook.

from aspose.cells_foss import Workbook

workbook = Workbook()
ws = workbook.worksheets[0]
ws.name = "Sales"

# Set header and data values
ws.cells["A1"].value = "Month"
ws.cells["B1"].value = "Revenue"
ws.cells["A2"].value = "January"
ws.cells["B2"].value = 12500
ws.cells["A3"].value = "February"
ws.cells["B3"].value = 14800

# Add a SUM formula
ws.cells["B4"].formula = "=SUM(B2:B3)"

# Apply bold styling to the header row
style = ws.cells["A1"].get_style()
style.font.bold = True
ws.cells["A1"].apply_style(style)
style2 = ws.cells["B1"].get_style()
style2.font.bold = True
ws.cells["B1"].apply_style(style2)

workbook.save("sales_report.xlsx")

See Also