Difference between revisions of "CellCustomAtributes"
From Apache OpenOffice Wiki
(Python modules) |
(Python modules) |
||
Line 33: | Line 33: | ||
<source lang=python>oCell.UserDefinedAttributes = oUserDefinedAttributes</source> | <source lang=python>oCell.UserDefinedAttributes = oUserDefinedAttributes</source> | ||
in the example above. | in the example above. | ||
− | |||
− | |||
− | |||
Then, using a new python session, I reloaded the document and verified that it had my custom attribute.... <source lang=python>>>> from Danny.OOo.OOoLib import * | Then, using a new python session, I reloaded the document and verified that it had my custom attribute.... <source lang=python>>>> from Danny.OOo.OOoLib import * |
Revision as of 03:00, 18 February 2015
I created a spreadsheet with a user defined attribute like this....
>>> import Danny.OOo.OOoLib >>> from Danny.OOo.OOoLib import * >>> oDoc = StarDesktop.loadComponentFromURL( "private:factory/scalc", "_blank", 0, Array() ) >>> oSheet = oDoc.getSheets().getByIndex( 0 ) >>> oCell = oSheet.getCellByPosition( 2, 5 ) >>> oUserDefinedAttributes = oShape.UserDefinedAttributes Traceback (most recent call last): File "<pyshell#5>", line 1, in -toplevel- oUserDefinedAttributes = oShape.UserDefinedAttributes NameError: name 'oShape' is not defined >>> oUserDefinedAttributes = oCell.UserDefinedAttributes >>> oUserDefinedAttributes.hasByName( "MeowMix" ) False >>> oMyAttribute = createUnoStruct( "com.sun.star.xml.AttributeData" ) >>> oMyAttribute.Type = "CDATA" >>> oMyAttribute.Value = "Giddy Gat" >>> oUserDefinedAttributes.insertByName( "MeowMix", oMyAttribute ) >>> oCell.UserDefinedAttributes = oUserDefinedAttributes >>> oDoc.storeToURL( convertToURL( "C:\\Documents and Settings\\dbrewer\\Desktop\Test.sxc" ), Array() ) >>> oDoc.close( True ) >>>
Please note that it is IMPORTANT to store the collection of user attributes back to the property like so....
oCell.UserDefinedAttributes = oUserDefinedAttributes
in the example above.
Then, using a new python session, I reloaded the document and verified that it had my custom attribute....>>> from Danny.OOo.OOoLib import * >>> oDoc = StarDesktop.loadComponentFromURL( convertToURL( "C:\\Documents and Settings\\dbrewer\\Desktop\Test.sxc" ), "_blank", 0, Array() ) >>> oSheet = oDoc.getSheets().getByIndex( 0 ) >>> oCell = oSheet.getCellByPosition( 2, 5 ) >>> oUserDefinedAttributes = oCell.UserDefinedAttributes >>> oUserDefinedAttributes.hasByName( "MeowMix" ) True >>> oMyAttribute = oUserDefinedAttributes.getByName( "MeowMix" ) >>> oMyAttribute.Value u'Giddy Gat' >>> oDoc.close( True ) >>>