Weird dot syntax?

See: we have a sheet named ‘Help’
oSheet = ThisComponent.Sheets("Help") 'no errors, but it doesn’n return the desired sheet
Can you refer to an object like that?
oSheet = ThisComponent.Sheets.Help 'it works (!) WHY?


The instructions are equivalent:
oDlg = CreateUnoDialog(DialogLibraries.getByName(Standard).getByName(HelpDlg))
oDlg = CreateUnoDialog(DialogLibraries.Standard.HelpDlg)

The instructions are not equivalent:
oSheet = ThisComponent.Sheets.getByName("Help")
oSheet = ThisComponent.Sheets("Help")  'no errors, but it doesn'n return the desired sheet
oSheet = ThisComponent.Sheets.Help  'it works (!) 

The instructions are equivalent:
oSheet = ThisComponent.Sheets.getByIndex(i)
oSheet = ThisComponent.Sheets(i)

oSheet = ThisComponent.Sheets.Help 'it works (!) WHY?

Implementiondetail or Bug?! why did you ask here??

Python (roundabout since Version LO5):

doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.Sheets.Help  #ok, but obviously not for sheetnames with <space> in Name
sheet = doc.Sheets["Help"] #ok also with <space>
sheet = doc.Sheets[0] #ok first by Index

all above are “convinient shorts” instead the explizit Methods …getByName(…) respectively …geByIndex(…)

1 Like