lpod.table

class lpod.table.odf_cell(native_element)

Bases: lpod.element.odf_element

Class for the table cell element.

clone()
get_currency()

Get the currency used for monetary values.

get_formula()

Get the formula of the cell, or None if undefined.

The formula is not interpreted in any way.

Return: unicode

get_repeated()

Get the number of times the cell is repeated.

Always None when using the table API.

Return: int or None

get_style()

Get the style of the cell itself.

Return: unicode

get_type()

Get the type of the cell: boolean, float, date, string or time.

Return: str

get_value(get_type=False)

Get the Python value that represent the cell.

Possible return types are unicode, int, Decimal, datetime, timedelta. If get_type is True, returns a tuple (value, ODF type of value)

Return: Python type or tuple (python type, string)

is_empty(aggressive=False)
set_currency(currency)

Set the currency used for monetary values.

Arguments:

currency – unicode
set_formula(formula)

Set the formula of the cell, or None to remove it.

The formula is not interpreted in any way.

Arguments:

formula – unicode
set_repeated(repeated)

Set the numnber of times the cell is repeated, or None to delete it.

Arguments:

repeated – int or None
set_style(style)

Set the style of the cell itself.

Arguments:

style – unicode
set_text(text)
set_type(cell_type)

Set the type ofthe cell manually.

Arguments:

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’ or ‘time’
set_value(value, text=None, cell_type=None, currency=None, formula=None)

Set the cell state from the Python value type.

Text is how the cell is displayed. Cell type is guessed, unless provided.

For monetary values, provide the name of the currency.

Arguments:

value – Python type

text – unicode

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’ or ‘percentage’

currency – unicode

class lpod.table.odf_column(native_element, cache=None)

Bases: lpod.element.odf_element

clone()
get_default_cell_style()
get_repeated()

Get the number of times the column is repeated.

Always None when using the table API.

Return: int or None

get_style()

Get the style of the column itself.

Return: unicode

set_default_cell_style(style)
set_repeated(repeated)

Set the numnber of times the column is repeated, or None to delete it and update cache map.

Arguments:

repeated – int or None
set_style(style)

Set the style of the column itself.

Arguments:

style – unicode
class lpod.table.odf_named_range(native_element)

Bases: lpod.element.odf_element

ODF Named Range. Identifies inside the spreadsheet a range of cells of a table by a name and the name of the table.

Name Ranges have the following attributes:

name – name of the named range

table_name – name of the table

start – first cell of the named range, tuple (x, y)

end – last cell of the named range, tuple (x, y)

crange – range of the named range, tuple (x, y, z, t)

usage – None or str, usage of the named range.

get_value(get_type=False)

Shortcut to retrieve the value of the first cell of the named range. See table.get_value() for the arguments description and return format.

get_values(cell_type=None, complete=True, get_type=False, flat=False)

Shortcut to retrieve the values of the cells of the named range. See table.get_values() for the arguments description and return format.

set_name(name)

Set the name of the Named Range. The name is mandatory, if a Named Range of the same name exists, it will be replaced. Name must contains only alphanumerics characters and ‘_’, and can not be of a cell coordinates form like ‘AB12’.

Arguments:

name – str
set_range(crange)

Set the range of the named range. Range can be either one cell (like ‘A1’) or an area (‘A1:B2’). It can be provided as an alpha numeric value like “A1:B2’ or a tuple like (0, 0, 1, 1) or (0, 0).

Arguments:

crange – str or tuple of int, cell or area coordinate
set_table_name(name)

Set the name of the table of the Named Range. The name is mandatory.

Arguments:

name – str
set_usage(usage=None)

Set the usage of the Named Range. Usage can be None (default) or one of :

‘print-range’ ‘filter’ ‘repeat-column’ ‘repeat-row’

Arguments:

usage – None or str
set_value(value, cell_type=None, currency=None, style=None)

Shortcut to set the value of the first cell of the named range. See table.set_value() for the arguments description.

set_values(values, style=None, cell_type=None, currency=None)

Shortcut to set the values of the cells of the named range. See table.set_values() for the arguments description.

