Skip to content

Commit 50a1ae8

Browse files
committed
wks.userprops and put back
1 parent 2df27a1 commit 50a1ae8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

1. Origin-Python Data Exchange/Worksheet User Tree Access.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
2-
This sample shows how to set values to worksheet tree nodes, and
3-
then read out into a tree object. This is useful to save the metadata
2+
This sample shows how to prepare a worksheet tree, and
3+
how to read the values back. This is useful to save the metadata
44
of a data file. See the blog:
55
https://blog.originlab.com/accessing-metadata-using-python
66
'''
@@ -13,8 +13,22 @@
1313
wks.set_int("tree.data.age", 37)
1414
wks.set_float("tree.data.mean", 23.56)
1515

16-
# Save the worksheet tree values to a tree object and print out the values.
16+
# access the tree as a dictionary
17+
dd = wks.userprops['data']
18+
user=dd['name']
19+
value=dd['age']
20+
print(f'{user} is {value}')
21+
22+
# you can also get the tree as an xml ElementTree for more advanced usage
1723
trWks = wks.usertree
1824
trData = trWks.find('data')
1925
for child in trData:
2026
print(f'{child.tag} = {child.text}')
27+
28+
# how to put a modified tree to another sheet
29+
wk2 = op.new_sheet()
30+
age_node=trData.find('age')
31+
age_node.text='47'
32+
33+
wk2.usertree=trWks
34+
print(wk2.userprops['data']['age'])

0 commit comments

Comments
 (0)