Aspose.Cells FOSS for Python

Package Information

PyPI packageaspose-cells-foss
Python importfrom aspose.cells_foss import ...
Version26.3.1
LicenseMIT
Python requirement>= 3.7
Dependenciespycryptodome>=3.15.0, olefile>=0.46

Modules

ModuleDescription
aspose.cells_fossCore spreadsheet API: workbooks, worksheets, cells, styles, charts, format handlers

Note: There is no aspose.pydrawing module in Aspose.Cells FOSS. Colors are expressed as 8-digit AARRGGBB hex strings (e.g., "FFFF0000" for opaque red).


aspose.cells_foss

Classes

ClassPageDescription
WorkbookworkbookEntry point for creating, loading, and saving spreadsheet files
WorksheetworksheetRepresents a single sheet; provides access to cells, charts, and pictures
CellscellsDictionary-like collection of Cell objects within a Worksheet
CellcellRepresents an individual cell; value, formula, and style
StylestyleCell formatting: font, fill, borders, alignment, number format, protection
FontstyleFont properties: name, size, color, bold, italic, underline, strikethrough
FillstyleBackground fill: solid, gradient, or pattern
NumberFormatstyleBuilt-in number format lookup utilities
SaveFormatworkbookEnumeration of supported output formats (XLSX, CSV, MARKDOWN, JSON)
ChartchartRepresents a chart embedded in a worksheet
ChartTypechartEnum: LINE, BAR, PIE, AREA, STOCK, and more
NSerieschartData series collection on a chart
ChartSerieschartA single data series with values, categories, and error bars
ChartAxischartAxis settings: scale, format, title
ChartView3Dchart3D rotation and perspective settings
ChartErrorBarschartError bar configuration for a series
DataValidationdata-validationSingle validation rule on a cell range
DataValidationCollectiondata-validationAll validation rules for a worksheet
DataValidationTypedata-validationEnum: WHOLE_NUMBER, DECIMAL, LIST, DATE, TIME, TEXT_LENGTH, CUSTOM
DataValidationOperatordata-validationEnum: BETWEEN, EQUAL, GREATER_THAN, etc.
DataValidationAlertStyledata-validationEnum: STOP, WARNING, INFORMATION
CSVHandlercsv-handlerStatic methods for CSV export and CSV data handling
CSVLoadOptionscsv-handlerOptions for loading CSV files
CSVSaveOptionscsv-handlerOptions for saving CSV files
MarkdownHandlermarkdown-handlerStatic methods for Markdown export
MarkdownSaveOptionsmarkdown-handlerOptions for Markdown export
JsonHandlerjson-handlerStatic methods for JSON export
JsonSaveOptionsjson-handlerOptions for JSON export
ShapeshapeDrawing shape with fill, line, text, and font formatting
ShapeCollectionshapeAll shapes in a worksheet (ws.shapes)
MsoDrawingTypeshapeEnum: RECTANGLE, OVAL, TEXT_BOX, ARROW, etc.
TabletableExcel table (structured reference) in a worksheet
TableCollectiontableAll tables in a worksheet (ws.tables)
TableColumntableColumn definition within a Table
TableStyleInfotableVisual style settings for a Table
SparklineGroupsparklineGroup of sparkline charts sharing a visual style
SparklineGroupCollectionsparklineAll sparkline groups (ws.sparkline_groups)
SparklinesparklineA single sparkline cell linked to a data range
SparklineTypesparklineEnum: LINE, COLUMN, WIN_LOSS
HorizontalPageBreakCollectionpage-breakManual horizontal page breaks (ws.horizontal_page_breaks)
VerticalPageBreakCollectionpage-breakManual vertical page breaks (ws.vertical_page_breaks)
AgileEncryptionParametersencryptionAES-256/SHA-512 encryption parameters (recommended)
StandardEncryptionParametersencryptionLegacy AES-128/SHA-1 encryption parameters
CipherAlgorithmencryptionEnum: AES_128, AES_192, AES_256
HashAlgorithmencryptionEnum: SHA1, SHA256, SHA384, SHA512

Workbook

Constructors

SignatureDescription
Workbook()Create a new empty workbook (XLSX format)
Workbook(file_path: str)Load a workbook from a file path
Workbook(file_path: str, password: str)Load a password-protected workbook

Key Properties

PropertyTypeDescription
worksheetslistAccess worksheets by index: workbook.worksheets[0]

Key Methods

MethodReturnDescription
save(file_path)NoneSave to file; format inferred from extension
save(file_path, save_format)NoneSave with explicit SaveFormat
save_as_csv(file_path, options=None)NoneSave as CSV
save_as_markdown(file_path, options=None)NoneSave as Markdown tables
save_as_json(file_path, options=None)NoneSave as JSON
load_csv(file_path, options=None)NonePopulate the workbook from a CSV file
add_worksheet(name=None)WorksheetAdd a new worksheet
get_worksheet(index_or_name)WorksheetGet worksheet by index or name
remove_worksheet(index_or_name)NoneRemove a worksheet
copy_worksheet(index_or_name_or_ws)WorksheetCopy an existing worksheet
protect(password=None, lock_structure=True)NonePassword-protect the workbook
unprotect(password=None)NoneRemove workbook protection
is_protected()boolCheck if the workbook is protected

Worksheet

