自己动手用autoit实现用友NC凭证查询和下载的RPA机器人

类似效果实例

#include “Swing.au3”

#include

#include

shellexecute(“C:UsersAdminAppDataLocalUClientapps121c9f01-b00e-366b-ae6b-52e4cdd0d056Launcher.exe”, “121c9f01-b00e-366b-ae6b-52e4cdd0d056”)

Sleep(5000)

Opt(“MouseCoordMode”, 0)

Opt(“SendKeyDelay”, 20)

global $wintitle = “Yonyou NC – nc65:8080”

$winHandle = WinActivate($wintitle)

WinSetState($wintitle, “”, @SW_MAXIMIZE)

$result = __isJavaWindow($winHandle)

Global $vmId

Global $ac

global $sName = “用户”

global $sRole = “label”

__getAccessibleContextFromHWND($winHandle, $vmID, $ac)

Sleep(500)

$re_ac = _JAB_getAccessibleContextByFindAll($vmId, $ac, $sName, $sRole)

_JAB_getIndexInParent($vmId, $re_ac)

$indexObject = __getAccessibleParentFromContext($vmId, $re_ac)

$username = __getAccessibleChildFromContext($vmId, $indexObject, 3)

$passwd = __getAccessibleChildFromContext($vmId, $indexObject, 5)

$loginBtn = __getAccessibleChildFromContext($vmId, $indexObject, 7)

__setTextContents($vmId, $username, “slwql”)

__setTextContents($vmId, $passwd, “@365”)

_JAB_singleAction($vmId, $loginBtn)

Sleep(600)

If WinExists(“提示”) Then

$hWnd=WinGetHandle(“[ACTIVE]”);

$ret=DllCall(“user32.dll”,”long”,”LoadKeyboardLayout”,”str”,”08040804″,”int”,1+0);

DllCall(“user32.dll”,”ptr”,”SendMessage”,”hwnd”,$hWnd,”int”,0x50,”int”,1,”int”,$ret[0]);

Sleep(400)

WinActivate(“提示”)

Sleep(400)

Send(“{Y}”)

Sleep(400)

EndIf

Sleep(200)

$function_ac = _JAB_getAccessibleContextByFindAll($vmId, $ac, “财务会计”, “page tab”)

Sleep(200)

Send(“{DOWN 5}”)

Sleep(200)

$base_ac = _JAB_getAccessibleContextByFindAll($vmId, $ac, “基础档案及规则”, “label”)

Sleep(200)

$indexList = __getAccessibleParentFromContext($vmId, $base_ac)

Sleep(200)

$clickLabel = __getAccessibleChildFromContext($vmId, $indexList, 1)

Sleep(200)

_JAB_singleAction($vmId, $clickLabel)

Sleep(300)

$infoX = _JAB_getX($vmId, $clickLabel)

$infoY = _JAB_getY($vmId, $clickLabel)

Sleep(20)

$posx = $infoX + 280

Sleep(20)

$posy = $infoY + 20

Sleep(20)

MouseClick(“left”,$posx,$posy,1)

Sleep(200)

Send(“{DOWN 10}”)

Sleep(200)

Send(“{ENTER}”)

Sleep(100)

$searchBtn = _JAB_getAccessibleContextByFindAll($vmId, $ac, “查询”, “push button”)

Sleep(100)

Send(“{F3}”)

Sleep(600)

If WinExists(“凭证查询”) Then

$searchDialog = WinActivate(“凭证查询”)

Sleep(200)

$result = __isJavaWindow($searchDialog)

__getAccessibleContextFromHWND($searchDialog, $vmId, $ac)

Sleep(100)

$accountLabel = _JAB_getAccessibleContextByFindAll($vmId, $ac, “核算账簿”, “label”)

Sleep(40)

$accoutBtn = _JAB_getNextSibling($vmId, $accountLabel, 1)

Sleep(40)

$btn = __getAccessibleChildFromContext($vmId, $accoutBtn, 1)

Sleep(40)

_JAB_singleAction($vmId, $btn)

Sleep(100)

Send(“{DOWN 2}”)

Sleep(40)

Send(“{RIGHT}”)

Sleep(40)

Send(“{DOWN}”)

Sleep(40)

Send(“{ENTER}”)

Sleep(40)

$confirmBtn = _JAB_getAccessibleContextByFindAll($vmId, $ac, “确定”, “push button”)

Sleep(40)

_JAB_singleAction($vmId, $confirmBtn)

Sleep(600)

WinFlash(“凭证查询”)

EndIf

Sleep(100)

Send(“{TAB 2}”)

Sleep(100)

$result = __isJavaWindow($winHandle)

Sleep(40)

__getAccessibleContextFromHWND($winHandle, $vmId, $ac)

Sleep(40)

$page_tab = _JAB_getAccessibleContextByFindAll($vmId, $ac, “查询”, “page tab”)

Sleep(40)

$table_header = _JAB_getAccessibleContextByFindAll($vmId, $page_tab, “出纳”, “label”)

Sleep(40)

$table = _JAB_getTableFromColumn($vmId, $table_header)

Sleep(40)

$count = _JAB_getTableRowCount($vmId, $table)

Sleep(300)

Send(“{DOWN 20}”)

Sleep(200)

$cardBtn = _JAB_getAccessibleContextByFindAll($vmId, $page_tab, “卡片显示”, “push button”)

Sleep(200)

_JAB_singleAction($vmId, $cardBtn)

Sleep(400)

Send(“{TAB 1}”)

Sleep(400)

$backBtn = _JAB_getAccessibleContextByFindAll($vmId, $page_tab, “返回”, “push button”)

Sleep(400)

MouseMove(16, 249, 10)

Sleep(40)

__getAccessibleContextWithFocus($winHandle, $vmId, $ac)

Sleep(40)

$iTableHeadCount = _JAB_getTableColumnCount($vmId, $ac)

$iTableRowCount = _JAB_getTableRowCount($vmId, $ac)

Sleep(400)

Local $oExcel = _Excel_Open()

Local $sFilePath = “D:est.xls”

Local $oWorkbook = _Excel_BookOpen($oExcel, $sFilePath)

Local $oSheet = $oWorkbook.Sheets(1)

Sleep(400)

;Local $tableHeads[12] = [“分录号”, “摘要”, “科目”, “辅助核算”, “币种”, “原币”, “组织本币借方)”, “组织本币(贷方)”, “集团本币(借方)”, “集团本币(贷方)”, “全局本币(借方)”, “全局本币(贷方)”]

;$file = FileOpen(“C:data.txt”, 1)

For $i = 0 To $iTableRowCount – 1

Local $tableData[12]

For $j = 0 To $iTableHeadCount – 1

Local $tableCell = _JAB_getTableCellTextValue($vmId, $ac, $i, $j)

Local $cellValue = StringRegExpReplace($tableCell, ”, ”)

Sleep(20)

;_ArrayAdd($tableData, $tableCell)

$oSheet.Range(“A2”).Offset($i, $j).Value = $cellValue

$oSheet.Range(“A:L”).Columns.AutoFit

;FileWriteL ine($file, $tableHeads[$j] &@TAB &”:” & $tableCell & @CRLF)

;If $j = 11 Then

; FileWriteLine($file, $tableCell & @CRLF & “===================================================================”)

;EndIf

Next

Next

Sleep(400)

_Excel_BookSave($oWorkbook)

Sleep(400)

_Excel_BookClose($oWorkbook)

_Excel_Close($oExcel)

;FileClose($file)

Sleep(400)

WinClose($wintitle)

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
上一篇 2022年6月12日 14:30
下一篇 2022年6月12日 14:31

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息