from __future__ import annotations
from typing import Any, TYPE_CHECKING
from com.sun.star.table import XCell
from ooodev.exceptions import ex as mEx
from ooodev.loader import lo as mLo
if TYPE_CHECKING:
from ooo.dyn.table.cell_content_type import CellContentType
from ooodev.utils.type_var import UnoInterface
[docs]class CellPartial:
"""
Partial Class for XCell.
"""
# pylint: disable=unused-argument
[docs] def __init__(self, component: XCell, interface: UnoInterface | None = XCell) -> None:
"""
Constructor
Args:
component (XCell): UNO Component that implements ``com.sun.star.table.XCell`` interface.
interface (UnoInterface, optional): The interface to be validated. Defaults to ``XCell``.
"""
def validate(comp: Any, obj_type: Any) -> None:
if obj_type is None:
return
if not mLo.Lo.is_uno_interfaces(comp, obj_type):
raise mEx.MissingInterfaceError(obj_type)
validate(component, interface)
self.__component = component
# region XCell
[docs] def get_error(self) -> int:
"""
returns the error value of the cell.
If the cell does not contain a formula, the error is always zero.
"""
return self.__component.getError()
[docs] def get_type(self) -> CellContentType:
"""
Gets the type of the cell.
Returns:
CellContentType: The type of the cell.
Hint:
- ``CellContentType`` can be imported from ``ooo.dyn.table.cell_content_type``.
"""
return self.__component.getType() # type: ignore
[docs] def get_value(self) -> float:
"""
Gets the floating point value of the cell.
For a value cell the value is returned, for a string cell zero is returned and for a formula cell the result value of a formula is returned.
"""
return self.__component.getValue()
[docs] def set_value(self, value: float) -> None:
"""
Sets a floating point value into the cell.
After a call to this method the type of the cell is C``ellContentType.VALUE``.
"""
self.__component.setValue(value)
# endregion XCell