Key Properties

PropertyTypeDescription
namestrWorksheet tab name
cellsCellsAll cells in this worksheet
chartsChartCollectionAll charts in this worksheet

Cells

Cells supports dictionary-style access by cell address string.

Access Patterns

# Read a cell value
value = ws.cells["A1"].value

# Set a cell value directly
ws.cells["A1"].value = "Hello"

# Assign a Cell object
from aspose.cells_foss import Cell
ws.cells["A1"] = Cell(42)
ws.cells["A2"] = Cell(3.14)
ws.cells["A3"] = Cell("Hello World")
ws.cells["A4"] = Cell(None, "=SUM(A1:A3)")   # formula cell

Cell

Constructor

SignatureDescription
Cell(value=None)Create a cell with a value (int, float, str, or None)
Cell(value, formula)Create a formula cell (value is typically None)

Key Properties

PropertyTypeDescription
valueAnyCell value (str, int, float, or None)
formulastrFormula string (e.g., "=SUM(A1:A5)")
styleStyleCell style (font, fill)

Style

PropertyTypeDescription
fontFontFont settings for this style
fillFillBackground fill settings

Font

Colors are expressed as 8-digit AARRGGBB hex strings without a # prefix. Examples: "FFFF0000" = opaque red, "FF0000FF" = opaque blue, "FF000000" = black.

PropertyTypeDefaultDescription
namestrCalibriFont family name
sizefloat11Font size in points
colorstrFF0000008-digit AARRGGBB hex color string
boldboolFalseBold text
italicboolFalseItalic text
underlineboolFalseUnderlined text
strikethroughboolFalseStrikethrough text

Constructor

Font(name="Calibri", size=11, color="FF000000",
     bold=False, italic=False, underline=False, strikethrough=False)

Fill

MethodDescription
set_solid_fill(color)Solid background; color is an 8-digit AARRGGBB hex string
set_pattern_fill(pattern_type, fg_color, bg_color)Patterned fill
set_no_fill()Remove background fill

MarkdownHandler

MethodReturnDescription
MarkdownHandler.save_markdown_to_string(workbook)strExport workbook to a Markdown string in memory

MarkdownSaveOptions

PropertyTypeDefaultDescription
default_alignmentstrleftColumn alignment: left, right, or center
include_worksheet_nameboolTrueWhether to include the sheet name as a heading
header_levelint2Markdown heading level (1-6)
worksheet_indexint0Sheet index to export; -1 exports all sheets

ChartCollection

Charts are added using dedicated per-type methods. Row and column indices are zero-based.

MethodReturnDescription
add_bar(top_row, left_col, bottom_row, right_col)ChartAdd a column (vertical bar) chart
add_line(top_row, left_col, bottom_row, right_col)ChartAdd a line chart
add_pie(top_row, left_col, bottom_row, right_col)ChartAdd a pie chart

Chart

PropertyTypeDescription
titlestrChart title as a plain string (not .title.text)
category_datastrCell range for x-axis category labels
n_seriesNSeriesData series collection
show_legendboolWhether to display the legend
legend_positionstrLegend position: right, bottom, left, or top

NSeries

MethodDescription
add(data_range, category_data=None, name=None)Add a named data series

SaveFormat Enumeration

ConstantOutput Format
SaveFormat.XLSXExcel XML format (default)
SaveFormat.CSVComma-separated values
SaveFormat.TSVRead-only constant. workbook.save() does not support TSV — raises ValueError at runtime.
SaveFormat.MARKDOWNMarkdown tables
SaveFormat.JSONJSON-structured data

Note: SaveFormat.PDF, SaveFormat.HTML, SaveFormat.PNG, SaveFormat.TIFF, SaveFormat.DOCX, and SaveFormat.PPTX are not available in Aspose.Cells FOSS. These formats require the commercial aspose-cells-python package.


Code Examples

Create, style, and save a workbook

from aspose.cells_foss import Workbook, Cell

wb = Workbook()
ws = wb.worksheets[0]

ws.cells["A1"].value = "Revenue Report"
ws.cells["A2"].value = 125000

ws.cells["A1"].style.font.bold = True
ws.cells["A1"].style.font.size = 14
ws.cells["A1"].style.font.color = "FF1E64C8"   # Blue (AARRGGBB, no #)

wb.save("report.xlsx")

Export to Markdown in memory

from aspose.cells_foss import Workbook, Cell, MarkdownHandler

wb = Workbook()
ws = wb.worksheets[0]
ws.cells["A1"].value = "Name"
ws.cells["B1"].value = "Score"
ws.cells["A2"].value = "Alice"
ws.cells["B2"].value = 95

md = MarkdownHandler.save_markdown_to_string(wb)
print(md)

Build a line chart

from aspose.cells_foss import Workbook, Cell

wb = Workbook()
ws = wb.worksheets[0]

for i, (m, v) in enumerate([("Jan", 50), ("Feb", 80), ("Mar", 120)], start=2):
    ws.cells[f"A{i}"].value = m
    ws.cells[f"B{i}"].value = v

chart = ws.charts.add_line(5, 0, 18, 7)
chart.title = "Monthly Trend"
chart.category_data = "A2:A4"
chart.n_series.add("B2:B4", category_data="A2:A4", name="Sales")

wb.save("trend.xlsx")

Related Resources