API Reference

This section contains the automatically generated API documentation extracted from the source code.

class pyopenxlsx.Alignment(horizontal=None, vertical=None, wrap_text=False)[source]

Bases: object

horizontal()[source]
Return type:

Optional[XLAlignmentStyle]

set_horizontal(value)[source]
Return type:

None

set_vertical(value)[source]
Return type:

None

set_wrap_text(value)[source]
Return type:

None

vertical()[source]
Return type:

Optional[XLAlignmentStyle]

wrap_text()[source]
Return type:

bool

class pyopenxlsx.Border(left=None, right=None, top=None, bottom=None, diagonal=None, outline=None)[source]

Bases: object

bottom()[source]
Return type:

Side

diagonal()[source]
Return type:

Side

left()[source]
Return type:

Side

right()[source]
Return type:

Side

set_bottom(style, color)[source]
Return type:

None

set_diagonal(style, color)[source]
Return type:

None

set_left(style, color)[source]
Return type:

None

set_right(style, color)[source]
Return type:

None

set_top(style, color)[source]
Return type:

None

top()[source]
Return type:

Side

class pyopenxlsx.Cell(raw_cell, worksheet=None)[source]

Bases: object

Represents an Excel cell.

Uses weak references to worksheet and workbook to avoid circular references that could delay garbage collection.

property alignment
property border
property comment
property fill
property font
property formula
property is_date

Returns True if the cell is formatted as a date/time. Requires workbook to be passed to Cell constructor.

property style
property style_index
property value
class pyopenxlsx.Column(raw_column, worksheet=None)[source]

Bases: object

Represents an Excel column.

Uses weak references to avoid circular references with Worksheet/Workbook.

property hidden
property style_index
property width
class pyopenxlsx.DataValidation(raw_dv, worksheet=None)[source]

Bases: object

Represents an Excel data validation rule.

add_cell(cell_ref)[source]

Add a cell to the validation range.

Return type:

None

add_range(range_ref)[source]

Add a range to the validation.

Return type:

None

property allow_blank

Whether blank values are allowed.

property error

The error message.

property error_style

Get the error style.

property error_title

The title of the error message.

property formula1

The first formula for the validation.

property formula2

The second formula for the validation.

property ime_mode

Get the IME mode.

property operator

Get the validation operator.

property prompt

The prompt message.

property prompt_title

The title of the prompt message.

set_error(title, message, style='stop')[source]

Set the error message title, message and style. Style can be ‘stop’, ‘warning’, or ‘information’.

Return type:

None

set_list(items)[source]

Set a list of allowed values.

Return type:

None

set_prompt(title, message)[source]

Set the input prompt title and message.

Return type:

None

set_reference_drop_list(sheet_name, range_ref)[source]

Set a drop-down list from a range reference on another sheet.

Return type:

None

property show_drop_down

Whether to show a drop-down list.

property show_error_message

Whether to show the error message.

property show_input_message

Whether to show the input message.

property sqref

Get the range (sqref) this validation applies to.

property type

Get the validation type.

class pyopenxlsx.DataValidations(raw_dvs, worksheet=None)[source]

Bases: object

Manages all data validation rules in a worksheet.

add_validation(sqref, type='none', operator='between', formula1='', formula2='', **kwargs)[source]

Convenience method to add a data validation rule.

Return type:

DataValidation

append()[source]

Append a new empty data validation rule.

Return type:

DataValidation

clear()[source]

Clear all data validation rules.

Return type:

None

remove(index_or_sqref)[source]

Remove a data validation rule by index or sqref.

Return type:

None

class pyopenxlsx.Fill(pattern_type=XLPatternType.Solid, color=None, background_color=None)[source]

Bases: object

background_color()[source]
Return type:

Optional[XLColor]

color()[source]
Return type:

Optional[XLColor]

pattern_type()[source]
Return type:

XLPatternType

set_background_color(value)[source]
Return type:

None

set_color(value)[source]
Return type:

None

set_pattern_type(value)[source]
Return type:

None

class pyopenxlsx.Font(name='Arial', size=11, bold=False, italic=False, color=None)[source]

Bases: object

bold()[source]
Return type:

bool

color()[source]
Return type:

XLColor

italic()[source]
Return type:

bool

name()[source]
Return type:

str

set_bold(value)[source]
Return type:

None

set_color(value)[source]
Return type:

None

set_italic(value)[source]
Return type:

None

set_name(value)[source]
Return type:

None

set_size(value)[source]
Return type:

None

size()[source]
Return type:

int

class pyopenxlsx.Formula(raw_cell)[source]

Bases: object

Wrapper for Excel formulas. Allows interacting with the formula assigned to a cell.

clear()[source]

Clear the formula from the cell.

Return type:

None

property text

Get or set the formula string.

class pyopenxlsx.FormulaEngine[source]

Bases: object

Lightweight formula evaluation engine.

evaluate(formula, worksheet=None)[source]

Evaluate a formula string. If a worksheet is provided, cell references within the formula will be resolved.

Return type:

Any

class pyopenxlsx.ImageInfo

Bases: object

property extension

File extension (e.g., ‘png’)

property name

Image filename (e.g., ‘image1.png’)

property path

Full path in archive (e.g., ‘xl/media/image1.png’)

class pyopenxlsx.PageMargins(raw_margins, worksheet=None)[source]

Bases: object

Represents the page margins of a worksheet. Values are in inches.

property bottom
property footer
property header
property left
property right
property top
class pyopenxlsx.PageSetup(raw_setup, worksheet=None)[source]

Bases: object

Represents the page setup of a worksheet.

property black_and_white

Whether to print in black and white.

property fit_to_height

The number of pages to fit to height.

property fit_to_width

The number of pages to fit to width.

property orientation

The page orientation (XLPageOrientation).

property paper_size

The paper size (Excel internal paper size enumeration).

property scale

The print scale (in percentage).

class pyopenxlsx.PrintOptions(raw_options, worksheet=None)[source]

Bases: object

Represents the print options of a worksheet.

property grid_lines

Whether grid lines are printed.

property headings

Whether row and column headings are printed.

property horizontal_centered

Whether content is horizontally centered on the page.

property vertical_centered

Whether content is vertically centered on the page.

class pyopenxlsx.Protection(locked=True, hidden=False)[source]

Bases: object