class lpod.table.odf_row(native_element, cache=None)

Bases: lpod.element.odf_element

append(cell=None, clone=True, _repeated=None)

Append the given cell at the end of the row. Repeated cells are accepted. If no cell is given, an empty one is created.

Do not use when working on a table, use odf_table.append_cell.

Arguments:

cell – odf_cell

_repeated – (optional), repeated value of the row

returns the cell with x and y updated

append_cell(cell=None, clone=True, _repeated=None)

Append the given cell at the end of the row. Repeated cells are accepted. If no cell is given, an empty one is created.

Do not use when working on a table, use odf_table.append_cell.

Arguments:

cell – odf_cell

_repeated – (optional), repeated value of the row

returns the cell with x and y updated

clone()
delete_cell(x)

Delete the cell at the given position “x” starting from 0. Alphabetical positions like “D” are accepted.

Cells on the right will be shifted to the left. In a table, other rows remain unaffected.

Arguments:

x – int or str
extend_cells(cells=[])
get_cell(x, clone=True)

Get the cell at position “x” starting from 0. Alphabetical positions like “D” are accepted.

A copy is returned, use set_cell to push it back.

Arguments:

x – int or str

Return: odf_cell

get_cells(coord=None, style=None, content=None, cell_type=None)

Get the list of cells matching the criteria.

Filter by cell_type, with cell_type ‘all’ will retrieve cells of any type, aka non empty cells.

Filter by coordinates will retrieve the amount of cells defined by ‘coord’, minus the other filters.

Arguments:

coord – str or tuple of int : coordinates

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

content – regex, unicode

style – unicode

Return: list of tuples

get_repeated()

Get the number of times the row is repeated.

Always None when using the table API.

Return: int or None

get_style()

Get the style of the row itself.

Return: unicode

get_value(x, get_type=False)

Shortcut to get the value of the cell at position “x”. If get_type is True, returns the tuples (value, ODF type).

If the cell is empty, returns None or (None, None)

See get_cell and odf_cell.get_value.

get_values(coord=None, cell_type=None, complete=False, get_type=False)

Shortcut to get the cell values in this row.

Filter by cell_type, with cell_type ‘all’ will retrieve cells of any type, aka non empty cells. If cell_type is used and complete is True, missing values are replaced by None. If cell_type is None, complete is always True : with no cell type queried, get_values() returns None for each empty cell, the length of the list is equal to the length of the row (depending on coordinates use).

If get_type is True, returns a tuple (value, ODF type of value), or (None, None) for empty cells if complete is True.

Filter by coordinates will retrieve the amount of cells defined by coordinates with None for empty cells, except when using cell_type.

Arguments:

coord – str or tuple of int : coordinates in row

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

complete – boolean

get_type – boolean

Return: list of Python types, or list of tuples.

get_width()

Get the number of expected cells in the row, i.e. addition repetitions.

Return: int

insert_cell(x, cell=None, clone=True)

Insert the given cell at position “x” starting from 0. If no cell is given, an empty one is created.

Alphabetical positions like “D” are accepted.

Do not use when working on a table, use odf_table.insert_cell.

Arguments:

x – int or str

cell – odf_cell

returns the cell with x and y updated

is_empty(aggressive=False)

Return whether every cell in the row has no value or the value evaluates to False (empty string), and no style.

If aggressive is True, empty cells with style are considered empty.

Arguments:

aggressive – bool

Return: bool

rstrip(aggressive=False)

Remove in-place empty cells at the right of the row. An empty cell has no value but can have style. If “aggressive” is True, style is ignored.

Arguments:

aggressive – bool
set_cell(x, cell=None, clone=True, _get_repeat=False)

Push the cell back in the row at position “x” starting from 0. Alphabetical positions like “D” are accepted.

Arguments:

x – int or str

returns the cell with x and y updated

set_cells(cells=[], start=0, clone=True)

Set the cells in the row, from the ‘start’ column. This method does not clear the row, use row.clear() before to start with an empty row.

Arguments:

cells – list of cells

start – int or str

set_repeated(repeated)

Set the numnber of times the row is repeated, or None to delete it and update cache map.

