某些神奇的单位用word做报销单,不点名.word的自动化难度比excel大的多,并且在word里面用表格更是恶心.简单做了一个有局限性的制作报销单的脚本.
实际效果视频,哦我发不了视频哈哈哈
将就看一下源码吧
objExcel:=Excel_Get()
objExcel.Cells(2,1).Activate
loop
{
;建立;excel对象
objExcel:=Excel_Get()
y:=objExcel.ActiveCell.Row
x:=objExcel.ActiveCell.Column
arr:=[]
Loop, % x-1
arr.Push( objExcel.Cells(y,A_Index).Text )
if (objExcel.Cells(y,1).Value="")
break
用途:=objExcel.Cells(y,1).Text
金额:=objExcel.Cells(y,2).Text
run "C:\Users\YZ\Desktop\MyCodeProject\Project\报销项目\墨华报销单模板.doc"
Sleep 2000
WinActivate ahk_exe WINWORD.EXE
SendInput,^{End}
WinActivate ahk_exe WINWORD.EXE
;点击日期旁边
ClickPosition(906,601, 1, 0, "Window", true)
Sleep 100
SendInput,% A_YYYY "年" A_MM "月" A_DD "日"
Sleep 100
;点击用途
WinActivate ahk_exe WINWORD.EXE
ClickPosition(805,722, 1, 0, "Window", true)
SendInput,% 用途
; Sleep 300
; SendInput,{Tab 2}
; Sleep 200
a:=金额
b:=RegExReplace(a,"[\.]")
粘贴次数:=StrLen(b)
if (InStr(a, ".")<>0) ? 位数:=InStr(a, ".")-1
:位数:=StrLen(a)
次数:=4+3-位数
SendInput,{tab %次数%}
;加一个符号
Sleep 100
Send,¥
Sleep 100
Send {Tab}
loop
{
if (A_Index=粘贴次数+1)
break
Clipboard:=SubStr(b,A_Index,1)
ClipWait
if WinExist("ahk_exe WINWORD.EXE")
WinActivate
else
MsgBox 报错
Sleep 500
SendInput,^v
Sleep 400
SendInput,{Tab}
}
if (InStr(a, "."))
send,0
else
{
send,0
Sleep 100
send,{Tab}
send,0
}
;点击大写金额
Sleep 200
ClickPosition(724,891, 1, 0, "Window", true)
send,V
Sleep 200
send,% a
send,b
Sleep 1000
send,% InStr(a, ".") ? "整" : "元整"
;send,% RegExMatch(a,"\.") ? "元整" : "整"
Sleep 1000
ow:= ComObjActive("Word.Application")
ow.ActiveDocument.SaveAs2("C:\2.23\%用途%.doc")
ow.ActiveDocument.Close
objExcel.Cells(y+1,1).Activate
}
return
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。