pyopenxlsx.PythonMergeCells

alias of MergeCells

class pyopenxlsx.Range(raw_range, worksheet=None)[source]

Bases: object

Represents a range of Excel cells.

Uses weak references to avoid circular references with Worksheet.

property address
clear()[source]
Return type:

None

async clear_async()[source]
Return type:

None

property num_columns
property num_rows
class pyopenxlsx.Side(style=XLLineStyle.Thin, color=None)[source]

Bases: object

color()[source]
Return type:

XLColor

style()[source]
Return type:

XLLineStyle

class pyopenxlsx.Style(font=None, fill=None, border=None, alignment=None, number_format=None, protection=None)[source]

Bases: object

class pyopenxlsx.Table(raw_table, worksheet=None)[source]

Bases: object

Represents an Excel Table (ListObject).

append_column(name)[source]

Append a new column to the table.

property display_name

The display name of the table.

property name

The name of the table. Table names cannot have spaces.

property range

The range reference of the table (e.g., ‘A1:C10’).

property show_column_stripes

Whether column stripes are shown.

property show_first_column

Whether the first column is highlighted.

property show_last_column

Whether the last column is highlighted.

property show_row_stripes

Whether row stripes are shown.

property show_totals_row

Whether the totals row is shown.

property style

The table style name (e.g., ‘TableStyleMedium2’).

class pyopenxlsx.Workbook(filename=None, force_overwrite=True, password=None)[source]

Bases: object

Represents an Excel workbook.

Uses WeakValueDictionary for worksheet caching to allow garbage collection of Worksheet objects when they are no longer referenced elsewhere.

property active
add_style(font=None, fill=None, border=None, alignment=None, number_format=None, protection=None)[source]
Return type:

int

async add_style_async(font=None, fill=None, border=None, alignment=None, number_format=None, protection=None)[source]
Return type:

int

close()[source]
Return type:

None

async close_async()[source]
Return type:

None

copy_worksheet(from_worksheet)[source]
Return type:

Worksheet

async copy_worksheet_async(from_worksheet)[source]
Return type:

Worksheet

create_sheet(title=None, index=None)[source]
Return type:

Worksheet

async create_sheet_async(title=None, index=None)[source]
Return type:

Worksheet

property custom_properties

Get the custom document properties.

property defined_names

Access the collection of defined names (named ranges) in the workbook.

extract_images(output_dir)[source]

Extract all embedded images to a directory.

Return type:

List[str]

Args:
output_dir: Directory path where images will be saved.

Will be created if it doesn’t exist.

Returns:

list[str]: List of paths to the extracted image files.

Example:
>>> wb = Workbook("test.xlsx")
>>> extracted = wb.extract_images("./images/")
>>> print(f"Extracted {len(extracted)} images")
async extract_images_async(output_dir)[source]

Async version of extract_images.

Return type:

List[str]

get_archive_entries()[source]

Get a list of all files/directories in the underlying zip archive.

Return type:

List[str]

Returns:

list[str]: List of entry paths.

get_archive_entry(path)[source]

Get the raw bytes of an entry from the underlying zip archive.

Return type:

bytes

Args:

path: Path in the archive (e.g., ‘xl/workbook.xml’).

Returns:

bytes: The raw binary data of the entry.

Raises:

RuntimeError: If the entry is not found in the archive.

get_embedded_images()[source]

Get a list of all embedded images in the workbook.

Return type:

List[Any]

Returns:

list[ImageInfo]: List of ImageInfo objects with name, path, and extension attributes.

Example:
>>> wb = Workbook("test.xlsx")
>>> images = wb.get_embedded_images()
>>> for img in images:
...     print(f"Found image: {img.name}")
get_image_data(image_path_or_name)[source]

Get the binary data of an embedded image.

Return type:

bytes

Args:
image_path_or_name: Either the full path (e.g., ‘xl/media/image1.png’)

or just the filename (e.g., ‘image1.png’)

Returns:

bytes: The raw binary data of the image.

Raises:

RuntimeError: If the image is not found in the archive.

Example:
>>> wb = Workbook("test.xlsx")
>>> images = wb.get_embedded_images()
>>> if images:
...     data = wb.get_image_data(images[0].name)
...     with open("extracted_image.png", "wb") as f:
...         f.write(data)
has_archive_entry(path)[source]

Check if the underlying zip archive contains an entry with the given path.

Return type:

bool

Args:

path: Path in the archive (e.g., ‘xl/workbook.xml’).

Returns:

bool: True if the entry exists.

property has_macro

Check if the loaded document contains a VBA macro project.

property properties
remove(worksheet)[source]
Return type:

None

async remove_async(worksheet)[source]
Return type:

None

save(filename=None, force_overwrite=True, password=None)[source]
Return type:

None

async save_async(filename=None, force_overwrite=True, password=None)[source]
Return type:

None

property sheetnames
property styles
property workbook
class pyopenxlsx.Worksheet(raw_sheet, workbook=None)[source]

Bases: object

Represents an Excel worksheet.

Uses WeakValueDictionary for cell caching to allow garbage collection of Cell objects when they are no longer referenced elsewhere.

add_comment(cell_ref, text, author='')[source]

Add a simple (legacy) comment.

add_conditional_formatting(sqref, rule)[source]

Add conditional formatting to a range.

Add an external hyperlink to a cell.

Parameters:
  • cell_ref (str) – Cell reference (e.g., ‘A1’).

  • url (str) – URL of the hyperlink.

  • tooltip (str) – Optional tooltip text.

Return type:

None

add_image(img_path, anchor='A1', width=None, height=None)[source]

Add an image to the worksheet.

Parameters:
  • img_path (str) – Path to the image file.

  • anchor (str) – Cell reference for the top-left corner of the image (e.g., ‘A1’).

  • width (Optional[int]) – Width of the image in pixels. If None, it will try to get it from the image.

  • height (Optional[int]) – Height of the image in pixels. If None, it will try to get it from the image.

Return type:

None

async add_image_async(img_path, anchor='A1', width=None, height=None)[source]
Return type:

None

Add an internal hyperlink (to another sheet or range) to a cell.

Parameters:
  • cell_ref (str) – Cell reference (e.g., ‘A1’).

  • location (str) – Destination in the workbook (e.g., ‘Sheet2!A1’).

  • tooltip (str) – Optional tooltip text.

