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

How to set current cell on SAP GUIContainerShell in C#?

我目前正在使用 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 脚本 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