If we design Claases they should proper designed:
from com.sun.star.sheet import XSpreadsheets
from unohelper import Base
class Sheets( XSpreadsheets, Base):
def __init__(self, sheets):
XSpreadsheets.__init__(sheets)
self.sheets = sheets
## ↓↓↓ copy NameSpace from 'sheets' into class.Namespace
## !ugly … is there a better way ??
for entry in dir(sheets):
setattr(self, entry, getattr(sheets, entry))
def getByCodeName(self, code_name):
for sheet in self.sheets:
if sheet.CodeName == code_name:
return sheet
raise NameError(f"Sheet with CodeName: {code_name} dont exist")
def test():
doc = XSCRIPTCONTEXT.getDocument()
sheets = Sheets(doc.Sheets)
sheet = sheets.getByCodeName('Tabelle1')
print(sheet.Name)
print(sheets.getByName(sheet.Name).AbsoluteName)