0

我目前正在使用 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");
4

1 回答 1

2

老实说,我无法帮助您使用 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
于 2018-05-02T09:25:03.757 回答