Arguments:

repeated – int or None
set_style(style)

Set the style of the row itself.

Arguments:

style – unicode
set_value(x, value, style=None, cell_type=None, currency=None)

Shortcut to set the value of the cell at position “x”.

Arguments:

x – int or str

value – Python type

cell_type – ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’,
‘string’ or ‘time’

currency – three-letter str

style – unicode

See get_cell and odf_cell.get_value.

set_values(values, start=0, style=None, cell_type=None, currency=None)

Shortcut to set the value of cells in the row, from the ‘start’ column vith values. This method does not clear the row, use row.clear() before to start with an empty row.

Arguments:

values – list of Python types

start – int or str

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’ or ‘percentage’

currency – three-letter str

style – cell style

traverse(start=None, end=None)

Yield as many cell elements as expected cells in the row, i.e. expand repetitions by returning the same cell as many times as necessary.

Arguments:

start – int

end – int

Copies are returned, use set_cell to push them back.

class lpod.table.odf_row_group(native_element, cache=None)

Bases: lpod.element.odf_element

Class to group rows with common properties.

class lpod.table.odf_table(native_element, cache=None)

Bases: lpod.element.odf_element

append(something)

Dispatch .append() call to append_row() or append_column().

append_cell(y, cell=None, clone=True)

Append the given cell at the “y” coordinate. Repeated cells are accepted. If no cell is given, an empty one is created.

Position start at 0. So cell A4 is on row 3.

Other rows remain untouched.

Arguments:

y – int

cell – odf_cell

returns the cell with x and y updated

append_column(column=None, _repeated=None)

Append the column at the end of the table. If no column is given, an empty one is created.

ODF columns don’t contain cells, only style information.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

Arguments:

column – odf_column
append_row(row=None, clone=True, _repeated=None)

Append the row at the end of the table. If no row is given, an empty one is created.

Position start at 0. So cell A4 is on row 3.

Note the columns are automatically created when the first row is inserted in an empty table. So better insert a filled row.

Arguments:

row – odf_row

_repeated – (optional), repeated value of the row

returns the row, with updated row.y

del_span(area)

Delete a Cell Span. ‘area’ is the cell coordiante of the upper left cell of the spanned area.

Area can be either one cell (like ‘A1’) or an area (‘A1:B2’). It can be provided as an alpha numeric value like “A1:B2’ or a tuple like (0, 0, 1, 1) or (0, 0). If an area is provided, the upper left cell is used.

Arguments:

area – str or tuple of int, cell or area coordinate
delete_cell(coord)

Delete the cell at the given coordinates, so that next cells are shifted to the left.

Coordinates are either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”.

Use “set_value” for erasing value.

Arguments:

coord – (int, int) or str
delete_column(x)

Delete the column at the given position. ODF columns don’t contain cells, only style information.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

Arguments:

x – int or str.isalpha()
delete_named_range(name)

Delete the Named Range of specified name from the spreadsheet. Beware : named ranges are stored at the body level, thus do not call this method on a cloned table.

Arguments:

name – str
delete_row(y)

Delete the row at the given “y” position.

Position start at 0. So cell A4 is on row 3.

Arguments:

y – int or str
extend_rows(rows=[])

Append a list of rows at the end of the table.

Arguments:

rows – list of odf_row
get_cell(coord, clone=True, keep_repeated=True)

Get the cell at the given coordinates.

They are either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”.

A copy is returned, use set_cell to push it back.

Arguments:

coord – (int, int) or str

Return: odf_cell

get_cells(coord=None, cell_type=None, style=None, content=None, flat=False)

Get the cells matching the criteria. If ‘coord’ is None, parse the whole table, else parse the area defined by ‘coord’.

Filter by cell_type = “all” will retrieve cells of any type, aka non empty cells.

If flat is True (default is False), the method return a single list of all the values, else a list of lists of cells.

if cell_type, style and content are None, get_cells() will return the exact number of cells of the area, including empty cells.

Arguments:

coordinates – str or tuple of int : coordinates of area

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

content – regex, unicode

style – unicode

flat – boolean

Return: list of tuples

