gpt4 book ai didi

excel - ALV网格只加载前64行,如何更改默认加载

转载 作者:行者123 更新时间:2023-12-03 03:14:09 25 4
gpt4 key购买 nike

情况

我已经为 SAP GUI 脚本创建了查找功能。
如果网格行在特定列中具有特定值,则双击它(这会触发加载特定的相关数据)。
我的网格少于 300 行,因此加载如此多的数据不会给现代计算机带来压力。

问题

我遇到的问题是,从 SAPGrid Row 64 中,它为每个单元格返回“”。如果我进入调试并在 ALV 网格中向下滚动,则网格行会加载并找到结果。

可能的解决方案

我可以更改默认加载的行数吗?
有没有一种方法可以提取完整的记录集?
替代选项包括使用脚本上下滚动或设置过滤器。

代码

Sub FindGridLine(SAPGrid As Object, criteria() As String)
SAPGrid.ClearSelection 'first it deselects what has been selected

For k = 0 To (SAPGrid.RowCount - 1) 'for each grid row
For i = 1 To UBound(criteria, 1) ' for each criteria row except for the first (should be only 1)
For j = LBound(criteria, 2) To UBound(criteria, 2) 'and for each column
tempstr = SAPGrid.GetCellValue(k, criteria(0, j))
If tempstr <> criteria(i, j) Then 'if the criterion doesn't match
GoTo nextrow 'then go to the next row
End If
Next j
Next i
'if it passed the criteria then doubleclick it
SAPGrid.DoubleClick k, criteria(0, 0)
Exit Sub
nextrow:
Next k
'in case no results were found
MsgBox "No line was found in grid!"
End Sub

更新了代码

根据@Asger 的正确答案更新代码。
由于查找主要使用主键,因此我选择了 SAPGrid.GetCellValue(k, criteria(0, j)) = "" 的安全解决方案。但解决方案实际上是 SAPGrid.SetCurrentCell k, criteria(0, j) .

Sub FindGridLine(SAPGrid As Object, criteria() As String)
' SAPGrid.SelectAll 'first it selects everything as to load the full grid
SAPGrid.ClearSelection 'first it deselects what has been selected

For k = 0 To (SAPGrid.RowCount - 1) 'for each grid row
For i = 1 To UBound(criteria, 1) ' for each criteria row except for the first (should be only 1)
For j = LBound(criteria, 2) To UBound(criteria, 2) 'and for each column
tempstr = SAPGrid.GetCellValue(k, criteria(0, j))
If tempstr = "" Then SAPGrid.SetCurrentCell k, criteria(0, j) 'this solution only works if the search is done in a non-empty field
tempstr = SAPGrid.GetCellValue(k, criteria(0, j))
If tempstr <> criteria(i, j) Then 'if the criterion doesn't match
GoTo nextrow 'then go to the next row
End If
Next j
Next i
'if it passed the criteria then doubleclick it
SAPGrid.DoubleClick k, criteria(0, 0)
Exit Sub
nextrow:
Next k
'in case no results were found
For i = 0 To UBound(criteria, 1) ' for each criteria row except for the first (should be only 1)
For j = LBound(criteria, 2) To UBound(criteria, 2) 'and for each column
tempstr = tempstr & "|" & criteria(i, j)
Next j
If i <> UBound(criteria, 1) Then
tempstr = tempstr & vbNewLine
End If
Next i
MsgBox "No line was found in grid!" & vbNewLine & "Please select line" & tempstr & vbNewLine & "manually and press 'OK'" & vbNewLine & "or enter debug mode."
End Sub

最佳答案

GuiGridView/ALV 网格控件:对于大量数据,只有在滚动后才会重新加载内容,否则很可能只返回一个空字符串作为结果 - 即使不会引发异常。

因此,应始终使用SetCurrentCell来聚焦和加载要读取的数据集。

请测试 e。 G。 SAPGrid.SetCurrentCell(k, 1)

也许加载每一个新的 64 行就足够了(我无法测试它):

If k Mod 64 = 63 Then ' at least if 1 row before each 64 rows
SAPGrid.SetCurrentCell (k, criteria(0, LBound(criteria, 2)))
End If

关于excel - ALV网格只加载前64行,如何更改默认加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54709653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com