Return type:

None

add_shape(row=1, col=1, shape_type='Rectangle', **kwargs)[source]

Add a vector shape to the worksheet.

Return type:

None

Args:

row (int): The 1-based row index to place the top-left corner. col (int): The 1-based column index to place the top-left corner. shape_type (str): The type of the shape (e.g., “Rectangle”, “Ellipse”, “Arrow”). **kwargs: Shape options including:

  • name (str): Shape name.

  • text (str): Text inside the shape.

  • fill_color (str): ARGB fill color.

  • line_color (str): ARGB line color.

  • line_width (float): Line width.

  • width (int): Width in pixels.

  • height (int): Height in pixels.

  • offset_x (int): Offset X in pixels.

  • offset_y (int): Offset Y in pixels.

  • end_row (int): End row for two-cell anchor.

  • end_col (int): End column for two-cell anchor.

  • end_offset_x (int): End offset X.

  • end_offset_y (int): End offset Y.

  • rotation (int): Rotation in degrees.

  • flip_h (bool): Flip horizontally.

  • flip_v (bool): Flip vertically.

  • line_dash (str): Line dash style (e.g., “dash”, “sysDash”).

  • arrow_start (str): Arrow start style.

  • arrow_end (str): Arrow end style.

  • horz_align (str): Horizontal text alignment (“l”, “ctr”, “r”).

  • vert_align (str): Vertical text alignment (“t”, “ctr”, “b”).

add_sparkline(location, data_range, sparkline_type=None, options=None)[source]

Add a sparkline to the worksheet.

add_table(name, range_string)[source]

Add a new table to the worksheet.

Parameters:
  • name (str) – Table name (no spaces).

  • range_string (str) – Range reference (e.g., ‘A1:C10’).

Return type:

Any

Returns:

Table object.

add_threaded_comment(cell_ref, text, author='')[source]

Add a modern threaded comment.

add_threaded_reply(parent_id, text, author='')[source]

Add a reply to a threaded comment.

append(iterable)[source]
Return type:

None

async append_async(iterable)[source]
Return type:

None

apply_auto_filter()[source]

Apply auto filter to the worksheet.

Return type:

None

property auto_filter

Get the AutoFilter object for the worksheet to manage filters. Returns None if no AutoFilter is set.

auto_fit_column(column_number)[source]

Auto-fit the specified column.

cell(row, column, value=None)[source]
Return type:

Cell

clear_all_conditional_formatting()[source]

Clear all conditional formatting.

Return type:

None

clear_panes()[source]

Clear all panes (frozen or split) from the worksheet.

Return type:

None

column(col)[source]

Get a Column object.

Return type:

Column

property data_validations

Get the DataValidations object for this worksheet to manage data validation rules.

delete_column(col_number, count=1)[source]

Delete one or more columns starting at the given column number (1-based).

Return type:

bool

delete_row(row_number, count=1)[source]

Delete one or more rows starting at the given row number (1-based).

Return type:

bool

property drawing

Get the drawing object for the worksheet.

freeze_panes(row_or_ref, col=None)[source]

Freeze the worksheet panes.

Parameters:
  • row_or_ref (Union[int, str]) – Row number (1-indexed) or a cell reference string (e.g., ‘B2’).

  • col (Optional[int]) – Column number (1-indexed). Only used if row_or_ref is an int.

Return type:

None

get_cell_value(row, column)[source]

Get a single cell’s value directly without creating a Cell object.

This is faster than ws.cell(row, col).value when you only need the value and don’t need to modify the cell or access other properties.

Parameters:
  • row (int) – Row number (1-indexed)

  • column (int) – Column number (1-indexed)

Returns:

The cell’s value (str, int, float, bool, or None)

async get_cell_value_async(row, column)[source]

Async version of get_cell_value().

Get the hyperlink target for a cell.

Return type:

str

get_range_data(start_row, start_col, end_row, end_col)[source]

Get a range of cells as list[list[Any]].

This is an optimized bulk read method for reading a specific range of cells without creating intermediate Cell objects.

Parameters:
  • start_row (int) – Starting row number (1-indexed)

  • start_col (int) – Starting column number (1-indexed)

  • end_row (int) – Ending row number (1-indexed, inclusive)

  • end_col (int) – Ending column number (1-indexed, inclusive)

Returns:

list[list[Any]] - Cell values in the range

async get_range_data_async(start_row, start_col, end_row, end_col)[source]

Async version of get_range_data().

get_range_values(start_row, start_col, end_row, end_col)[source]

Read a range of numeric cells into a 2D numpy array of doubles.

This is a high-performance method for reading large amounts of numeric data.

Parameters:
  • start_row (int) – Starting row number (1-indexed)

  • start_col (int) – Starting column number (1-indexed)

  • end_row (int) – Ending row number (1-indexed, inclusive)

  • end_col (int) – Ending column number (1-indexed, inclusive)

Returns:

2D numpy array (float64)

async get_range_values_async(start_row, start_col, end_row, end_col)[source]

Async version of get_range_values().

get_row_values(row)[source]

Get a single row’s values as list[Any].

Parameters:

row (int) – Row number (1-indexed)

Returns:

list[Any] - Cell values for the specified row

async get_row_values_async(row)[source]

Async version of get_row_values().

get_rows_data()[source]

Get all rows data as list[list[Any]].

This is an optimized bulk read method that returns all cell values without creating intermediate Cell objects. Much faster than iterating through ws.rows for large worksheets.

Return type:

List[List[Any]]

Returns:

list[list[Any]] - All cell values, with None for empty cells

async get_rows_data_async()[source]

Async version of get_rows_data().

Return type:

List[List[Any]]

property has_drawing

Check if the worksheet has a drawing (images, charts, etc.).

Check if a cell has a hyperlink.

Return type:

bool

property has_panes

Check if the worksheet has frozen or split panes.

property index
insert_column(col_number, count=1)[source]

Insert one or more columns at the given column number (1-based).

Return type:

bool

insert_row(row_number, count=1)[source]

Insert one or more rows at the given row number (1-based).

Return type:

bool

iter_row_values()[source]

Iterate over rows, yielding each row’s values as list[Any].

This is an optimized iterator that yields row values directly without creating Cell objects. Use this for efficient row-by-row processing of large worksheets.

Yields:

list[Any] - Cell values for each row

