File tree 1 file changed +17
-3
lines changed
1. Origin-Python Data Exchange
1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
'''
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
4
4
of a data file. See the blog:
5
5
https://blog.originlab.com/accessing-metadata-using-python
6
6
'''
13
13
wks .set_int ("tree.data.age" , 37 )
14
14
wks .set_float ("tree.data.mean" , 23.56 )
15
15
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
17
23
trWks = wks .usertree
18
24
trData = trWks .find ('data' )
19
25
for child in trData :
20
26
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' ])
You can’t perform that action at this time.
0 commit comments