I am wondering if a sheet has a unique identifier, one that does not change when the sheet is renamed or moved in the document.
I found How to uniquely identify sheet in calc but it was not aswerred.
My current solution is add a hidden control with a unique generated name to a page as follows:
def _get_sheet_id(self) -> str:
# need to get a unique id for the sheet.
if not self._addr:
raise Exception("_get_sheet_id() No cell selected")
sheet = self._doc.sheets[self._addr.Sheet]
if len(sheet.draw_page.forms) == 0:
frm = sheet.draw_page.forms.add_form("Form1")
else:
frm = sheet.draw_page.forms[0]
if frm.has_by_name(self._hidden_name):
ctl = FormCtlHidden(frm.get_by_name(self._hidden_name), self._doc.lo_inst)
sheet_id = cast(str, ctl.get_property("sheet_id"))
return sheet_id
ctl = frm.insert_control_hidden(name=self._hidden_name)
ctl.hidden_value = "SheetId"
str_id = gUtil.Util.generate_random_string(10)
ctl.add_property("sheet_id", PropertyAttributeEnum.CONSTRAINED, str_id)
return str_id
I don’t want to re-invent the wheel so I am wondering if there is another (existing) way?