property max_column
property max_row
merge_cells(range_string)[source]
Return type:

None

async merge_cells_async(range_string)[source]
Return type:

None

property merges
property name

Alias for title to maintain compatibility and prevent dynamic attribute bugs.

property page_margins

Get the PageMargins object for this worksheet.

property page_setup

Get the PageSetup object for this worksheet.

property print_options

Get the PrintOptions object for this worksheet.

protect(password=None, sheet=True, objects=False, scenarios=False, insert_columns=False, insert_rows=False, insert_hyperlinks=False, delete_columns=False, delete_rows=False, select_locked_cells=True, select_unlocked_cells=True, auto_filter=False, sort=False, pivot_tables=False, format_cells=False, format_columns=False, format_rows=False)[source]

Protect the worksheet.

Return type:

None

async protect_async(password=None, sheet=True, objects=False, scenarios=False, insert_columns=False, insert_rows=False, insert_hyperlinks=False, delete_columns=False, delete_rows=False, select_locked_cells=True, select_unlocked_cells=True, auto_filter=False, sort=False, pivot_tables=False, format_cells=False, format_columns=False, format_rows=False)[source]
Return type:

None

property protection

Get the protection status of the worksheet.

range(*args)[source]
Return type:

Range

read_dataframe(start_row=1, start_col=1, end_row=None, end_col=None, header=True)[source]

Import a range from the worksheet to a pandas DataFrame.

Return type:

Any

Args:

start_row (int): The starting 1-based row index. start_col (int): The starting 1-based column index. end_row (int): The ending 1-based row index. If None, uses max_row. end_col (int): The ending 1-based column index. If None, uses max_column. header (bool): Whether the first row of the range should be used as column names.

Returns:

A pandas DataFrame.

async read_dataframe_async(start_row=1, start_col=1, end_row=None, end_col=None, header=True)[source]
Return type:

Any

remove_conditional_formatting(sqref)[source]

Remove conditional formatting from a range.

Remove a hyperlink from a cell.

Return type:

None

property rows
set_cell_value(row, column, value)[source]

Set a cell’s value directly without creating a Cell object.

This is 10-20x faster than ws.cell(row, col).value = val for bulk operations as it bypasses: - Python Cell wrapper object creation - WeakValueDictionary cache operations - Multiple Python/C++ boundary crossings

Parameters:
  • row (int) – Row number (1-indexed)

  • column (int) – Column number (1-indexed)

  • value – Value to set (str, int, float, bool, or None)

Example:

# Fast bulk write
for r in range(1, 1001):
    for c in range(1, 51):
        ws.set_cell_value(r, c, f"R{r}C{c}")
async set_cell_value_async(row, column, value)[source]

Async version of set_cell_value().

set_cells(cells)[source]

Batch set multiple cell values efficiently.

This is optimal for non-contiguous cell updates where you can’t use write_rows() or write_range().

Parameters:

cells (Iterable[Tuple[int, int, Any]]) – Iterable of (row, col, value) tuples

Return type:

None

Example:

ws.set_cells([
    (1, 1, "Header A"),
    (1, 5, "Header B"),
    (10, 3, 42.5),
    (20, 1, "Footer"),
])
async set_cells_async(cells)[source]

Async version of set_cells().

Return type:

None

set_column_format(column, style_index)[source]
Return type:

None

set_print_area(sqref)[source]

Set the print area for the worksheet.

set_print_title_cols(first_col, last_col)[source]

Set the columns to repeat at left on printed pages.

set_print_title_rows(first_row, last_row)[source]

Set the rows to repeat at top on printed pages.

set_row_format(row, style_index)[source]
Return type:

None

property sheet_state
split_panes(x_split, y_split, top_left_cell='', active_pane='bottomRight')[source]

Split the worksheet panes at given pixel coordinates.

Parameters:
  • x_split (float) – Horizontal split position in 1/20th of a point.

  • y_split (float) – Vertical split position in 1/20th of a point.

  • top_left_cell (str) – Cell address of the top-left cell in the bottom-right pane.

  • active_pane (str) – The pane that is active (‘bottomRight’, ‘topRight’, ‘bottomLeft’, ‘topLeft’).

Return type:

None

stream_reader()[source]

Get a stream reader for this worksheet.

Return type:

XLStreamReader

stream_writer()[source]

Get a stream writer for this worksheet.

Return type:

XLStreamWriter

property table

Get the first Table object for this worksheet. If no table exists, one is created automatically with default name ‘Table1’ and range ‘A1:A1’. Note: OpenXLSX now supports multiple tables per worksheet. Use the ‘tables’ property to access all tables or ‘add_table’ to create new ones.

property tables

Get the collection of tables in this worksheet.

property title
unmerge_cells(range_string)[source]
Return type:

None

async unmerge_cells_async(range_string)[source]
Return type:

None

unprotect()[source]

Unprotect the worksheet.

Return type:

None

async unprotect_async()[source]
Return type:

None

write_dataframe(df, start_row=1, start_col=1, header=True, index=False, column_styles=None)[source]

Export a pandas DataFrame to the worksheet.

Return type:

None

Args:

df: The pandas DataFrame. start_row (int): The starting 1-based row index. start_col (int): The starting 1-based column index. header (bool): Whether to write the DataFrame columns as a header row. index (bool): Whether to write the DataFrame index as the first column(s). column_styles (dict): Optional dictionary mapping column names or 0-based indices to style IDs.

e.g. {“Date”: date_style_id}

async write_dataframe_async(df, start_row=1, start_col=1, header=True, index=False)[source]
Return type:

None

write_range(start_row, start_col, data)[source]

Write a 2D numpy array or any object supporting the buffer protocol to a worksheet range.

This is a high-performance method that avoids Python-level loops and object creation.

Parameters:
  • start_row (int) – Starting row number (1-indexed)

  • start_col (int) – Starting column number (1-indexed)

  • data – 2D numpy array or buffer-compatible object

async write_range_async(start_row, start_col, data)[source]

Async version of write_range().

write_row(row, values, start_col=1)[source]

Write a single row of Python data.

Parameters:
  • row (int) – Row number (1-indexed)

  • values – List/tuple of values for the row

  • start_col (int) – Starting column number (1-indexed), defaults to 1

Example:

ws.write_row(1, [“Name”, “Age”, “City”])

