revitron.excel

This submodule contains helper classes to access and modify Microsoft Excel files. The following example demonstrates how to write data to table cells in a sheet created from a template:

book = revitron.ExcelWorkbook(xlsx)
sheet = book.newWorksheetFromTemplate('Template', 'Name')
sheet.setCell(5, 1, 'Value')

Classes:

ExcelWorkbook(file)

A wrapper class for Excel workbooks.

ExcelWorksheet(worksheet)

A wrapper class for modifying Excel worksheet cells.

class ExcelWorkbook(file)[source]

Bases: object

A wrapper class for Excel workbooks.

Methods:

__init__(file)

Inits a new ExcelWorkbook instance.

close([save])

Closes and optionally saves a workbook file.

getWorksheet(name)

Returns a Excel worksheet for a given name

newWorksheetFromTemplate(template, name)

Creates a new worksheet as a copy from a given template.

__init__(file)[source]

Inits a new ExcelWorkbook instance.

Parameters

file (string) – The path to the xls file

close(save=True)[source]

Closes and optionally saves a workbook file.

Parameters

save (bool, optional) – If True, the file is saved before closing. Defaults to True.

getWorksheet(name)[source]

Returns a Excel worksheet for a given name

Parameters

name (string) – The worksheet name

Returns

An Excel worksheet object instance

Return type

object

newWorksheetFromTemplate(template, name)[source]

Creates a new worksheet as a copy from a given template.

Parameters
  • template (string) – The template name

  • name (string) – The name of the new copy

Returns

An ExcelWorksheet instance

Return type

object

class ExcelWorksheet(worksheet)[source]

Bases: object

A wrapper class for modifying Excel worksheet cells.

Methods:

__init__(worksheet)

Inits a new ExcelWorksheet instance.

setCell(row, column, value)

Writes data to a cell of the current worksheet.

__init__(worksheet)[source]

Inits a new ExcelWorksheet instance.

Parameters

file (object) – An Excel worksheet object

setCell(row, column, value)[source]

Writes data to a cell of the current worksheet.

Parameters
  • row (integer) – The row

  • column (integer) – The column

  • value (mixed) – The value

Returns

The ExcelWorkbook instance

Return type

object