Class RangeConverter
- class ooodev.utils.data_type.rng.range_converter.RangeConverter(lo_inst=None)[source]
Bases:
LoInstPropsPartial
- Parameters:
lo_inst (LoInst | None) –
- __init__(lo_inst=None)[source]
Constructor.
- Parameters:
lo_inst (LoInst, optional) – Lo instance.
- Return type:
None
- column_number_str(col)[source]
Creates a column Name from zero base column number.
Columns are numbered starting at 0 where 0 corresponds to
A
They run asA-Z
,AA-AZ
,BA-BZ
, …,IV
- Parameters:
col (int) – Zero based column index
- Returns:
Column Name
- Return type:
str
- get_cell(col: int, row: int)[source]
- get_cell(addr: com.sun.star.table.CellAddress)
- get_cell(cell: com.sun.star.table.XCell)
- get_cell(cell_obj: ooodev.utils.data_type.cell_obj.CellObj)
- get_cell(*args, **kwargs)
Gets the cell as string from a cell.
- Parameters:
col (int) – Column. Zero Based column index.
row (int) – Row. Zero Based row index.
addr (CellAddress) – Cell Address.
cell (XCell) – Cell.
cell_obj (CellObj) – Cell Object.
- Returns:
Cell as string in the format of
A1
.- Return type:
str
- get_cell_address_from_cell(cell)[source]
Gets a cell address from a cell.
- Parameters:
cell (XCell) – Cell.
- Returns:
Cell address.
- Return type:
CellAddress
- get_cell_address_from_cell_range(cell_range)[source]
Gets the cell address from a cell range.
- Parameters:
cell_range (XCellRange) – Cell Range.
- Returns:
Cell address.
- Return type:
CellRangeAddress
- get_cell_address_sheet(sheet, cell_name)[source]
Gets a cell address from a sheet using the cell name.
- Parameters:
sheet (XSpreadsheet) – Sheet.
cell_name (str) – Cell name.
- Returns:
Cell address.
- Return type:
CellAddress
- get_cell_by_position(sheet, col, row)[source]
Gets a cell from a sheet using the column and row.
- Parameters:
sheet (XSpreadsheet) – Sheet.
col (int) – Column. Zero Based column index.
row (int) – Row. Zero Based row index.
- Returns:
Cell.
- Return type:
XCell
- get_cell_from_cell_range(cell_range, col, row)[source]
Gets a cell from a cell range.
- Parameters:
cell_range (XCellRange) – Cell Range.
col (int) – Column. Zero Based column index.
row (int) – Row. Zero Based row index.
- Returns:
Cell.
- Return type:
XCell
- get_cell_from_sheet_addr(sheet, addr)[source]
Gets a cell from a sheet using the cell address.
- Parameters:
sheet (XSpreadsheet) – Sheet.
addr (CellAddress) – Cell Address.
- Returns:
Cell.
- Return type:
XCell
- get_cell_obj(values: Tuple[int, int] | Tuple[int, int, int])[source]
- get_cell_obj(col: int, row: int, sheet_idx: int = ...)
- get_cell_obj(addr: com.sun.star.table.CellAddress)
- get_cell_obj(cell: com.sun.star.table.XCell)
- get_cell_obj(val: ooodev.utils.data_type.cell_values.CellValues)
- get_cell_obj(name: str)
- get_cell_obj(name: str, sheet_idx: int)
- get_cell_obj(cell_obj: ooodev.utils.data_type.cell_obj.CellObj)
- get_cell_obj(*args, **kwargs)
Gets the cell as string from a cell.
- Parameters:
col (int) – Column. Zero Based column index.
row (int) – Row. Zero Based row index.
sheet_idx (int, optional) – Sheet index that this cell value belongs to. Default is
-2
.addr (CellAddress) – Cell Address.
cell (XCell) – Cell.
val (CellValues) – Cell values.
name (str) – Cell name such as as
A23
orSheet1.A23
cell_obj (CellObj) – Cell Object.
values (Tuple[int, int], Tuple[int, int, int]) – Cell values.
- Returns:
Cell Object.
- Return type:
- get_cell_obj_from_addr(addr)[source]
Gets the cell as CellObj from a cell address.
- Parameters:
addr (CellAddress) – Cell Address.
- Returns:
Cell Object.
- Return type:
- get_cell_obj_from_cell(cell)[source]
Gets the cell as CellObj from a cell.
- Parameters:
cell (XCell) – Cell.
- Returns:
Cell Object.
- Return type:
- get_cell_obj_from_cell_obj(val)[source]
Gets the cell as CellObj from CellValues.
- Parameters:
val (CellValues) – Cell values.
- Returns:
Cell Object.
- Return type:
Hint
CellValues
can be imported fromooodev.utils.data_type.cell_values
- get_cell_obj_from_col_row(col, row, sheet_idx=-2)[source]
Gets the cell as CellObj from column and row.
- Parameters:
col (int) – Column. Zero Based column index.
row (int) – Row. Zero Based row index.
sheet_idx (int, optional) – Sheet index that this cell value belongs to. A value of
-1
means the sheet index is not set and an attempt will be made to discover the sheet index from current document if it is a Calc document. A value of-2
means no attempt is made to discover the sheet index. Default is-2
.
- Returns:
Cell Object.
- Return type:
- get_cell_obj_from_str(name)[source]
Gets the cell as CellObj from a cell name.
- Parameters:
name (str) – Cell name such as as
A23
orSheet1.A23
- Returns:
Cell Object.
- Return type:
- get_cell_obj_from_str_idx(name, sheet_idx)[source]
Gets the cell as CellObj from a cell name.
- Parameters:
name (str) – Cell name such as as
A23
orSheet1.A23
sheet_idx (int) – Sheet index (zero based).
- Returns:
Cell Object.
- Return type:
- get_cell_obj_tuple(values)[source]
Gets the cell as CellObj from CellValues.
- Parameters:
val (Tuple[int, int], Tuple[int, int, int]) – Cell values. Tuple of (col, row) or (col, row, sheet_idx). All values are Zero Based.
values (Tuple[int, int] | Tuple[int, int, int]) –
- Returns:
Cell Object.
- Return type:
- get_cell_sheet_cell(sheet, rng_name)[source]
Gets a cell from a sheet using the cell name.
- Parameters:
sheet (XSpreadsheet) – Sheet.
rng_name (str) – Range name such as ‘A1:D7’.
- Returns:
Cell.
- Return type:
XCell
Note
In spreadsheets valid names may be
A1:C5
or$B$2
or even defined names for cell ranges such asMySpecialCell
.
- get_cell_str_col_row(col, row)[source]
LO Safe Method
- Return type:
str
- Parameters:
col (int) –
row (int) –
- get_cell_str_from_addr(addr)[source]
Gets the cell as string from a cell address.
- Parameters:
addr (CellAddress) – Cell Address.
- Returns:
Cell as string in the format of
A1
.- Return type:
str
- get_cell_str_from_cell(cell)[source]
Gets the cell as string from a cell.
- Parameters:
cell (XCell) – Cell.
- Returns:
Cell as string in the format of
A1
.- Return type:
str
- get_cell_str_from_cell_obj(cell_obj)[source]
Gets the cell as string from a cell object.
- Parameters:
cell_obj (CellObj) – Cell Object.
- Returns:
Cell as string in the format of
A1
.- Return type:
str
- get_cell_str_from_col_row(col, row)[source]
Gets the cell as string from column and row.
- Parameters:
col (int) – Column. Zero Based column index.
row (int) – Row. Zero Based row index.
- Returns:
Cell as string in the format of
A1
.- Return type:
str
- get_cell_values(cell)[source]
Gets the cell values from a cell like object.
- Parameters:
cell (XCell) – Cell.
- Returns:
Column and Row.
- Return type:
Tuple[int, int]
See also
get_cell_obj()
- get_offset_range_obj(range_obj)[source]
Gets a new range object with an offset from the original range object.
The returned range will have Start column of
A
, Start row of1
.- Parameters:
range_obj (RangeObj) – Range Object.
col_offset (int) – Column offset.
row_offset (int) – Row offset.
- Returns:
Range Object.
- Return type:
Note
A
RangeConverter.EVENT_RANGE_CREATING
event is triggered that allows for a sheet index to be set and any other range object args to be set. TheEventArgs.event_data
is a dictionary and contains the following keys:col_start: Column start such as
A
col_end: Column end such as
C
row_start: Row start such as
1
row_end: Row end such as
125
sheet_idx: Sheet index, if applicable, that this range value belongs to. Default is -1.
- get_range_from_2d(data)[source]
Creates a range object from a 2D array of data.
- Parameters:
data (Sequence[Sequence[Any]]) – 2D array of data.
- Returns:
Range object.
- Return type:
- get_range_obj(cell_obj: ooodev.utils.data_type.cell_obj.CellObj)[source]
- get_range_obj(range_obj: ooodev.utils.data_type.range_obj.RangeObj)
- get_range_obj(col_start: int, row_start: int, col_end: int)
- get_range_obj(addr: com.sun.star.table.CellRangeAddress)
- get_range_obj(rng: ooodev.utils.data_type.range_values.RangeValues)
- get_range_obj(cell_range: com.sun.star.table.XCellRange)
- get_range_obj(rng_name: str)
- get_range_obj(rng_name: str, sheet_idx: int)
- get_range_obj(*args, **kwargs)
Gets the cell as string from a cell.
- Parameters:
range_obj (RangeObj) – Range Object.
col_start (int) – Zero-based start column index.
row_start (int) – Zero-based start row index.
col_end (int) – Zero-based end column index.
row_end (int) – Zero-based end row index.
sheet_idx (int, optional) – Zero-based sheet index that this range value belongs to. Default is
-2
.addr (CellRangeAddress) – Cell Range Address.
rng (RangeValues) – Cell Range Values.
cell_range (XCellRange) – Cell Range.
rng_name (str) – Range as string such as
Sheet1.A1:C125
orA1:C125
- Returns:
Range Object.
- Return type:
- get_range_str_from_cr_addr(cr_addr)[source]
Gets the range as string from a Cell Range Address.
- Parameters:
cr_addr (CellRangeAddress) – Cell Range Address.
- Returns:
Range as string. In the format of
A1:B2
.- Return type:
str
- get_range_str_from_cr_addr_sheet(cr_addr, sheet)[source]
Return as str using the name taken from the sheet works, Sheet1.A1:B2
- Parameters:
cr_addr (CellRangeAddress) – Cell Range Address.
sheet (XSpreadsheet) – Sheet.
- Returns:
Range as string.
- Return type:
str
- get_range_values(rng)[source]
Gets the range values from a range like object.
- Parameters:
rng (Any) – Any value that can be converted to RangeObj.
- Returns:
Column and Row.
- Return type:
Tuple[int, int]
See also
get_range_obj()
- get_rng_str_from_cell_rng(cell_range, sheet)[source]
Return as str using the name taken from the sheet works, Sheet1.A1:B2
- Parameters:
cell_range (XCellRange) – Cell Range.
sheet (XSpreadsheet) – Sheet.
- Returns:
Range as string.
- Return type:
str
- get_safe_quoted_name(name)[source]
Returns the name quoted if it is not alphanumeric.
- Parameters:
name (str) – Name
- Returns:
Quoted name
- Return type:
str
- get_sheet_index(key=-1)[source]
Gets the sheet index from the current Calc document.
- Parameters:
key (str | int, optional) – Sheet name or Sheet index. A value of
-1
means get active sheet index. Defaults to-1
- Returns:
Sheet index or
-1
if not found. If current doc is not a Calc doc then-2
is returned.- Return type:
int
- get_sheet_name(sheet, safe_quote=True)[source]
Gets the name of a sheet.
- Parameters:
sheet (XSpreadsheet) – Spreadsheet
safe_quote (bool, optional) – If True, returns quoted (in single quotes) sheet name if the sheet name is not alphanumeric. Default is
True
.
- Returns:
Name of sheet
- Return type:
str
- is_cell_range_name(s)[source]
Gets if is a cell name or a cell range.
- Parameters:
s (str) – cell name such as ‘A1’ or range name such as ‘B3:E7’
- Returns:
True if range name; Otherwise, False
- Return type:
bool
- is_single_cell_range(cr_addr)[source]
Gets if a cell address is a single cell or a range.
- Parameters:
cr_addr (CellRangeAddress) – cell range address
- Returns:
True
if single cell; Otherwise,False
- Return type:
bool
- is_single_column_range(cr_addr)[source]
Gets if a cell address is a single column or multi-column.
- Parameters:
cr_addr (CellRangeAddress) – cell range address
- Returns:
True
if single column; Otherwise,False
- Return type:
bool
Note
If
cr_addr
is a single cell address thenTrue
is returned.
- is_single_row_range(cr_addr)[source]
Gets if a cell address is a single row or multi-row.
- Parameters:
cr_addr (CellRangeAddress) – cell range address
- Returns:
True
if single row; Otherwise,False
- Return type:
bool
Note
If
cr_addr
is a single cell address thenTrue
is returned.
- rng_from_cell_rng(cell_range)[source]
Gets a range Object representing a range.
- Parameters:
cell_range (XCellRange) – Cell Range.
- Returns:
Range object.
- Return type:
- rng_from_cell_rng_addr(addr)[source]
Gets a range Object representing a range from a cell range address.
- Parameters:
addr (CellRangeAddress) – Cell Range Address.
- Returns:
Range object.
- Return type:
- rng_from_cell_rng_value(rng)[source]
Gets a range Object representing a range from a cell range address.
- Parameters:
rng (RangeValues) – Cell Range Values.
- Returns:
Range object.
- Return type:
Hint
RangeValues
can be imported fromooodev.utils.data_type.range_values
- rng_from_position(col_start, row_start, col_end, row_end, sheet_idx=-2)[source]
Gets a range Object representing a range.
- Parameters:
col_start (int) – Zero-based start column index.
row_start (int) – Zero-based start row index.
col_end (int) – Zero-based end column index.
row_end (int) – Zero-based end row index.
sheet_idx (int, optional) – Zero-based sheet index that this range value belongs to. Default is -1.
- Returns:
Range object.
- Return type:
- rng_from_str(rng_name)[source]
Gets a range Object representing a range.
- Parameters:
rng_name (str) – Range as string such as
Sheet1.A1:C125
orA1:C125
. Cell name is also valid such asA1
.- Returns:
Range object.
- Return type:
- rng_from_str_idx(rng_name, sheet_idx)[source]
Gets a range Object representing a range.
- Parameters:
rng_name (str) – Range as string such as
Sheet1.A1:C125
orA1:C125
. Cell name is also valid such asA1
.sheet_idx (int) – Sheet index (zero based).
- Returns:
Range object.
- Return type:
- EVENT_CELL_CREATING = 'range_converter_cell_creating'
- EVENT_RANGE_CREATING = 'range_converter_range_creating'