async write_row_async(row, values, start_col=1)[source]

Async version of write_row().

write_rows(start_row, data, start_col=1)[source]

Write a 2D Python list to a worksheet range.

This is optimized for any Python data (strings, mixed types, etc.). For pure numeric data, use write_range() with numpy for best performance.

Parameters:
  • start_row (int) – Starting row number (1-indexed)

  • data – 2D list/tuple of values [[row1_val1, row1_val2, …], [row2_val1, …], …]

  • start_col (int) – Starting column number (1-indexed), defaults to 1

Example:

data = [
    ["Name", "Age", "City"],
    ["Alice", 30, "New York"],
    ["Bob", 25, "Los Angeles"],
]
ws.write_rows(1, data)
async write_rows_async(start_row, data, start_col=1)[source]

Async version of write_rows().

property zoom

Get or set the worksheet zoom scale (percentage, e.g., 100).

class pyopenxlsx.XLAlignment(*args, **kwargs)

Bases: object

horizontal(self) pyopenxlsx._openxlsx.XLAlignmentStyle
indent(self) int
rotation(self) int
set_horizontal(self, arg: pyopenxlsx._openxlsx.XLAlignmentStyle, /) bool
set_indent(self, arg: int, /) bool
set_rotation(self, arg: int, /) bool
set_shrink_to_fit(self, set: bool = True) bool
set_vertical(self, arg: pyopenxlsx._openxlsx.XLAlignmentStyle, /) bool
set_wrap_text(self, set: bool = True) bool
shrink_to_fit(self) bool
vertical(self) pyopenxlsx._openxlsx.XLAlignmentStyle
wrap_text(self) bool
class pyopenxlsx.XLAlignmentStyle(*values)

Bases: Enum

Bottom = 5
Center = 3
CenterContinuous = 8
Distributed = 9
Fill = 6
General = 0
Justify = 7
Left = 1
Right = 2
Top = 4
class pyopenxlsx.XLAppProperties

Bases: object

add_heading_pair(self, arg0: str, arg1: int, /) None
add_sheet_name(self, arg: str, /) None
align_worksheets(self, arg: collections.abc.Sequence[str], /) None
append_sheet_name(self, arg: str, /) None
delete_heading_pair(self, arg: str, /) None
delete_property(self, arg: str, /) None
delete_sheet_name(self, arg: str, /) None
increment_sheet_count(self, arg: int, /) None
insert_sheet_name(self, arg0: str, arg1: int, /) None
prepend_sheet_name(self, arg: str, /) None
property(self, arg: str, /) str
set_heading_pair(self, arg0: str, arg1: int, /) None
set_property(self, arg0: str, arg1: str, /) None
set_sheet_name(self, arg0: str, arg1: str, /) None
class pyopenxlsx.XLBorder(*args, **kwargs)

Bases: object

bottom(self) pyopenxlsx._openxlsx.XLLine
diagonal(self) pyopenxlsx._openxlsx.XLLine
left(self) pyopenxlsx._openxlsx.XLLine
right(self) pyopenxlsx._openxlsx.XLLine
set_bottom(self, lineStyle: pyopenxlsx._openxlsx.XLLineStyle, lineColor: pyopenxlsx._openxlsx.XLColor, lineTint: float = 0.0) bool
set_diagonal(self, lineStyle: pyopenxlsx._openxlsx.XLLineStyle, lineColor: pyopenxlsx._openxlsx.XLColor, lineTint: float = 0.0) bool
set_left(self, lineStyle: pyopenxlsx._openxlsx.XLLineStyle, lineColor: pyopenxlsx._openxlsx.XLColor, lineTint: float = 0.0) bool
set_right(self, lineStyle: pyopenxlsx._openxlsx.XLLineStyle, lineColor: pyopenxlsx._openxlsx.XLColor, lineTint: float = 0.0) bool
set_top(self, lineStyle: pyopenxlsx._openxlsx.XLLineStyle, lineColor: pyopenxlsx._openxlsx.XLColor, lineTint: float = 0.0) bool
top(self) pyopenxlsx._openxlsx.XLLine
class pyopenxlsx.XLBorders

Bases: object

border_by_index(self, arg: int, /) pyopenxlsx._openxlsx.XLBorder
count(self) int
create(self, copyFrom: pyopenxlsx._openxlsx.XLBorder = <pyopenxlsx._openxlsx.XLBorder object at 0x7f78e87d1550>, styleEntriesPrefix: str = '\n\t\t') int
class pyopenxlsx.XLCellFormat(*args, **kwargs)

Bases: object

