半肾
精华
|
战斗力 鹅
|
回帖 0
注册时间 2017-1-23
|
本帖最后由 spikedingo 于 2019-2-11 17:01 编辑
用autoit获取两个excel文件的句柄就可以随意操作了
用stringInStr('B单元格内容', 'B单元格内容中与A相同的部分')函数来确定某一行为对应A内的数据
简单写一下
- #include <Excel.au3>
- #include <Constants.au3>
- Opt('MouseCoordMode', 2)
- AutoItSetOption("SendKeyDelay", 100)
- ; 链接到已打开的excel工作表
- Local $excelA = _ExcelBookAttach("A.xlsx" ,"FileName")
- Local $excelB = _ExcelBookAttach("B.xlsx" ,"FileName")
- ; 弹框请求起始循环的行数
- Dim $readLine = 1
- Dim $readLineB = 1
- ; Dim $i = 102
- ; While语句,A表b列没有数据时,则需要从B表取数据
- While _ExcelReadCell($excelA,"b"&$readLine) = ""
- ; 取得A表a列值用于判断
- Local $sCheck = _ExcelReadCell($excel,"a"&$readLine)
- $readLineB = 1
- ; B表a列有数据时,进行读取,否则就不再遍历
- While _ExcelReadCell($excelB,"a"&$readLineB) <> ""
- Local $sStr = _ExcelReadCell($excelB,"a"&$readLineB)
- ; B表a列的值包含之前存的A表a列标题,则取B表b列的值去粘贴到A表
- If StringInStr($sStr, $sCheck) Then
- Local $Value = _ExcelReadCell($excelB,"b"&$readLineB)
- ; 粘贴A表并跳出while
- _ExcelWriteCell($excelA, $Value, "b"&$readLine)
- ExitLoop
- EndIf
- $readLineB +=1
- WEnd
- ; 给A表检查完毕栏做个记号
- _ExcelWriteCell($excelA, 'done', "c"&$readLine)
- $readLine += 1
- WEnd
复制代码 |
|