本帖最后由 yurong 于 2016-12-4 20:00 编辑
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.2
Author: myName
Script Function:
Template AutoIt script.
1.保存两张图图片到桌面,分别命名1111.jpg和2222.jpg
2.Chrom浏览器设置勾选新的标签页
3.酷狗音乐播放器设置勾选关闭今日推荐
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <MsgBoxConstants.au3>
#include <Word.au3>
#include <String.au3>
#Include <EXCEL.au3>
#include <file.au3>
Local $a=0
While $a<1
Sleep(10000)
;音乐播放器
musicTest()
Sleep(3000)
WinMinimizeAll()
WinMinimizeAll()
Sleep(5000)
;Excel使用
excelTest()
Sleep(3000)
WinMinimizeAll()
Sleep(5000)
;ie浏览器
ieTest()
Sleep(3000)
WinMinimizeAll()
Sleep(5000)
;Word使用
wordTest2()
Sleep(3000)
WinMinimizeAll()
Sleep(5000)
;Excel使用
excelTest()
Sleep(3000)
WinMinimizeAll()
Sleep(5000)
;暂停音乐
stopmusicTest()
Sleep(2000)
WinMinimizeAll()
WinMinimizeAll()
Sleep(3000)
;Chrome使用
chromtest()
Sleep(50000)
WinMinimizeAll()
WEnd
Func musicTest()
Run("C:\Program Files\KuGou\KGMusic\KuGou.exe")
Sleep(3000)
Send("{SPACE}")
EndFunc
Func ieTest()
run('"C:\Program Files\Internet Explorer\iexplore.exe" http://www.baidu.com',"",@SW_MAXIMIZE)
$oIE = WinWait("[CLASS:IEFrame]","",90)
Sleep(3000)
Send("shaonianruntu{SPACE}{SPACE}")
Sleep(1000)
Send("{ENTER}")
MouseMove(1350,300,20)
Sleep(2000)
MouseClick("left")
MouseWheel("down", 60)
Sleep(2000)
MouseWheel("up", 10)
Sleep(2000)
MouseWheel("down", 60)
MouseWheel("up",50)
Sleep(2000)
WinClose("[CLASS:IEFrame]")
EndFunc
Func excelTest()
WinMinimizeAll()
;表格行数
Dim $row_n=100
Dim $password="123456"
;创建excel应用程序对象
$xls = ObjCreate("Excel.Application")
;显示
$xls.visible=1
;添加新工作簿
$obj_xls=$xls.Workbooks.Add
WinActivate($xls)
Sleep(3000)
;关闭激活窗口给
If WinExists("[CLASS:NUIDialog]") Then
Send("{c down}")
Send("{c up}")
EndIf
$xls.DisplayAlerts = False
;$obj_xls.Worksheets("Sheet3").Delete
;$oExcel.Worksheets("Sheet2").Delete
$xls.DisplayAlerts = True
;激活窗口
$obj_xls.Worksheets("Sheet1").Activate
$xls_sup=$obj_xls.WorkSheets(1)
$xls_sup.name="云办公自动化测试"
;设置垂直对齐方式为居中
$xls_sup.Cells.VerticalAlignment=-4108
;设置水平对齐方式为居中
$xls_sup.Cells.HorizontalAlignment=-4108
;合并单元格
$xls_sup.Range("A1:D1").merge(True)
$xls_sup.Cells(1, 1).Value ="自动化测试"
;设置第一行高度
$xls_sup.Rows(1).RowHeight =40
;设置字体
With $xls_sup.Range("A1:D1")
.font.size=16
.Range("A1:D1").font.bold=True
.Range("A1:D1").font.name="楷体_GB2312"
EndWith
;InchesToPoints函数,将英寸转为磅值。
$xls_sup.Columns(1).ColumnWidth=$obj_xls.Application.InchesToPoints(0.2)
$xls_sup.Columns(2).ColumnWidth=$obj_xls.Application.InchesToPoints(0.2)
$xls_sup.Columns(3).ColumnWidth=$obj_xls.Application.InchesToPoints(0.2)
$xls_sup.Columns(4).ColumnWidth=$obj_xls.Application.InchesToPoints(0.2)
$xls_sup.Rows(2).RowHeight =24
$xls_sup.Cells(2, 1).Value ="学生学号"
$xls_sup.Cells(2, 2).Value ="学生姓名"
$xls_sup.Cells(2, 3).Value ="学生成绩"
$xls_sup.Cells(2, 4).Value ="学生性别"
For $z=1 To $row_n
$xls_sup.Rows($z+2).RowHeight =24
$xls_sup.Rows($z+2).HorizontalAlignment=-4108
$xls_sup.Rows($z+2).VerticalAlignment=-4108
$xls_sup.Cells($z+2, 1).Value =$z
Sleep(1000)
$xls_sup.Cells($z+2, 2).Value =("张三")
Sleep(1000)
$xls_sup.Cells($z+2, 3).Value ="98"
Sleep(1000)
$xls_sup.Cells($z+2, 4).Value ="男"
Sleep(1000)
Next
$xls_sup.Range("A2:D"&($row_n+2)).Borders(11).LineStyle=1
$xls_sup.Range("A2:D"&($row_n+2)).Borders(12).LineStyle=1
$xls_sup.Range("A2:D"&($row_n+2)).Borders(7).LineStyle=1
$xls_sup.Range("A2:D"&($row_n+2)).Borders(7).Weight=3
$xls_sup.Range("A2:D"&($row_n+2)).Borders(8).LineStyle=1
$xls_sup.Range("A2:D"&($row_n+2)).Borders(8).Weight=3
$xls_sup.Range("A2:D"&($row_n+2)).Borders(9).LineStyle=1
$xls_sup.Range("A2:D"&($row_n+2)).Borders(9).Weight=3
$xls_sup.Range("A2:D"&($row_n+2)).Borders(10).LineStyle=1
$xls_sup.Range("A2:D"&($row_n+2)).Borders(10).Weight=3
;加入公式
;$xls_sup.Range("B3").Formula = "=B2"
$obj_xls.Windows(1).DisplayGridlines=False
$obj_xls.Windows(1).DisplayHeadings = False
$xls_sup.Range("A1:D"&($row_n+2)).Locked = True
$xls_sup.Protect($password)
$obj_xls.Protect($password, True)
$obj_xls.SaveAs(@DesktopDir & "\test.xls")
$obj_xls.Save
$xls.quit
Sleep(2000)
FileDelete("C:\Users\user\Desktop\test.xls")
EndFunc
Func chromtest()
Run("C:\Program Files\Google\Chrome\Application\chrome.exe", "", @SW_SHOWMAXIMIZED)
Local $oChrom=WinWait("[CLASS:Chrome_WidgetWin_1]", "", 10)
WinSetState($oChrom,"",@SW_SHOWMAXIMIZED)
Send("www.iqiyi.com")
Sleep(1000)
Send("{ENTER}")
Send("{ENTER}")
Sleep(1000)
Send("jinxiuweiyang{SPACE}")
Sleep(1000)
Send("{ENTER}")
WinClose("[CLASS:Chrome_WidgetWin_1]")
Run("C:\Program Files\Google\Chrome\Application\chrome.exe", "", @SW_SHOWMAXIMIZED)
Local $oChrom=WinWait("[CLASS:Chrome_WidgetWin_1]", "", 90)
WinSetState($oChrom,"",@SW_SHOWMAXIMIZED)
Send("http://www.iqiyi.com/v_19rr9convg.html#vfrm=2-3-0-1")
Sleep(1000)
Send("{ENTER}")
Send("{ENTER}")
ProcessClose($oChrom)
WinClose("[CLASS:Chrome_WidgetWin_1]")
EndFunc
Func stopmusicTest()
Run("C:\Program Files\KuGou\KGMusic\KuGou.exe")
Sleep(3000)
Send("{SPACE}")
WinClose("[CLASS:kugou_ui]")
EndFunc
Func wordTest2()
Local $word = ObjCreate("word.application")
$word.visible = True
Local $Document = $word.documents.add
WinActivate($Document.Name)
Sleep(5000)
If WinExists("[CLASS:NUIDialog]") Then
Send("{c down}")
Send("{c up}")
EndIf
$Document.tables.add($Document.range,20,2)
Local $i
With $Document.tables(1)
For $i = -6 To -1
$Document.tables(1).borders($i).linestyle=1;此处在循环多变之后会报错
_FileWriteLog("c/yr.log", $i+"=报错的次数,这个是数字", -1)
Sleep(1000)
Next
For $i = 1 To 20
_FileWriteLog("c/yr.log", $i+"=报错的次数,这个是图片", -1)
$Document.tables(1).cell($i,1).range.inlineshapes.addpicture(@DesktopDir&"\1111.jpg",false,true);此处在循环多变之后会报错
Sleep(2000)
$Document.tables(1).cell($i,2).range.inlineshapes.addpicture(@DesktopDir&"\2222.jpg",false,true)
Sleep(1000)
Next
EndWith
_Word_DocSaveAs($Document, @DesktopDir & "\_word_test2.doc")
;关闭word窗口
_Word_DocClose($Document)
WinClose("Microsoft Word","")
;删除word
FileDelete("C:\Users\user\Desktop\_word_test2.doc")
;循环时间间隔2s
Sleep(2000)
EndFunc |