alignment(self, createIfMissing: bool = False) pyopenxlsx._openxlsx.XLAlignment
apply_alignment(self) bool
apply_border(self) bool
apply_fill(self) bool
apply_font(self) bool
apply_number_format(self) bool
apply_protection(self) bool
border_index(self) int
fill_index(self) int
font_index(self) int
hidden(self) bool
locked(self) bool
number_format_id(self) int
set_apply_alignment(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_apply_border(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_apply_fill(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_apply_font(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_apply_number_format(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_apply_protection(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_border_index(self, arg: int, /) pyopenxlsx._openxlsx.XLCellFormat
set_fill_index(self, arg: int, /) pyopenxlsx._openxlsx.XLCellFormat
set_font_index(self, arg: int, /) pyopenxlsx._openxlsx.XLCellFormat
set_hidden(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_locked(self, set: bool = True) pyopenxlsx._openxlsx.XLCellFormat
set_number_format_id(self, arg: int, /) pyopenxlsx._openxlsx.XLCellFormat
class pyopenxlsx.XLCellFormats

Bases: object

cell_format_by_index(self, arg: int, /) pyopenxlsx._openxlsx.XLCellFormat
count(self) int
create(self, copyFrom: pyopenxlsx._openxlsx.XLCellFormat = <pyopenxlsx._openxlsx.XLCellFormat object at 0x7f78e8962be0>, styleEntriesPrefix: str = '\n\t\t') int
class pyopenxlsx.XLCellRange

Bases: object

address(self) str
clear(self) None
num_columns(self) int
num_rows(self) int
class pyopenxlsx.XLCellReference(*args, **kwargs)

Bases: object

address(self) str
column(self) int
row(self) int
class pyopenxlsx.XLColor(*args, **kwargs)

Bases: object

alpha(self) int
blue(self) int
green(self) int
hex(self) str
red(self) int
set(self, arg0: int, arg1: int, arg2: int, arg3: int, /) None
set(self, arg0: int, arg1: int, arg2: int, /) None
set(self, arg: str, /) None
class pyopenxlsx.XLComment

Bases: object

author_id(self) int
ref(self) str
set_author_id(self, arg: int, /) pyopenxlsx._openxlsx.XLComment
set_text(self, arg: str, /) pyopenxlsx._openxlsx.XLComment
text(self) str
valid(self) bool
class pyopenxlsx.XLComments

Bases: object

add_author(self, arg: str, /) int
author(self, arg: int, /) str
author_count(self) int
count(self) int
delete_comment(self, arg: str, /) bool
get(self, arg: int, /) pyopenxlsx._openxlsx.XLComment
get(self, arg: str, /) str
set(self, cellRef: str, comment: str, author_id: int = 0, widthCols: int = 4, heightRows: int = 6) bool
shape(self, arg: str, /) pyopenxlsx._openxlsx.XLShape
class pyopenxlsx.XLContentItem(*args, **kwargs)

Bases: object

path(self) str
type(self) pyopenxlsx._openxlsx.XLContentType
class pyopenxlsx.XLContentType(*values)

Bases: Enum

CalculationChain = 14
Chart = 10
ChartColorStyle = 12
ChartStyle = 11
Chartsheet = 4
Comments = 19
ControlProperties = 13
CoreProperties = 16
CustomProperties = 18
Drawing = 9
ExtendedProperties = 17
Relationships = 1
SharedStrings = 8
Styles = 7
Table = 20
Theme = 6
Unknown = 23
VBAProject = 15
VMLDrawing = 21
Workbook = 0
WorkbookMacroEnabled = 2
Worksheet = 3
class pyopenxlsx.XLContentTypes

Bases: object

add_override(self, arg0: str, arg1: pyopenxlsx._openxlsx.XLContentType, /) None
content_item(self, arg: str, /) pyopenxlsx._openxlsx.XLContentItem
delete_override(self, arg: str, /) None
delete_override(self, arg: pyopenxlsx._openxlsx.XLContentItem, /) None
get_content_items(self) list[pyopenxlsx._openxlsx.XLContentItem]
class pyopenxlsx.XLDataValidationErrorStyle(*values)

Bases: Enum

Information = 2
Stop = 0
Warning = 1
class pyopenxlsx.XLDataValidationOperator(*values)

Bases: Enum

Between = 0
Equal = 1
GreaterThan = 2
GreaterThanOrEqual = 3
LessThan = 4
LessThanOrEqual = 5
NotBetween = 6
NotEqual = 7
class pyopenxlsx.XLDataValidationType(*values)

Bases: Enum

Custom = 1
Date = 2
Decimal = 3
List = 4
None = 0
TextLength = 5
Time = 6
Whole = 7
class pyopenxlsx.XLDateTime(*args, **kwargs)

Bases: object

as_datetime(self) object
serial(self) float
class pyopenxlsx.XLDefinedName(*args, **kwargs)

Bases: object

comment(self) str
hidden(self) bool
local_sheet_id(self) object
name(self) str
refers_to(self) str
set_comment(self, arg: str, /) None
set_hidden(self, arg: bool, /) None
set_local_sheet_id(self, arg: int, /) None
set_name(self, arg: str, /) None
set_refers_to(self, arg: str, /) None
valid(self) bool
class pyopenxlsx.XLDefinedNames

Bases: object

all(self) list[pyopenxlsx._openxlsx.XLDefinedName]
append(self, name: str, formula: str) pyopenxlsx._openxlsx.XLDefinedName
append(self, name: str, formula: str, local_sheet_id: int) pyopenxlsx._openxlsx.XLDefinedName
count(self) int
exists(self, name: str) bool
exists(self, name: str, local_sheet_id: int) bool
get(self, name: str) pyopenxlsx._openxlsx.XLDefinedName
get(self, name: str, local_sheet_id: int) pyopenxlsx._openxlsx.XLDefinedName
remove(self, name: str) None
remove(self, name: str, local_sheet_id: int) None
class pyopenxlsx.XLDocument(*args, **kwargs)

Bases: object

app_properties(self) pyopenxlsx._openxlsx.XLAppProperties
close(self) None
content_types(self) pyopenxlsx._openxlsx.XLContentTypes
core_properties(self) pyopenxlsx._openxlsx.XLProperties
create(self, name: str, force_overwrite: bool = True) None
custom_property(self, name: str) str

Get a custom document property by name

delete_custom_property(self, name: str) None

Delete a custom document property by name

delete_property(self, arg: pyopenxlsx._openxlsx.XLProperty, /) None
get_archive_entries(self) list[str]

Get a list of all entries (files/directories) in the underlying zip archive.

get_archive_entry(self, path: str) bytes

Get the raw bytes of an entry from the underlying zip archive.

get_embedded_images(self) list[pyopenxlsx._openxlsx.ImageInfo]

Get list of embedded images in the document. Returns list of dicts with ‘name’, ‘path’, ‘extension’ keys.

get_image(self, path: str) bytes

Get image data as bytes from the document archive.

get_image_data(self, image_path: str) bytes

Get image data as bytes. image_path can be full path (e.g., ‘xl/media/image1.png’) or just filename (e.g., ‘image1.png’).

has_archive_entry(self, path: str) bool

Check if the underlying zip archive contains an entry with the given path.

has_macro(self) bool
is_open(self) bool
name(self) str
open(self, path: str) None
open(self, path: str, password: str) None
path(self) str
persons(self) pyopenxlsx._openxlsx.XLPersons
property(self, arg: pyopenxlsx._openxlsx.XLProperty, /) str
save(self) None
save_as(self, arg0: str, arg1: bool, /) None
save_as(self, arg0: str, arg1: bool, arg2: str, /) None
set_custom_property(self, name: str, value: object) None

Set a custom document property

set_property(self, arg0: pyopenxlsx._openxlsx.XLProperty, arg1: str, /) None
styles(self) pyopenxlsx._openxlsx.XLStyles
workbook(self) pyopenxlsx._openxlsx.XLWorkbook
class pyopenxlsx.XLDrawing

Bases: object

add_image(self, r_id: str, name: str, description: str, row: int, col: int, width: int, height: int, options: pyopenxlsx._openxlsx.XLImageOptions = <pyopenxlsx._openxlsx.XLImageOptions object at 0x7f78e8878030>) None
add_scaled_image(self, r_id: str, name: str, description: str, data: str, row: int, col: int, scaling_factor: float = 1.0) None
add_shape(self, row: int, col: int, options: pyopenxlsx._openxlsx.XLVectorShapeOptions = <pyopenxlsx._openxlsx.XLVectorShapeOptions object at 0x7f78e88f03b0>) None
image(self, index: int) pyopenxlsx._openxlsx.XLDrawingItem
image_count(self) int
class pyopenxlsx.XLFill(*args, **kwargs)

Bases: object

background_color(self) pyopenxlsx._openxlsx.XLColor
color(self) pyopenxlsx._openxlsx.XLColor
fill_type(self) pyopenxlsx._openxlsx.XLFillType
pattern_type(self) pyopenxlsx._openxlsx.XLPatternType
set_background_color(self, arg: pyopenxlsx._openxlsx.XLColor, /) pyopenxlsx._openxlsx.XLFill
set_color(self, arg: pyopenxlsx._openxlsx.XLColor, /) pyopenxlsx._openxlsx.XLFill
set_fill_type(self, newFillType: pyopenxlsx._openxlsx.XLFillType, force: bool = False) bool
set_pattern_type(self, arg: pyopenxlsx._openxlsx.XLPatternType, /) pyopenxlsx._openxlsx.XLFill
class pyopenxlsx.XLFillType(*values)

Bases: Enum

Gradient = 0
Pattern = 1
class pyopenxlsx.XLFills

Bases: object

count(self) int
create(self, copyFrom: pyopenxlsx._openxlsx.XLFill = <pyopenxlsx._openxlsx.XLFill object at 0x7f78e87d1670>, styleEntriesPrefix: str = '\n\t\t') int
fill_by_index(self, arg: int, /) pyopenxlsx._openxlsx.XLFill
class pyopenxlsx.XLFont(*args, **kwargs)

Bases: object

bold(self) bool
color(self) pyopenxlsx._openxlsx.XLColor
italic(self) bool
name(self) str
scheme(self) pyopenxlsx._openxlsx.XLFontSchemeStyle
set_bold(self, set: bool = True) pyopenxlsx._openxlsx.XLFont
set_color(self, arg: pyopenxlsx._openxlsx.XLColor, /) pyopenxlsx._openxlsx.XLFont
set_italic(self, set: bool = True) pyopenxlsx._openxlsx.XLFont
set_name(self, arg: str, /) pyopenxlsx._openxlsx.XLFont
set_scheme(self, arg: pyopenxlsx._openxlsx.XLFontSchemeStyle, /) pyopenxlsx._openxlsx.XLFont
set_size(self, arg: int, /) pyopenxlsx._openxlsx.XLFont
set_strikethrough(self, set: bool = True) pyopenxlsx._openxlsx.XLFont
set_underline(self, style: pyopenxlsx._openxlsx.XLUnderlineStyle = XLUnderlineStyle.Single) pyopenxlsx._openxlsx.XLFont
set_vert_align(self, arg: pyopenxlsx._openxlsx.XLVerticalAlignRunStyle, /) pyopenxlsx._openxlsx.XLFont
size(self) int
strikethrough(self) bool
underline(self) pyopenxlsx._openxlsx.XLUnderlineStyle
vert_align(self) pyopenxlsx._openxlsx.XLVerticalAlignRunStyle
class pyopenxlsx.XLFontSchemeStyle(*values)

Bases: Enum

Major = 1
Minor = 2
None = 0
class pyopenxlsx.XLFonts

Bases: object

count(self) int
create(self, copyFrom: pyopenxlsx._openxlsx.XLFont = <pyopenxlsx._openxlsx.XLFont object at 0x7f78e87d0d30>, styleEntriesPrefix: str = '\n\t\t') int
font_by_index(self, arg: int, /) pyopenxlsx._openxlsx.XLFont
class pyopenxlsx.XLIMEMode(*values)

Bases: Enum

Disabled = 3
FullAlpha = 7
FullHangul = 9
FullKatakana = 5
HalfAlpha = 8
HalfHangul = 10
HalfKatakana = 6
Hiragana = 4
NoControl = 0
Off = 1
On = 2
class pyopenxlsx.XLLineStyle(*values)

Bases: Enum

DashDot = 9
DashDotDot = 11
Dashed = 3
Dotted = 4
Double = 6
Hair = 7
Medium = 2
MediumDashDot = 10
MediumDashDotDot = 12
MediumDashed = 8
None = 0
SlantDashDot = 13
Thick = 5
Thin = 1
class pyopenxlsx.XLMergeCells

Bases: object

append_merge(self, arg: str, /) int
count(self) int
delete_merge(self, arg: int, /) None
find_merge(self, arg: str, /) int
merge_exists(self, arg: str, /) bool
class pyopenxlsx.XLNumberFormat(*args, **kwargs)

Bases: object

format_code(self) str
number_format_id(self) int
set_format_code(self, arg: str, /) bool
set_number_format_id(self, arg: int, /) bool
class pyopenxlsx.XLNumberFormats

Bases: object

count(self) int
create(self, copyFrom: pyopenxlsx._openxlsx.XLNumberFormat = <pyopenxlsx._openxlsx.XLNumberFormat object at 0x7f78e87d0cb0>, styleEntriesPrefix: str = '\n\t\t') int
number_format_by_id(self, arg: int, /) pyopenxlsx._openxlsx.XLNumberFormat
number_format_by_index(self, arg: int, /) pyopenxlsx._openxlsx.XLNumberFormat
class pyopenxlsx.XLPageOrientation(*values)

Bases: Enum

Default = 0
Landscape = 2
Portrait = 1
class pyopenxlsx.XLPane(*values)

Bases: Enum

BottomLeft = 2
BottomRight = 0
TopLeft = 3
TopRight = 1
class pyopenxlsx.XLPaneState(*values)

Bases: Enum

Frozen = 1
FrozenSplit = 2
Split = 0
class pyopenxlsx.XLPatternType(*values)

Bases: Enum

DarkDown = 7
DarkGray = 3
DarkGrid = 9
DarkHorizontal = 5
DarkTrellis = 10
DarkUp = 8
DarkVertical = 6
Gray0625 = 18
Gray125 = 17
LightDown = 13
LightGray = 4
LightGrid = 15
LightHorizontal = 11
LightTrellis = 16
LightUp = 14
LightVertical = 12
MediumGray = 2
None = 0
Solid = 1
class pyopenxlsx.XLProperties

Bases: object

delete_property(self, arg: str, /) None
property(self, arg: str, /) str
set_property(self, arg0: str, arg1: str, /) None
set_property(self, arg0: str, arg1: int, /) None
set_property(self, arg0: str, arg1: float, /) None
class pyopenxlsx.XLProperty(*values)

Bases: Enum

AppVersion = 19
Application = 10
Category = 9
Company = 14
CreationDate = 7
Creator = 2
Description = 4
DocSecurity = 11
HyperlinkBase = 17
HyperlinksChanged = 18
Keywords = 3
LastModifiedBy = 5
LastPrinted = 6
LinksUpToDate = 15
Manager = 13
ModificationDate = 8
ScaleCrop = 12
SharedDoc = 16
Subject = 1
Title = 0
class pyopenxlsx.XLRichText(*args, **kwargs)

Bases: object

add_run(self, arg: pyopenxlsx._openxlsx.XLRichTextRun, /) pyopenxlsx._openxlsx.XLRichText
add_run(self, arg: str, /) pyopenxlsx._openxlsx.XLRichTextRun
clear(self) None
empty(self) bool
get_runs(self) list[pyopenxlsx._openxlsx.XLRichTextRun]
property plain_text

(self) -> str

property runs

(self) -> collections.abc.Iterator[pyopenxlsx._openxlsx.XLRichTextRun]

class pyopenxlsx.XLRichTextRun(*args, **kwargs)

Bases: object

property bold

(self) -> object

property font_color

(self) -> object

property font_name

(self) -> object

property font_size

(self) -> object

property italic

(self) -> object

property strikethrough

(self) -> object

property text

(self) -> str

property underline

(self) -> object

class pyopenxlsx.XLShape

Bases: object

allow_in_cell(self) bool
client_data(self) pyopenxlsx._openxlsx.XLShapeClientData
fill_color(self) str
set_allow_in_cell(self, arg: bool, /) bool
set_fill_color(self, arg: str, /) bool
set_stroked(self, arg: bool, /) bool
set_style(self, arg: str, /) bool
set_style_obj(self, arg: pyopenxlsx._openxlsx.XLShapeStyle, /) bool
set_type(self, arg: str, /) bool
shape_id(self) str
stroked(self) bool
style(self) pyopenxlsx._openxlsx.XLShapeStyle
type(self) str
class pyopenxlsx.XLShapeClientData

Bases: object

anchor(self) str
auto_fill(self) bool
column(self) int
move_with_cells(self) bool
object_type(self) str
row(self) int
set_anchor(self, arg: str, /) bool
set_auto_fill(self, arg: bool, /) bool
set_column(self, arg: int, /) bool
set_move_with_cells(self, arg: bool, /) bool
set_object_type(self, arg: str, /) bool
set_row(self, arg: int, /) bool
set_size_with_cells(self, arg: bool, /) bool
set_text_h_align(self, arg: pyopenxlsx._openxlsx.XLShapeTextHAlign, /) bool
set_text_v_align(self, arg: pyopenxlsx._openxlsx.XLShapeTextVAlign, /) bool
size_with_cells(self) bool
text_h_align(self) pyopenxlsx._openxlsx.XLShapeTextHAlign
text_v_align(self) pyopenxlsx._openxlsx.XLShapeTextVAlign
class pyopenxlsx.XLShapeStyle

Bases: object

height(self) int
hidden(self) bool
hide(self) bool
margin_left(self) int
margin_top(self) int
mso_wrap_style(self) str
position(self) str
raw(self) str
set_height(self, arg: int, /) bool
set_margin_left(self, arg: int, /) bool
set_margin_top(self, arg: int, /) bool
set_mso_wrap_style(self, arg: str, /) bool
set_position(self, arg: str, /) bool
set_raw(self, arg: str, /) bool
set_v_text_anchor(self, arg: str, /) bool
set_width(self, arg: int, /) bool
show(self) bool
v_text_anchor(self) str
visible(self) bool
width(self) int
class pyopenxlsx.XLSheetState(*values)

Bases: Enum

Hidden = 1
VeryHidden = 2
Visible = 0
class pyopenxlsx.XLStreamReader

Bases: object

close(self) None
current_row(self) int
property current_row_index

(self) -> int

has_next(self) bool
next_row(self) list
class pyopenxlsx.XLStreamWriter

Bases: object

append_row(self, values: list) None
append_rows(self, rows: collections.abc.Iterable) None
close(self) None
property is_active

(self) -> bool

class pyopenxlsx.XLStyles

Bases: object

borders(self) pyopenxlsx._openxlsx.XLBorders
cell_formats(self) pyopenxlsx._openxlsx.XLCellFormats
fills(self) pyopenxlsx._openxlsx.XLFills
fonts(self) pyopenxlsx._openxlsx.XLFonts
number_formats(self) pyopenxlsx._openxlsx.XLNumberFormats
class pyopenxlsx.XLUnderlineStyle(*values)

Bases: Enum

Double = 2
None = 0
Single = 1
class pyopenxlsx.XLVerticalAlignRunStyle(*values)

Bases: Enum

Baseline = 0
Subscript = 1
Superscript = 2
class pyopenxlsx.XLWorkbook

Bases: object

add_worksheet(self, arg: str, /) None
clear_active_tab(self) None
clone_sheet(self, arg0: str, arg1: str, /) None
defined_names(self) pyopenxlsx._openxlsx.XLDefinedNames
delete_sheet(self, arg: str, /) None
sheet_count(self) int
sheet_exists(self, arg: str, /) bool
worksheet(self, arg: str, /) pyopenxlsx._openxlsx.XLWorksheet
worksheet_names(self) list[str]
pyopenxlsx.is_date_format(c_format)[source]

Returns True if the given format code or id implies a date/time.

Return type:

bool

pyopenxlsx.load_workbook(filename, password=None)[source]
Return type:

Workbook

async pyopenxlsx.load_workbook_async(filename, password=None)[source]
Return type:

Workbook