get_column(x)

Get the column at the given “x” position.

ODF columns don’t contain cells, only style information.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

A copy is returned, use set_column to push it back.

Arguments:

x – int or str.isalpha()

Return: odf_column

get_column_cells(x, style=None, content=None, cell_type=None, complete=False)

Get the list of cells at the given position.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

Filter by cell_type, with cell_type ‘all’ will retrieve cells of any type, aka non empty cells.

If complete is True, replace missing values by None.

Arguments:

x – int or str.isalpha()

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

content – regex, unicode

style – unicode

complete – boolean

Return: list of odf_cell

get_column_values(x, cell_type=None, complete=True, get_type=False)

Shortcut to get the list of Python values for the cells at the given position.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

Filter by cell_type, with cell_type ‘all’ will retrieve cells of any type, aka non empty cells. If cell_type and complete is True, replace missing values by None.

If get_type is True, returns a tuple (value, ODF type of value)

Arguments:

x – int or str.isalpha()

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

complete – boolean

get_type – boolean

Return: list of Python types

get_columns(coord=None, style=None)

Get the list of columns matching the criteria. Each result is a tuple of (x, column).

Arguments:

coord – str or tuple of int : coordinates of columns

style – unicode

Return: list of columns

get_columns_width()
get_displayed()
get_formatted_text(context)
get_height()

Get the current height of the table.

Return: int

get_name()

Return the name of the table.

get_named_range(name)

Returns the Name Ranges of the specified name. If table_name is provided, limits the search to these tables. Beware : named ranges are stored at the body level, thus do not call this method on a cloned table.

Arguments:

name – str, name of the named range object

Return : odf_named_range

get_named_ranges(table_name=None)

Returns the list of available Name Ranges of the spreadsheet. If table_name is provided, limits the search to these tables. Beware : named ranges are stored at the body level, thus do not call this method on a cloned table.

Arguments:

table_names – str or list of str, names of tables

Return : list of odf_table_range

get_print_ranges()
get_printable()
get_protected()
get_row(y, clone=True, create=True)

Get the row at the given “y” position.

Position start at 0. So cell A4 is on row 3.

A copy is returned, use set_cell to push it back.

Arguments:

y – int or str

Return: odf_row

get_row_values(y, cell_type=None, complete=True, get_type=False)

Shortcut to get the list of Python values for the cells of the row at the given “y” position.

Position start at 0. So cell A4 is on row 3.

Filter by cell_type, with cell_type ‘all’ will retrieve cells of any type, aka non empty cells. If cell_type and complete is True, replace missing values by None.

If get_type is True, returns a tuple (value, ODF type of value)

Arguments:

y – int, str

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

complete – boolean

get_type – boolean

Return: list of lists of Python types

get_rows(coord=None, style=None, content=None)

Get the list of rows matching the criteria.

Filter by coordinates will parse the area defined by the coordinates.

Arguments:

coord – str or tuple of int : coordinates of rows

content – regex, unicode

style – unicode

Return: list of rows

get_size()

Shortcut to get the current width and height of the table.

Return: (int, int)

get_style()
get_value(coord, get_type=False)

Shortcut to get the Python value of the cell at the given coordinates.

If get_type is True, returns the tuples (value, ODF type)

coord is either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”. If an Area is given, the upper left position is used as coord.

Arguments:

coord – (int, int) or str : coordinate

Return: Python type

get_values(coord=None, cell_type=None, complete=True, get_type=False, flat=False)

Get a matrix of values of the table.

Filter by coordinates will parse the area defined by the coordinates.

If ‘cell_type’ is used and ‘complete’ is True (default), missing values are replaced by None. Filter by ‘ cell_type = “all” ‘ will retrieve cells of any type, aka non empty cells.

If ‘cell_type’ is None, complete is always True : with no cell type queried, get_values() returns None for each empty cell, the length each lists is equal to the width of the table.

If get_type is True, returns tuples (value, ODF type of value), or (None, None) for empty cells with complete True.

If flat is True, the methods return a single list of all the values. By default, flat is False.

Arguments:

coord – str or tuple of int : coordinates of area

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

