问题
I need to read a specific column value of the last row of the below Variant table in SAP. When I record the script to navigate through the rows of the table, I get below lines. I need to extract specific cell value. Manually, I can copy and paste the content of the row to note pad. But, I am unable to figure out how to read the content of the specific column or entire row.
I have been trying different ways:
session.findById("wnd[0]/usr/subTABSTRIP:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB06/" _
& "ssubSUBSC:SAPLATAB:0201/subAREA1:SAPLAIA1:0304/subSUB:SAPLAIA1:0308/" _
& "subTREE:SAPLAIA1:0306/cntlVARI_CANVAS/shell").selectedNode = "0001"
session.findById("wnd[0]/usr/subTABSTRIP:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB06/" _
& "ssubSUBSC:SAPLATAB:0201/subAREA1:SAPLAIA1:0304/subSUB:SAPLAIA1:0308/" _
& "subTREE:SAPLAIA1:0306/cntlVARI_CANVAS/shell").selectedNode = "0002"
These are the lines generated when I move down the row using down arrow key. But how can I get the content of the row?
回答1:
This is a GuiTree object, and more specifically one of type "Column Tree".
In your case, that will be:
set tree = session.findById("wnd[0]/usr/subTABSTRIP:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB06/" _
& "ssubSUBSC:SAPLATAB:0201/subAREA1:SAPLAIA1:0304/subSUB:SAPLAIA1:0308/" _
& "subTREE:SAPLAIA1:0306/cntlVARI_CANVAS/shell")
The property SelectedNode
gives a String which is the key of the node currently selected ("node" is for a line of the tree):
nodeKey = tree.SelectedNode
From there, you may access the node text with the method GetNodeText
:
nodeText = tree.GetNodeText( nodekey )
The text of a cell is obtained with the method GetItemText
("item" being a cell at the intersection of a row and a column of the tree, excluding the left column containing the hierarchy):
itemText = tree.GetItemText( nodeKey, columnName )`
The column names are obtained with the method GetColumnNames
:
set columnNames = tree.GetColumnNames()`
The column names being a GuiComponentCollection object, you loop at its elements as follows:
for i = 0 to columnNames.Length - 1
colunmName = columnNames.ElementAt(i)
next
来源:https://stackoverflow.com/questions/59820810/how-to-read-row-details-of-a-guitree-control-using-gui-script