Class CalcCharts

class ooodev.calc.CalcCharts(owner, charts, lo_inst=None)[source]

Bases: LoInstPropsPartial, TableChartsComp, QiPartial, ServicePartial, CalcSheetPropPartial, CalcDocPropPartial

Class for managing Calc Charts.

New in version 0.26.1..

__delitem__(_item)[source]

Removes a chart from the document.

Parameters:

_item (int | str, TableChart) – Index, name, or TableChart to remove.

Raises:

TypeError – If the item is not a supported type.

Return type:

None

__getitem__(index)[source]

Gets the chart at the specified index or name.

This is short hand for get_by_index() or get_by_name().

Parameters:
  • key (key, str, int) – The index or name of the chart. When getting by index can be a negative value to get from the end.

  • index (str | int) –

Returns:

The chart with the specified index or name.

Return type:

TableChart

__init__(owner, charts, lo_inst=None)[source]

Constructor

Parameters:
  • owner (CalcDoc) – Owner Document

  • sheet (XSpreadsheet) – Sheet instance.

  • charts (XTableCharts) –

  • lo_inst (LoInst | None) –

Return type:

None

__len__()[source]

Gets the number of charts in the document.

Returns:

Number of charts in the document.

Return type:

int

__next__()[source]

Gets the next chart.

Returns:

The next chart.

Return type:

TableChart

add_new_by_name(name, rect, ranges, column_headers, row_headers)

Creates a chart and adds it to the collection.

Return type:

None

Parameters:
  • name (str) –

  • rect (com.sun.star.awt.Rectangle) –

  • ranges (Tuple[CellRangeAddress, ...]) –

  • column_headers (bool) –

  • row_headers (bool) –

clear()[source]

Removes all charts from the sheet.

Return type:

None

create_enumeration()

Creates an enumeration of the container’s elements.

Return type:

XEnumeration

get_by_index(idx)[source]

Gets the element at the specified index.

Parameters:

idx (int) – The Zero-based index of the element. Idx can be a negative value to index from the end of the list. For example, -1 will return the last element.

Returns:

The element at the specified index.

Return type:

CalcSheet

get_by_name(name)[source]

Gets the element with the specified name.

Parameters:

name (str) – The name of the element.

Raises:

MissingNameError – If sheet is not found.

Returns:

The element with the specified name.

Return type:

CalcSheet

get_count()

Gets the number of elements contained in the container.

Returns:

The number of elements.

Return type:

int

get_element_names()

Gets the names of all elements contained in the container.

Returns:

The names of all elements.

Return type:

tuple[str, …]

get_element_type()

Gets the type of the elements contained in the container.

Returns:

The type of the elements. None means that it is a multi-type container and you cannot determine the exact types with this interface.

Return type:

Any

get_services()

Gets service names for the instance.

Returns:

service names

Return type:

List[str]

has_by_name(name)

Checks if the container has an element with the specified name.

Parameters:

name (str) – The name of the element.

Returns:

True if the container has an element with the specified name, otherwise False.

Return type:

bool

has_elements()

Determines whether the container has elements.

Return type:

bool

insert_chart(*, rng_obj=None, cell_name='', width=16, height=9, diagram_name='Column', color_bg=14085119, color_wall=11393254, **kwargs)[source]

Insert a new chart.

Parameters:
  • rng_obj (RangeObj, optional) – Cell range object. Defaults to current selected cells.

  • cell_name (str, optional) – Cell name such as A1.

  • width (int, optional) – Width. Default 16.

  • height (int, optional) – Height. Default 9.

  • diagram_name (ChartTemplateBase | str) – Diagram Name. Defaults to Column.

  • color_bg (Color, optional) – Color Background. Defaults to CommonColor.PALE_BLUE. If set to None then no color is applied.

  • color_wall (Color, optional) – Color Wall. Defaults to CommonColor.LIGHT_BLUE. If set to None then no color is applied.

Keyword Arguments:
  • chart_name (str, optional) – Chart name

  • is_row (bool, optional) – Determines if the data is row data or column data.

  • first_cell_as_label (bool, optional) – Set is first row is to be used as a label.

  • set_data_point_labels (bool, optional) – Determines if the data point labels are set.

Raises:

ChartError – If error occurs

Returns:

Chart Document that was created and inserted into the sheet.

Return type:

TableChart

Note

Keyword Arguments are to mostly be ignored. If finer control over chart creation is needed then Keyword Arguments can be used.

Note

See Open Office Wiki - The Structure of Charts for more information.

qi(atype, raise_err=False)

Generic method that get an interface instance from an object.

Parameters:
  • atype (T) – Interface type to query obj for. Any Uno class that starts with ‘X’ such as XInterface

  • raise_err (bool, optional) – If True then raises MissingInterfaceError if result is None. Default False

Raises:

MissingInterfaceError – If ‘raise_err’ is ‘True’ and result is None

Returns:

instance of interface if supported; Otherwise, None

Return type:

T | None

Note

When raise_err=True return value will never be None.

remove_by_name(name)

Removes a chart from the collection.

Return type:

None

Parameters:

name (str) –

remove_chart(chart_name)[source]

Removes a chart from Spreadsheet.

Parameters:
  • sheet (XSpreadsheet) – Spreadsheet

  • chart_name (str) – Chart Name

Returns:

True if chart was removed; Otherwise, False

Return type:

bool

support_service(*service)

Gets if instance supports a service.

Parameters:

*service (str) – Variable length argument list of UNO namespace strings such as com.sun.star.configuration.GroupAccess

Returns:

True if instance supports any passed in service; Otherwise, False

Return type:

bool

property calc_doc: CalcDoc

Calc Document.

Return type:

CalcDoc

property calc_sheet: CalcSheet

Calc Sheet.

Return type:

CalcSheet

property component: com.sun.star.table.TableCharts

TableCharts Component

Return type:

TableCharts

property lo_inst: LoInst

Lo Instance

Return type:

LoInst

property office_doc: OfficeDocumentT

Office Document.

Return type:

OfficeDocumentT