complete – boolean

get_type – boolean

Return: list of lists of Python types

get_width()

Get the current width of the table, measured on columns.

Rows may have different widths, use the odf_table API to ensure width consistency.

Return: int

insert_cell(coord, cell=None, clone=True)

Insert the given cell at the given coordinates. If no cell is given, an empty one is created.

Coordinates are either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”.

Cells on the right are shifted. Other rows remain untouched.

Arguments:

coord – (int, int) or str

cell – odf_cell

returns the cell with x and y updated

insert_column(x, column=None)

Insert the column before the given “x” position. If no column is given, an empty one is created.

ODF columns don’t contain cells, only style information.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

Arguments:

x – int or str.isalpha()

column – odf_column

insert_row(y, row=None, clone=True)

Insert the row before the given “y” position. If no row is given, an empty one is created.

Position start at 0. So cell A4 is on row 3.

If row is None, a new empty row is created.

Arguments:

y – int or str

row – odf_row

returns the row, with updated row.y

is_column_empty(x, aggressive=False)

Return wether every cell in the column at “x” position has no value or the value evaluates to False (empty string), and no style.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

If aggressive is True, empty cells with style are considered empty.

Return: bool

is_empty(aggressive=False)

Return whether every cell in the table has no value or the value evaluates to False (empty string), and no style.

If aggressive is True, empty cells with style are considered empty.

Arguments:

aggressive – bool
is_row_empty(y, aggressive=False)

Return wether every cell in the row at the given “y” position has no value or the value evaluates to False (empty string), and no style.

Position start at 0. So cell A4 is on row 3.

If aggressive is True, empty cells with style are considered empty.

Arguments:

y – int or str

aggressive – bool

iter_values(coord=None, cell_type=None, complete=True, get_type=False)

Iterate through lines of Python values of the table.

Filter by coordinates will parse the area defined by the coordinates.

cell_type, complete, grt_type : see get_values()

Arguments:

coord – str or tuple of int : coordinates of area

cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’,
‘currency’, ‘percentage’ or ‘all’

complete – boolean

get_type – boolean

Return: iterator of lists

rstrip(aggressive=False)

Remove in-place empty rows below and empty cells at the right of the table. Cells are empty if they contain no value or it evaluates to False, and no style.

If aggressive is True, empty cells with style are removed too.

Argument:

aggressive – bool
set_cell(coord, cell=None, clone=True)

Replace a cell of the table at the given coordinates.

They are either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”.

Arguments:

coord – (int, int) or str : coordinate

cell – odf_cell

return the cell, with x and y updated

set_cell_image(coord, image_frame, type=None)

Do all the magic to display an image in the cell at the given coordinates.

They are either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”.

The frame element must contain the expected image position and dimensions.

Image insertion depends on the document type, so the type must be provided or the table element must be already attached to a document.

Arguments:

coord – (int, int) or str

image_frame – odf_frame including an image

type – ‘spreadsheet’ or ‘text’

set_cells(cells, coord=None, clone=True)

set the cells in the table, from the ‘coord’ position.

‘coord’ is the coordinate of the upper left cell to be modified by values. If ‘coord’ is None, default to the position (0,0) (“A1”). If ‘coord’ is an area (e.g. “A2:B5”), the upper left position of this area is used as coordinate.

The table is not cleared before the operation, to reset the table before setting cells, use table.clear().

A list of lists is expected, with as many lists as rows to be set, and as many cell in each sublist as cells to be setted in the row.

Arguments:

cells – cell object

coord – tuple or str

values – list of lists of python types

set_column(x, column=None)

Replace the column at the given “x” position.

ODF columns don’t contain cells, only style information.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

Arguments:

x – int or str.isalpha()

column – odf_column

set_column_cells(x, cells)

Shortcut to set the list of cells at the given position.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

The list must have the same length than the table height.

Arguments:

x – int or str.isalpha()

cells – list of odf_cell

set_column_values(x, values, cell_type=None, currency=None, style=None)

Shortcut to set the list of Python values of cells at the given position.

Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted.

The list must have the same length than the table height.

