Bases: lpod.element.odf_element
Class for the table cell element.
Get the currency used for monetary values.
Get the formula of the cell, or None if undefined.
The formula is not interpreted in any way.
Return: unicode
Get the number of times the cell is repeated.
Always None when using the table API.
Return: int or None
Get the style of the cell itself.
Return: unicode
Get the type of the cell: boolean, float, date, string or time.
Return: str
Get the Python value that represent the cell.
Possible return types are unicode, int, Decimal, datetime, timedelta.
Return: Python type
Set the currency used for monetary values.
Arguments:
currency – unicode
Set the formula of the cell, or None to remove it.
The formula is not interpreted in any way.
Arguments:
formula – unicode
Set the numnber of times the cell is repeated, or None to delete it.
Arguments:
repeated – int or None
Set the style of the cell itself.
Arguments:
style – unicode
Set the type ofthe cell manually.
Arguments:
cell_type – ‘boolean’, ‘float’, ‘date’, ‘string’ or ‘time’
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’ or ‘time’
currency – unicode
Bases: lpod.element.odf_element
Get the number of times the column is repeated.
Always None when using the table API.
Return: int or None
Set the numnber of times the column is repeated, or None to delete it.
Arguments:
repeated – int or None
Bases: lpod.element.odf_element
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
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
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 the list of cells matching the criteria. Each result is a tuple of (x, y, cell).
Arguments:
regex – unicode
style – unicode
Return: list of tuples
Shortcut to get the value of the cell at position “x”.
See get_cell and odf_cell.get_cell_value.
Shortcut to get the list of all cell values in this row.
Return: list of Python types
Get the number of times the row is repeated.
Always None when using the table API.
Return: int or None
Get the style of the row itself.
Return: unicode
Get the number of expected cells in the row, i.e. addition repetitions.
Return: int
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
Return wether 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
Remove in-place empty cells at the right of the row. 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.
Arguments:
aggressive – bool
Push the cell back in the row at position “x” starting from 0. Alphabetical positions like “D” are accepted.
Arguments:
x – int or str
Shortcut to set the value of the cell at position “x”.
See get_cell and odf_cell.get_cell_value.
Shortcut to set the list of all cell values in this row.
Arguments:
values – list of Python types
Set the numnber of times the row is repeated, or None to delete it.
Arguments:
repeated – int or None
Set the style of the row itself.
Arguments:
style – unicode
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.
Copies are returned, use set_cell to push them back.
Bases: lpod.element.odf_element
Class to group rows with common properties.
Bases: lpod.element.odf_element
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
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 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
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_cell_value” for erasing value.
Arguments:
coordinates – (int, int) or str
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 the row at the given “y” position.
Position start at 0. So cell A4 is on row 3.
Arguments:
y – int
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
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:
coordinates – (int, int) or str
Return: odf_cell
Get the list of cells matching the criteria. Each result is a tuple of (x, y, cell).
Arguments:
regex – unicode
style – unicode
Return: list of tuples
Shortcut to get 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:
coordinates – (int, int) or str
Return: Python type
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
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.
Arguments:
x – int or str.isalpha()
Return: list of Python types
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.
Arguments:
x – int or str.isalpha()
Return: list of odf_cell
Get the list of columns matching the criteria. Each result is a tuple of (x, column).
The original column elements are returned, with their repetition attribute.
Arguments:
style – unicode
Return: list of tuples
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
Return: odf_row
Get the list of rows matching the criteria. Each result is a tuple of (y, row).
The original row elements are returned, with their repetition attribute.
Arguments:
regex – unicode
style – unicode
Return: list of tuples
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.
Arguments:
y – int
Get the current height of the table.
Return: int
Shortcut to get the current width and height of the table.
Return: (int, int)
Get a matrix of all Python values of the table.
Return: list of lists
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 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:
coordinates – (int, int) or str
cell – odf_cell
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 the row before the given “y” position. It must have the same number of cells. If no row is given, an empty one is created.
Position start at 0. So cell A4 is on row 3.
Arguments:
y – int
row – odf_row
Wether all the cells at the given position are empty.
Position start at 0. So cell C4 is on column 2. Alphabetical position like “C” is accepted. If aggressive is True, the cells without data are said empty.
Return: bool
Wether all the cells of the row at the given “y” position are undefined.
Position start at 0. So cell A4 is on row 3.
Arguments:
y – int
Iterate through lines of Python values of the table.
Return: iterator of lists
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
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:
coordinates – (int, int) or str
cell – odf_cell
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:
coordinates – (int, int) or str
image_frame – odf_frame including an image
type – ‘spreadsheet’ or ‘text’
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:
coordinates – (int, int) or str
value – Python type
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
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
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
Replace the row at the given position with the new one. It must have the same number of cells. Repetion of the old row will be adjusted.
Position start at 0. So cell A4 is on row 3.
Arguments:
y – int
row – odf_row
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
values – list of Python types
Set all Python values for the whole table.
A list of lists is expected, with as many lists as rows, and as many items in each sublist as cells.
Arguments:
values – list of lists
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.
Copies are returned, use set_column to push them back.
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.
Copies are returned, use set_row to push them back.
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
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
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
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
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
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