libreoffice calc - How to use userDefinedProperties to record persistent variables between 2 calls - Stack Overflow

i have hard to find solutions to record some variables i would like to be persistent during session (un

i have hard to find solutions to record some variables i would like to be persistent during session (untill i close libreoffice-cal application). First, i would like to know if i can record complex values as object by this way and methode. Second, what goes wrong with what i 've tried.

 dim docprops as object
 dim userprops as object
 dim usersetinf as object
 dim cell as object
 dim nom as string
 nom = "test"
 cell = thiscomponent.sheets.getbyname("Ingrédients").getcellbyposition(0,0)
 on error goto err
 docprops = thiscomponent.getdocumentproperties()
 userprops = docprops.userdefinedproperties
 usersetinf = userprops.getpropertysetinfo()
 if usersetinf.haspropertybyname(nom) then userprops.removeproperty(nom)

In this sample, i try to record a simple ScCellObj.I can add a new property called "nom" but i am not abble to add it with the value : this cell object. .addproperty(nom, ? , ?) this method i don't understand, i have managed to do this :

userprops.addproperty(nom,128,"")

first '?' : 128 is not clear for me, this parameter is called aAttributes[] as integer, i have seen those defined constants but not really clear.

second '?' : IS type value as a default value (something like that) and really i don't see clear what i can put on there, a constant ? the type of the value i want to record ?

well, so i 've tried :

userprops.addproperty(nom,128,cell)

it does not work.

 userprops.addproperty(nom,128,"") ' ok
 userprops.setpropertyvalues(nom,cell) ' ERR !

it doesn't work

Who can help me please to make this working ?

i have hard to find solutions to record some variables i would like to be persistent during session (untill i close libreoffice-cal application). First, i would like to know if i can record complex values as object by this way and methode. Second, what goes wrong with what i 've tried.

 dim docprops as object
 dim userprops as object
 dim usersetinf as object
 dim cell as object
 dim nom as string
 nom = "test"
 cell = thiscomponent.sheets.getbyname("Ingrédients").getcellbyposition(0,0)
 on error goto err
 docprops = thiscomponent.getdocumentproperties()
 userprops = docprops.userdefinedproperties
 usersetinf = userprops.getpropertysetinfo()
 if usersetinf.haspropertybyname(nom) then userprops.removeproperty(nom)

In this sample, i try to record a simple ScCellObj.I can add a new property called "nom" but i am not abble to add it with the value : this cell object. .addproperty(nom, ? , ?) this method i don't understand, i have managed to do this :

userprops.addproperty(nom,128,"")

first '?' : 128 is not clear for me, this parameter is called aAttributes[] as integer, i have seen those defined constants but not really clear.

second '?' : IS type value as a default value (something like that) and really i don't see clear what i can put on there, a constant ? the type of the value i want to record ?

well, so i 've tried :

userprops.addproperty(nom,128,cell)

it does not work.

 userprops.addproperty(nom,128,"") ' ok
 userprops.setpropertyvalues(nom,cell) ' ERR !

it doesn't work

Who can help me please to make this working ?

Share Improve this question asked Mar 21 at 9:24 Denis MDenis M 911 silver badge8 bronze badges 1
  • i fot to tell, libreoffice-cal version, 7.4.7.2 (Linux 6.1, debian bookworm) – Denis M Commented Mar 21 at 9:27
Add a comment  | 

1 Answer 1

Reset to default 1

First, 128 means REMOVABLE, which "indicates that the property can be removed (i.e., by calling XPropertyContainer::removeProperty())." That's the only flag I normally use.

Second, you mentioned wanting the data to persist only until the application is closed. User defined properties are stored in the document, so saving the document will also save the data for when that same document is opened next time. If you don't want that, maybe TRANSIENT would change the behavior?

Finally, this method does not store objects, and indeed, I can't imagine how that would work, as objects are dynamic references to the document. Instead, store the address or the contents of the cell (or both). If it seems like your project needs something different, maybe it would help to explain why you want to store an actual cell object, or how you expect that would work.

Here is a full example (in Python, but with the same UNO interface as Basic) that stores a user defined property.

import uno
from com.sun.star.beans.PropertyAttribute import REMOVEABLE

def store(self, varName, val):
    """Stores a value in a document. The value is persistent across macro
    calls.
    """
    oDocProps = oDoc.getDocumentProperties()
    self.userProps = oDocProps.getUserDefinedProperties()
    if val is None:
        stringVal = ""
    else:
        stringVal = str(val)
    if self.userPropsInfo().hasPropertyByName(varName):
        self.userProps.setPropertyValue(varName, stringVal)
    else:
        self.userProps.addProperty(varName, REMOVEABLE, stringVal)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744363768a4570598.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信