Arguments:

x – int or str.isalpha()

values – list of Python types

cell_type – ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’,
‘string’ or ‘time’

currency – three-letter str

style – unicode

set_displayed(display)
set_name(name)

Set the name of the table. Name can’t be empty and can’t have the character “’” or ‘/’.

set_named_range(name, crange, table_name=None, usage=None)

Create a Named Range element and insert it in the document. Beware : named ranges are stored at the body level, thus do not call this method on a cloned table.

Arguments:

name – str, name of the named range

crange – str or tuple of int, cell or area coordinate

table_name – str, name of the table

uage – None or ‘print-range’, ‘filter’, ‘repeat-column’, ‘repeat-row’

set_print_ranges(print_ranges)
set_printable(printable)
set_protected(protect)
set_row(y, row=None, clone=True)

Replace the row at the given position with the new one. Repetions of the old row will be adjusted.

If row is None, a new empty row is created.

Position start at 0. So cell A4 is on row 3.

Arguments:

y – int

row – odf_row

returns the row, with updated row.y

set_row_cells(y, cells=[])

Shortcut to set all the cells of the row at the given “y” position.

Position start at 0. So cell A4 is on row 3.

Arguments:

y – int or str

cells – list of Python types

style – unicode

returns the row, with updated row.y

set_row_values(y, values, cell_type=None, currency=None, style=None)

Shortcut to set the values of all cells of the row at the given “y” position.

Position start at 0. So cell A4 is on row 3.

Arguments:

y – int or str

values – list of Python types

cell_type – ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’,
‘string’ or ‘time’

currency – three-letter str

style – unicode

returns the row, with updated row.y

set_span(area, merge=False)

Create a Cell Span : span the first cell of the area on several columns and/or rows. If merge is True, replace text of the cell by the concatenation of existing text in covered cells. Beware : if merge is True, old text is changed, if merge is False (the default), old text in coverd cells is still present but not displayed by most GUI.

If the area defines only one cell, the set span will do nothing. It is not allowed to apply set span to an area whose one cell already belongs to previous cell span.

Area can be either one cell (like ‘A1’) or an area (‘A1:B2’). It can be provided as an alpha numeric value like “A1:B2’ or a tuple like (0, 0, 1, 1) or (0, 0).

Arguments:

area – str or tuple of int, cell or area coordinate

merge – boolean

set_style(style)
set_value(coord, value, cell_type=None, currency=None, style=None)

Set the Python value of the cell at the given coordinates.

They are either a 2-uplet of (x, y) starting from 0, or a human-readable position like “C4”.

Arguments:

coord – (int, int) or str

value – Python type

cell_type – ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’,
‘string’ or ‘time’

currency – three-letter str

style – unicode

set_values(values, coord=None, style=None, cell_type=None, currency=None)

set the value of cells in the table, from the ‘coord’ position with values.

‘coord’ is the coordinate of the upper left cell to be modified by values. If ‘coord’ is None, default to the position (0,0) (“A1”). If ‘coord’ is an area (e.g. “A2:B5”), the upper left position of this area is used as coordinate.

The table is not cleared before the operation, to reset the table before setting values, use table.clear().

A list of lists is expected, with as many lists as rows, and as many items in each sublist as cells to be setted. None values in the list will create empty cells with no cell type (but eventually a style).

Arguments:

coord – tuple or str

values – list of lists of python types

cell_type – ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’,
‘string’ or ‘time’

currency – three-letter str

style – unicode

to_csv(path_or_file=None, delimiter=', ', quotechar='"', lineterminator='n', encoding='utf-8')

Write the table as CSV in the file. If the file is a string, it is opened as a local path. Else a open file-like is expected; it will not be closed afterwards.

Arguments:

path_or_file – str or file-like

delimiter – str

quotechar – str

lineterminator – str

encoding – str

transpose(coord=None)

Swap in-place rows and columns of the table.

If ‘coord’ is not None, apply transpose only to the area defined by the coordinates. Beware, if area is not square, some cells mays be over written during the process.

Arguments:

coord – str or tuple of int : coordinates of area

start – int or str

