In Writer, data for each document can be stored with text field masters.
fieldMasters = self.document.getTextFieldMasters()
fieldName = "com.sun.star.text.FieldMaster.User." + varName
if fieldMasters.hasByName(fieldName):
field = fieldMasters.getByName(fieldName)
field.setPropertyValue("Content", stringVal)
else:
xMaster = self.document.createInstance(
"com.sun.star.text.fieldmaster.User")
xMaster.Name = varName
xMaster.Content = stringVal
xUserField = self.document.createInstance(
"com.sun.star.text.textfield.User")
xUserField.attachTextFieldMaster(xMaster)
This works very well, and the values can even be managed manually by going to Insert → Fields → More Fields, Variables, User Field.
However, I have not found a way to store data for Calc or other components of LibO. My current solution is to save a separate Writer document and then store the values in it. But that means that when using Calc, two files must be saved and opened together (the Calc file and a Writer file), which seems less than ideal.
There is com.sun.star.comp.configuration.ConfigurationProvider
, but this is global, and I need different data for each document.
Is there a way to store data in documents for components other than Writer?