Workbook — Aspose.Cells FOSS for Python API Reference

The Workbook class is the root object for all spreadsheet operations in aspose-cells-foss. It manages worksheets, handles file I/O, and provides access to document properties.

Package: aspose.cells_foss

from aspose.cells_foss import Workbook

Constructor

Workbook(path=None, password=None)
ParameterTypeDescription
pathstr | NoneFile path to open. Pass None (or omit) to create an empty workbook.
passwordstr | NoneDecryption password for AES-encrypted files. Only required when opening a protected file.

Examples:

from aspose.cells_foss import Workbook

# Create a new empty workbook
wb = Workbook()

# Open an existing XLSX file
wb = Workbook("report.xlsx")

# Open an AES-encrypted file
wb = Workbook("protected.xlsx", password="secret")

Properties

PropertyTypeAccessDescription
worksheetsWorksheetCollectionReadOrdered collection of worksheets. Access by index (wb.worksheets[0]) or add via wb.worksheets.add(name).
document_propertiesDocumentPropertiesReadCore and custom document metadata (title, author, subject, custom key-value pairs).

Methods

save

wb.save(path, password=None)

Save the workbook to a file. The output format is determined automatically from the file extension.

ParameterTypeDescription
pathstrDestination file path. Use .xlsx, .xls, or .csv extension.
passwordstr | NoneIf provided, the output file is encrypted with AES using this password.

Examples:

wb.save("output.xlsx")        # XLSX: default format
wb.save("output.xls")         # XLS: legacy binary format
wb.save("output.csv")         # CSV: first worksheet only
wb.save("protected.xlsx", password="secret")  # encrypted XLSX

save_as_markdown

wb.save_as_markdown(path)

Export the first worksheet as a GitHub-flavored Markdown table.

ParameterTypeDescription
pathstrDestination .md file path.
wb.save_as_markdown("output.md")

worksheets (WorksheetCollection methods)

MethodSignatureDescription
add(name: str) -> WorksheetAppend a new worksheet with the given name and return it.
__getitem__[index: int] -> WorksheetReturn the worksheet at zero-based index.
__len__() -> intNumber of worksheets in this workbook.

Usage Examples

Basic Workbook Workflow

from aspose.cells_foss import Workbook

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

ws.cells["A1"].put_value("Quarter")
ws.cells["B1"].put_value("Revenue")
ws.cells["A2"].put_value("Q1")
ws.cells["B2"].put_value(42000)
ws.cells["A3"].put_value("Q2")
ws.cells["B3"].put_value(58000)
ws.cells["B4"].formula = "=SUM(B2:B3)"

wb.save("sales.xlsx")

Add Multiple Worksheets

from aspose.cells_foss import Workbook

wb = Workbook()
wb.worksheets[0].name = "Summary"
ws2 = wb.worksheets.add("Details")
ws3 = wb.worksheets.add("Charts")

print(len(wb.worksheets))   # 3
wb.save("multi-sheet.xlsx")

Open, Modify, and Re-save

from aspose.cells_foss import Workbook

wb = Workbook("existing.xlsx")
ws = wb.worksheets[0]
ws.cells["C1"].put_value("Updated")
wb.save("existing.xlsx")    # overwrite in place

Encrypt on Save

from aspose.cells_foss import Workbook

wb = Workbook("report.xlsx")
wb.save("report-secure.xlsx", password="MyPassword123")

See Also