Add tables for Writer
This commit is contained in:
parent
0b116337c4
commit
2069ac0ba8
|
@ -4,18 +4,21 @@
|
||||||
# ~ https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1CellFlags.html
|
# ~ https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1CellFlags.html
|
||||||
|
|
||||||
from com.sun.star.sheet import CellFlags
|
from com.sun.star.sheet import CellFlags
|
||||||
|
from .easyuno import BitmapMode, CellContentType, FillStyle, LineStyle
|
||||||
from .easyuno import BitmapMode, FillStyle, LineStyle
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'ALL',
|
'ALL',
|
||||||
'ONLY_DATA',
|
'ONLY_DATA',
|
||||||
'BitmapMode',
|
'BitmapMode',
|
||||||
|
'CellContentType',
|
||||||
'FillStyle',
|
'FillStyle',
|
||||||
'LineStyle',
|
'LineStyle',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# ~ VALUE, DATETIME, STRING, ANNOTATION, FORMULA
|
||||||
ONLY_DATA = 31
|
ONLY_DATA = 31
|
||||||
|
|
||||||
ALL = 1023
|
ALL = 1023
|
||||||
|
|
||||||
|
SECONDS_DAY = 86400
|
|
@ -4,9 +4,6 @@ import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
from com.sun.star.sheet import CellFlags
|
|
||||||
from com.sun.star.table.CellContentType import EMPTY, VALUE, TEXT, FORMULA
|
|
||||||
|
|
||||||
from .easymain import (log, DATE_OFFSET,
|
from .easymain import (log, DATE_OFFSET,
|
||||||
BaseObject, Color, LOMain,
|
BaseObject, Color, LOMain,
|
||||||
dict_to_property, run_in_thread, set_properties
|
dict_to_property, run_in_thread, set_properties
|
||||||
|
@ -17,15 +14,9 @@ from .easyshape import LOShapes, LOShape
|
||||||
from .easydrawpage import LODrawPage
|
from .easydrawpage import LODrawPage
|
||||||
from .easyforms import LOForms
|
from .easyforms import LOForms
|
||||||
from .easystyles import LOStyleFamilies
|
from .easystyles import LOStyleFamilies
|
||||||
|
from .constants import ONLY_DATA, SECONDS_DAY, CellContentType
|
||||||
|
|
||||||
|
|
||||||
SECONDS_DAY = 60 * 60 * 24
|
|
||||||
ONLY_VALUES = CellFlags.VALUE + CellFlags.DATETIME + CellFlags.STRING
|
|
||||||
|
|
||||||
|
|
||||||
# ~ IsFiltered,
|
|
||||||
# ~ IsManualPageBreak,
|
|
||||||
# ~ IsStartOfNewPage
|
|
||||||
class LOSheetRows():
|
class LOSheetRows():
|
||||||
|
|
||||||
def __init__(self, sheet, obj, range_address):
|
def __init__(self, sheet, obj, range_address):
|
||||||
|
@ -45,7 +36,7 @@ class LOSheetRows():
|
||||||
return self.obj.Count
|
return self.obj.Count
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
name = f'Rows: {self._ra.StartRow} - {self._ra.EndRow}'
|
name = f'Rows: {self._ra.StartRow} to {self._ra.EndRow}'
|
||||||
return name
|
return name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -59,6 +50,27 @@ class LOSheetRows():
|
||||||
def visible(self, value):
|
def visible(self, value):
|
||||||
self._obj.IsVisible = value
|
self._obj.IsVisible = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_filtered(self):
|
||||||
|
return self._obj.IsFiltered
|
||||||
|
@is_filtered.setter
|
||||||
|
def is_filtered(self, value):
|
||||||
|
self._obj.IsFiltered = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_manual_page_break(self):
|
||||||
|
return self._obj.IsManualPageBreak
|
||||||
|
@is_manual_page_break.setter
|
||||||
|
def is_manual_page_break(self, value):
|
||||||
|
self._obj.IsManualPageBreak = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_start_of_new_page(self):
|
||||||
|
return self._obj.IsStartOfNewPage
|
||||||
|
@is_start_of_new_page.setter
|
||||||
|
def is_start_of_new_page(self, value):
|
||||||
|
self._obj.IsStartOfNewPage = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color(self):
|
def color(self):
|
||||||
return self.obj.CellBackColor
|
return self.obj.CellBackColor
|
||||||
|
@ -215,9 +227,7 @@ class LOCalcRange():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
ra = self.range_address
|
return self.obj.Rows.Count
|
||||||
rows = ra.EndRow - ra.StartRow + 1
|
|
||||||
return rows
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = f'Range: {self.name}'
|
s = f'Range: {self.name}'
|
||||||
|
@ -375,11 +385,11 @@ class LOCalcRange():
|
||||||
def value(self):
|
def value(self):
|
||||||
"""Get or set value, automatically get type data"""
|
"""Get or set value, automatically get type data"""
|
||||||
v = None
|
v = None
|
||||||
if self.type == VALUE:
|
if self.type == CellContentType.VALUE:
|
||||||
v = self.float
|
v = self.float
|
||||||
elif self.type == TEXT:
|
elif self.type == CellContentType.TEXT:
|
||||||
v = self.string
|
v = self.string
|
||||||
elif self.type == FORMULA:
|
elif self.type == CellContentType.FORMULA:
|
||||||
v = self.formula
|
v = self.formula
|
||||||
return v
|
return v
|
||||||
@value.setter
|
@value.setter
|
||||||
|
@ -535,7 +545,7 @@ class LOCalcRange():
|
||||||
c2 = ra.EndColumn + 1
|
c2 = ra.EndColumn + 1
|
||||||
return LOCalcRange(self.sheet[r1:r2, c1:c2].obj)
|
return LOCalcRange(self.sheet[r1:r2, c1:c2].obj)
|
||||||
|
|
||||||
def clear(self, what: int=ONLY_VALUES):
|
def clear(self, what: int=ONLY_DATA):
|
||||||
"""Clear contents"""
|
"""Clear contents"""
|
||||||
# ~ http://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1CellFlags.html
|
# ~ http://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1CellFlags.html
|
||||||
self.obj.clearContents(what)
|
self.obj.clearContents(what)
|
||||||
|
|
|
@ -21,10 +21,6 @@ TYPE_SHAPES = ('Line', 'Measure', 'Rectangle', 'Ellipse', 'Text', 'Connector',
|
||||||
|
|
||||||
# ~ class LOShapeBK(BaseObject):
|
# ~ class LOShapeBK(BaseObject):
|
||||||
|
|
||||||
# ~ @property
|
|
||||||
# ~ def cell(self):
|
|
||||||
# ~ return self.anchor
|
|
||||||
|
|
||||||
# ~ @property
|
# ~ @property
|
||||||
# ~ def anchor(self):
|
# ~ def anchor(self):
|
||||||
# ~ obj = self.obj.Anchor
|
# ~ obj = self.obj.Anchor
|
||||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
||||||
from com.sun.star.awt import Size, Point
|
from com.sun.star.awt import Size, Point
|
||||||
from .easymain import (
|
from .easymain import (
|
||||||
BaseObject, Paths,
|
BaseObject, Paths,
|
||||||
create_instance, dict_to_property, set_properties, get_properties
|
create_instance, dict_to_property, log, set_properties, get_properties
|
||||||
)
|
)
|
||||||
from .easyuno import (
|
from .easyuno import (
|
||||||
BaseObjectProperties,
|
BaseObjectProperties,
|
||||||
|
@ -14,11 +14,13 @@ from .easyuno import (
|
||||||
|
|
||||||
|
|
||||||
IMAGE = 'com.sun.star.drawing.GraphicObjectShape'
|
IMAGE = 'com.sun.star.drawing.GraphicObjectShape'
|
||||||
|
|
||||||
MIME_TYPE = {
|
MIME_TYPE = {
|
||||||
'image/png': 'png',
|
'image/png': 'png',
|
||||||
'image/jpeg': 'jpg',
|
'image/jpeg': 'jpg',
|
||||||
'image/svg': 'svg',
|
'image/svg': 'svg',
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPE_MIME = {
|
TYPE_MIME = {
|
||||||
'svg': 'image/svg',
|
'svg': 'image/svg',
|
||||||
'png': 'image/png',
|
'png': 'image/png',
|
||||||
|
@ -72,9 +74,32 @@ class LOShape(BaseObjectProperties):
|
||||||
return f'Shape: {self.name}'
|
return f'Shape: {self.name}'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
def sheet(self):
|
||||||
|
return self.anchor
|
||||||
|
@sheet.setter
|
||||||
|
def sheet(self, value):
|
||||||
|
self.anchor = value
|
||||||
|
@property
|
||||||
|
def cell(self):
|
||||||
|
return self.anchor
|
||||||
|
@cell.setter
|
||||||
|
def cell(self, value):
|
||||||
|
self.anchor = value
|
||||||
|
@property
|
||||||
def anchor(self):
|
def anchor(self):
|
||||||
|
from .easycalc import LOCalcSheet, LOCalcRange
|
||||||
|
TYPE_ANCHOR = {
|
||||||
|
'ScTableSheetObj': LOCalcSheet,
|
||||||
|
'ScCellObj': LOCalcRange,
|
||||||
|
}
|
||||||
"""Get anchor object"""
|
"""Get anchor object"""
|
||||||
return self.obj.Anchor
|
obj = self.obj.Anchor
|
||||||
|
implementation = obj.ImplementationName
|
||||||
|
if implementation in TYPE_ANCHOR:
|
||||||
|
obj = TYPE_ANCHOR[implementation](obj)
|
||||||
|
else:
|
||||||
|
log.debug(implementation)
|
||||||
|
return obj
|
||||||
@anchor.setter
|
@anchor.setter
|
||||||
def anchor(self, obj):
|
def anchor(self, obj):
|
||||||
if hasattr(obj, 'obj'):
|
if hasattr(obj, 'obj'):
|
||||||
|
|
|
@ -28,6 +28,10 @@ class BitmapMode():
|
||||||
from com.sun.star.drawing.BitmapMode import REPEAT, STRETCH, NO_REPEAT
|
from com.sun.star.drawing.BitmapMode import REPEAT, STRETCH, NO_REPEAT
|
||||||
|
|
||||||
|
|
||||||
|
class CellContentType():
|
||||||
|
from com.sun.star.table.CellContentType import EMPTY, VALUE, TEXT, FORMULA
|
||||||
|
|
||||||
|
|
||||||
class IOStream(object):
|
class IOStream(object):
|
||||||
"""Classe for input/output stream"""
|
"""Classe for input/output stream"""
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,170 @@ from .easydrawpage import LODrawPage
|
||||||
from .easystyles import LOStyleFamilies
|
from .easystyles import LOStyleFamilies
|
||||||
|
|
||||||
|
|
||||||
|
class LOTableRange(BaseObject):
|
||||||
|
|
||||||
|
def __init__(self, table, obj):
|
||||||
|
self._table = table
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'TextTable: Range - {self.name}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
if self.is_cell:
|
||||||
|
n = self.obj.CellName
|
||||||
|
else:
|
||||||
|
c1 = self.obj[0,0].CellName
|
||||||
|
c2 = self.obj[self.rows-1,self.columns-1].CellName
|
||||||
|
n = f'{c1}:{c2}'
|
||||||
|
return n
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_cell(self):
|
||||||
|
return hasattr(self.obj, 'CellName')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def data(self):
|
||||||
|
return self.obj.getDataArray()
|
||||||
|
@data.setter
|
||||||
|
def data(self, values):
|
||||||
|
self.obj.setDataArray(values)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rows(self):
|
||||||
|
return len(self.data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def columns(self):
|
||||||
|
return len(self.data[0])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def string(self):
|
||||||
|
return self.obj.String
|
||||||
|
@string.setter
|
||||||
|
def string(self, value):
|
||||||
|
self.obj.String = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
return self.obj.Value
|
||||||
|
@value.setter
|
||||||
|
def value(self, value):
|
||||||
|
self.obj.Value = value
|
||||||
|
|
||||||
|
|
||||||
|
class LORow(BaseObject):
|
||||||
|
|
||||||
|
def __init__(self, rows, index):
|
||||||
|
self._rows = rows
|
||||||
|
self._index = index
|
||||||
|
super().__init__(rows[index])
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'TextTable: Row'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def height(self):
|
||||||
|
return self.obj.Height
|
||||||
|
@height.setter
|
||||||
|
def height(self, value):
|
||||||
|
self.obj.Height = value
|
||||||
|
|
||||||
|
def remove(self):
|
||||||
|
self._rows.removeByIndex(self._index, 1)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class LORows(BaseObject):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'TextTable: Rows'
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return self.obj.Count
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return LORow(self.obj, key)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def count(self):
|
||||||
|
return self.obj.Count
|
||||||
|
|
||||||
|
def remove(self, index, count=1):
|
||||||
|
self.obj.removeByIndex(index, count)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class LOTextTable(BaseObject):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'Writer: TextTable - {self.name}'
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
self._i = 0
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
"""Interation cells"""
|
||||||
|
try:
|
||||||
|
name = self.obj.CellNames[self._i]
|
||||||
|
except IndexError:
|
||||||
|
raise StopIteration
|
||||||
|
self._i += 1
|
||||||
|
return self[name]
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
if isinstance(key, str):
|
||||||
|
if ':' in key:
|
||||||
|
rango = self.obj.getCellRangeByName(key)
|
||||||
|
else:
|
||||||
|
rango = self.obj.getCellByName(key)
|
||||||
|
elif isinstance(key, tuple):
|
||||||
|
if isinstance(key[0], slice):
|
||||||
|
rango = self.obj.getCellRangeByPosition(
|
||||||
|
key[1].start, key[0].start, key[1].stop-1, key[0].stop-1)
|
||||||
|
else:
|
||||||
|
rango = self.obj[key]
|
||||||
|
return LOTableRange(self.obj, rango)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.obj.Name
|
||||||
|
@name.setter
|
||||||
|
def name(self, value):
|
||||||
|
self.obj.Name = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rows(self):
|
||||||
|
return LORows(self.obj.Rows)
|
||||||
|
|
||||||
|
|
||||||
|
class LOTextTables(BaseObject):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Writer: TextTables'
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return LOTextTable(self.obj[key])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LOWriterTextPortion(BaseObject):
|
class LOWriterTextPortion(BaseObject):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
|
@ -180,6 +344,10 @@ class LOWriter(LODocument):
|
||||||
def view_cursor(self):
|
def view_cursor(self):
|
||||||
return self._cc.ViewCursor
|
return self._cc.ViewCursor
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tables(self):
|
||||||
|
return LOTextTables(self.obj.TextTables)
|
||||||
|
|
||||||
def select(self, rango: Any):
|
def select(self, rango: Any):
|
||||||
""""""
|
""""""
|
||||||
obj = rango
|
obj = rango
|
||||||
|
|
Loading…
Reference in New Issue