traverse(start=None, end=None)

Yield as many row elements as expected rows in the table, i.e. expand repetitions by returning the same row as many times as necessary.

Arguments:

start – int

end – int

Copies are returned, use set_row to push them back.

traverse_columns(start=None, end=None)

Yield as many column elements as expected columns in the table, i.e. expand repetitions by returning the same column as many times as necessary.

Arguments:

start – int

end – int

Copies are returned, use set_column to push them back.

lpod.table.import_from_csv(path_or_file, name, style=None, delimiter=None, quotechar=None, lineterminator=None, encoding='utf-8')

Convert the CSV file to an odf_table. If the file is a string, it is opened as a local path. Else a open file-like is expected; it will not be closed afterwards.

CSV format can be autodetected to a certain limit, but encoding is important.

Arguments:

path_or_file – str or file-like

name – unicode

style – str

delimiter – str

quotechar – str

lineterminator – str

encoding – str

lpod.table.odf_create_cell(value=None, text=None, cell_type=None, currency=None, formula=None, repeated=None, style=None)

Create a cell element containing the given value. The textual representation is automatically formatted but can be provided. Cell type can be deduced as well, unless the number is a percentage or currency. If cell type is “currency”, the currency must be given. The cell can be repeated on the given number of columns.

Arguments:

value – bool, int, float, Decimal, date, datetime, str, unicode,
timedelta

text – unicode

cell_type – ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’,
‘string’ or ‘time’

currency – three-letter str

repeated – int

style – unicode

Return: odf_cell

lpod.table.odf_create_column(default_cell_style=None, repeated=None, style=None)

Create a column group element of the optionally given style. Cell style can be set for the whole column. If the properties apply to several columns, give the number of repeated columns.

Columns don’t contain cells, just style information.

You don’t generally have to create columns by hand, use the odf_table API.

Arguments:

default_cell_style – unicode

repeated – int

style – unicode

Return: odf_column

lpod.table.odf_create_header_rows()
lpod.table.odf_create_named_range(name, crange, table_name, usage=None)

Create a Named Range element. ‘name’ must contains only letters, digits and ‘_’, and must not be like a coordinate as ‘A1’. ‘table_name’ must be a correct table name (no “’” or “/” in it).

Arguments:

name – str, name of the named range

crange – str or tuple of int, cell or area coordinate

table_name – str, name of the table

uage – None or ‘print-range’, ‘filter’, ‘repeat-column’, ‘repeat-row’

lpod.table.odf_create_row(width=None, repeated=None, style=None, cache=None)

Create a row element, optionally filled with “width” number of cells.

Rows contain cells, their number determine the number of columns.

You don’t generally have to create rows by hand, use the odf_table API.

Arguments:

width – int

repeated – int

style – unicode

Return: odf_row

lpod.table.odf_create_row_group(height=None, width=None)

Create a group of rows, optionnaly filled with “height” number of rows, of “width” cells each.

Row group bear style information applied to a series of rows.

Arguments:

height – int

Return odf_row_group

lpod.table.odf_create_table(name, width=None, height=None, protected=False, protection_key=None, display=True, printable=True, print_ranges=None, style=None)

Create a table element, optionally prefilled with “height” rows of “width” cells each.

If the table is to be protected, a protection key must be provided, i.e. a hash value of the password (XXX what algorithm?).

If the table must not be displayed, set “display” to False.

If the table must not be printed, set “printable” to False. The table will not be printed when it is not displayed, whatever the value of this argument.

Ranges of cells to print can be provided as a list of cell ranges, e.g. [‘E6:K12’, ‘P6:R12’] or directly as a raw string, e.g. “E6:K12 P6:R12”.

You can access and modify the XML tree manually, but you probably want to use the API to access and alter cells. It will save you from handling repetitions and the same number of cells for each row.

If you use both the table API and the XML API, you are on your own for ensuiring model integrity.

Arguments:

name – unicode

width – int

height – int

protected – bool

protection_key – str

display – bool

printable – bool

print_ranges – list

style – unicode

Return: odf_table

Previous topic

lpod.styles

Next topic

lpod.toc

This Page