如何在 C# 中在 SAP GUIContainerShell 上设置当前单元格?



我目前正在使用 SAP GUI 脚本自动化我的工作,在尝试重新创建录制的宏时,我在某个特定点遇到了一个我不知道如何翻译的问题。

session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").setCurrentCell 1,"MAKTX2"
session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").doubleClickCurrentCell
session.findById("wnd[1]/tbar[0]/btn[0]").press

我已经通读了SAP GUI Scripting API pdf,并且正在努力了解如何操作.setCurrentCell 1,"MAKTX2"部分。我正在通过以下方式访问容器单元:

GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

如何使"材料"双击"MAKTX2"?

编辑:完整的SAP GUI脚本:

SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper();
object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);
GuiApplication GuiApp = (GuiApplication)engine;
GuiConnection connection = (GuiConnection)GuiApp.Connections.ElementAt(0);
GuiSession session = (GuiSession)connection.Children.ElementAt(0);
GuiFrameWindow frame = (GuiFrameWindow)session.FindById("wnd[0]");
GuiTextField jobsite = (GuiTextField)session.FindById("wnd[0]/usr/subSA_0100_1:SAPMZCX_CSDSLSBM5001_OFS_OTS:2410/subSA_2410_1:SAPMZCX_CSDSLSBM5001_OFS_OTS:2510/ctxtKUWEV-KUNNR");
jobsite.Text = "I033";
frame.SendVKey(0);
GuiLabel aggregates = (GuiLabel)session.FindById("wnd[1]/usr/lbl[12,3]");
aggregates.SetFocus();
GuiFrameWindow frame2 = (GuiFrameWindow)session.FindById("wnd[1]");
frame2.SendVKey(1);
GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

老实说,我无法帮助您使用 C#,但也许 SAP 接口无论如何都足够通用。问题是,session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell")给你一个对GuiShell或GuiContainerShell类型的对象的引用,或者它叫什么。在此引用中,可以调用为此类型定义的方法。所以以同样的方式,当你这样做时

session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").setCurrentCell 1,"MAKTX2"

您只是先获取引用,然后setCurrentCell应用方法,所有这些都在同一行上。

当你在 C# 中这样做时

GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

你给这个引用起了一个名字materials,如果该行正常工作,我想你现在可以说:

materials.setCurrentCell(1, "MAKTX2")
materials.doubleClickCurrentCell

最新更新