Copy from doc refactory

This commit is contained in:
Mauricio Baeza 2020-11-08 22:12:24 -06:00
parent 772dacb828
commit 56360bb10d
2 changed files with 23 additions and 31 deletions

View File

@ -261,42 +261,11 @@ class LOImage(object):
class LOCalc(LODocument):
@property
def sheets(self):
return LOCalcSheets(self._sheets, self)
@property
def cell_style(self):
obj = self.obj.getStyleFamilies()['CellStyles']
return LOCellStyles(obj)
def copy_from(self, doc, source='', target='', pos=-1):
index = pos
if pos < 0:
index = self._sheets.Count + pos + 1
names = source
if not names:
names = doc.names
elif isinstance(source, str):
names = (source,)
new_names = target
if not target:
new_names = names
elif isinstance(target, str):
new_names = (target,)
for i, n in enumerate(names):
self._sheets.importSheet(doc.obj, n, index + i)
self.sheets[index + i].name = new_names[i]
# ~ doc.getCurrentController().setActiveSheet(sheet)
# ~ For controls in sheet
# ~ doc.getCurrentController().setFormDesignMode(False)
return LOCalcSheet(self._sheets[index], self)
def sort(self, reverse=False):
names = sorted(self.names, reverse=reverse)
for i, n in enumerate(names):

View File

@ -1149,6 +1149,29 @@ class LOCalc(LODocument):
self._sheets.copyByName(name, new_name, index)
return LOCalcSheet(self._sheets[new_name])
def copy_from(self, doc, source='', target='', pos=-1):
index = pos
if pos < 0:
index = len(self)
names = source
if not source:
names = doc.names
elif isinstance(source, str):
names = (source,)
new_names = target
if not target:
new_names = names
elif isinstance(target, str):
new_names = (target,)
for i, name in enumerate(names):
self._sheets.importSheet(doc.obj, name, index + i)
self[index + i].name = new_names[i]
return LOCalcSheet(self._sheets[index])
def render(self, data, sheet=None, clean=True):
if sheet is None:
sheet = self.active