TC官方合作论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: cylhb

[源码分享] 纯TC打开,读写EXCEL源码

  [复制链接]
发表于 2013-10-30 17:10:16 | 显示全部楼层
这段代码一运行就会报错,不信你试试!还是按键精灵好,不会报错
回复 支持 反对

使用道具 举报

发表于 2013-10-30 17:12:00 | 显示全部楼层
Sub ShutdownExcel
    VBSBegin
        Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set List = obj.ExecQuery ("Select * from Win32_Process Where Name = 'EXCEL.EXE'")
        For Each objProcess in List
            objProcess.Terminate()
        Next
    VBSEnd
End Sub
Sub OnScriptExit()
    ShutdownExcel
End Sub
ShutdownExcel

sIniFile="C:\Users\Administrator\Desktop\Book1.ini"
UserVar iDelay=DropList{"0.5秒":"500"|"1秒":"1000"|"1.5秒":"1500"|"2秒":"2000"|"3秒":"3000"|"5秒":"5000"}=1000 "设置延时"
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = true
Set xlBook = xlApp.Workbooks.Open("C:\Users\Administrator\Desktop\Book1.xls")
Set xlSheet = xlBook.sheets("Sheet1")
nEndLine = xlsheet.UsedRange.SpecialCells(11).Row
nStartLine = InputBox("请输入起始行号:","" , 2)
nEndLine = InputBox("请输入结束行号:", "", xlSheet.UsedRange.SpecialCells(11).Row)
xlApp.Visible = False
Delay 1000
For i = nStartLine To nEndLine
    未发现运行环境,请安装微软拼音2.0以上版本!= xlsheet.Range("A" & i).Value
    未发现运行环境,请安装微软拼音2.0以上版本!= xlsheet.Range("B" & i).Value
    flag = xlsheet.Range("C" & i).Value
        
    If flag <> "ok" Then
        Call Plugin.Msg.ShowScrTXT(0, 0, 1024, 768, "第" & i & "行正在处理。", "0000FF")
        DoSomeWorks
        Call Plugin.Msg.ShowScrTXT(0, 0, 1024, 768, "第" & i & "行已处理。", "0000FF")
        xlsheet.Range("C" & i).Value = "ok"
        xlsheet.Range("D" & i).Value = now
        xlBook.Save
    End If
Next

xlApp.Quit
ExitScript

Sub DoSomeWorks
    If GetPoint("ssd",sIniFile) Then
        LockMouse
        //输入位置 [ssd] 的操作
        LeftClick 1
       Delay 200
        SayString 未发现运行环境,请安装微软拼音2.0以上版本!
        UnlockMouse
        Delay iDelay
    End If
    If GetPoint("fdfg",sIniFile) Then
        LockMouse
        //输入位置 [fdfg] 的操作
        LeftClick 1
       Delay 200
        SayString 未发现运行环境,请安装微软拼音2.0以上版本!
        UnlockMouse
        Delay iDelay
    End If
End Sub
Function GetPoint(sPointName,sIniFile)
    GetPoint =false
    sRegion=Plugin.File.ReadINI(sPointName, "点位置", sIniFile)
    If sRegion="" then
        MsgBox "设置""" & sPointName & """点位置", vbInformation Or vbSystemModal, "提示"
        Delay 500
        sTemp = Plugin.QM_GetPoint.GetPoint()
        sRegion = sTemp  
        Plugin.File.WriteINI sPointName, "点位置", sTemp, sIniFile  
        sArrayRegion = Split(sTemp, "|")
        Plugin.File.WriteINI sPointName, "RegionX", sArrayRegion(0), sIniFile
        Plugin.File.WriteINI sPointName, "RegionY", sArrayRegion(1), sIniFile   
    End if
    If sRegion<>"" then
        x=Cint(Plugin.File.ReadINI(sPointName, "RegionX", sIniFile))
        y=Cint(Plugin.File.ReadINI(sPointName, "RegionY", sIniFile))  
        MoveTo x,y
        Delay 100
        GetPoint=true
    Else
        MsgBox "没有设置要找的""" &sPointName & """点位置"
    End if
End Function
Function WaitMyPic(sPicName,sIniFile,nDelay)
    WaitMyPic=true
    wait=0
    Do While Not FindMyPic(sPicName, sIniFile )
        Wait = Wait + 1
        If Wait > 20 Then
            WaitMyPic=False
            Exit Do
        End If
        Delay nDelay
    Loop
End Function
Function FindMyPic(sPicName, sIniFile)
    FindMyPic = False
    sPic = Plugin.File.ReadINI(sPicName, "图片", sIniFile)
    If sPic = "" Then
        MsgBox "设置""" & sPicName & """图片", vbInformation Or vbSystemModal, "提示"
        Delay 500
        sPic = Plugin.QM_SetFindPic.GetFindPic()
        If sPic <> "" Then
            Plugin.File.WriteINI sPicName, "图片", sPic, sIniFile
            '//图片尺寸
            Delay 500
            sTemp = Plugin.QM_SetFindPic.GetPicSize(sPic)
            sArraySize = Split(sTemp, "|")
            Plugin.File.WriteINI sPicName, "PicWidth", sArraySize(0), sIniFile
            Plugin.File.WriteINI sPicName, "PicHeight", sArraySize(1), sIniFile
            Plugin.File.WriteINI sPicName, "RegionX1", "0", sIniFile
            Plugin.File.WriteINI sPicName, "RegionY1", "0", sIniFile
            Plugin.File.WriteINI sPicName, "RegionX2","0", sIniFile
            Plugin.File.WriteINI sPicName, "RegionY2", "0", sIniFile
        End If
    End If
          If sPic <> "" Then
        x1 = CInt(Plugin.File.ReadINI(sPicName, "RegionX1", sIniFile))
        y1 = CInt(Plugin.File.ReadINI(sPicName, "RegionY1", sIniFile))
        x2 = CInt(Plugin.File.ReadINI(sPicName, "RegionX2", sIniFile))
        y2 = CInt(Plugin.File.ReadINI(sPicName, "RegionY2", sIniFile))
        If x1 = x2 and y1 = y1 Then
            MsgBox "设置""" & sPicName & """图片查找区域", vbInformation Or vbSystemModal, "提示"
            '//查找图片的区域
            Delay 500
            sTemp = Plugin.QM_SetFindPic.GetFindRegion()
            If sTemp <> "" Then
                sArrayRegion = Split(sTemp, "|")
                Plugin.File.WriteINI sPicName, "RegionX1", sArrayRegion(0), sIniFile
                Plugin.File.WriteINI sPicName, "RegionY1", sArrayRegion(1), sIniFile
                Plugin.File.WriteINI sPicName, "RegionX2", sArrayRegion(2), sIniFile
                Plugin.File.WriteINI sPicName, "RegionY2", sArrayRegion(3), sIniFile
                x1 = CInt(sArrayRegion(0))
                y1 = CInt(sArrayRegion(1))
                x2 = CInt(sArrayRegion(2))
                y2 = CInt(sArrayRegion(3))
            End If
        End If
        If x1 <> x2 OR y1 <> y2 Then
            Width = CInt(Plugin.File.ReadINI(sPicName, "PicWidth", sIniFile))
            Height = CInt(Plugin.File.ReadINI(sPicName, "Picheight", sIniFile))
            FindPic x1, y1, x2, y2, sPic, 0.9, intX, intY
            If intX > 0 And intY > 0 Then
                MoveTo intX + Width / 2, intY + Height / 2
                Delay 500
                FindMyPic = True
            End If
        Else
            MsgBox "没有设置图片的查找区域", vbInformation Or vbSystemModal, "提示"
        End If
    Else
        MsgBox "没有设置要找的""" & sPicName & """图片", vbInformation Or vbSystemModal, "提示"
    End If
End Function
回复 支持 反对

使用道具 举报

发表于 2013-11-7 10:52:32 | 显示全部楼层
楼上是按键精灵吧?我强烈要求版主开一个办公交流版块。我们搞办公的用TC确实太缺少资源了。
回复 支持 1 反对 0

使用道具 举报

发表于 2013-11-12 16:20:27 | 显示全部楼层
真的是不行,一运行就出错,TC功能好多出错啊
回复 支持 反对

使用道具 举报

发表于 2013-11-12 16:36:48 | 显示全部楼层
我发现即使是简单的功能,TC都有可能出错,按键很少,这方面来讲,TC要加油啊
回复 支持 反对

使用道具 举报

发表于 2014-4-25 00:12:14 | 显示全部楼层
本帖最后由 moist26 于 2014-4-25 00:22 编辑

有报错哦:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

发表于 2014-7-6 13:40:59 | 显示全部楼层
老大!
    xApp=com("Excel.Application")
    xBook=com("Excel.Workbook")
    xSheet=com("Excel.Worksheet")
    xBook=xApp.Workbooks.open("E:\\材料库.xlsx")
    xSheet=xApp.Worksheets(“蓝色”)
脚本第四行错误。。说是 xApp.Workbooks 不是合法的变量名或者是没有定义 怎么破啊!
回复 支持 反对

使用道具 举报

发表于 2014-8-9 17:14:44 | 显示全部楼层
多谢分享,如果还多一点基础的介绍就好了
回复 支持 反对

使用道具 举报

发表于 2014-11-22 19:32:04 | 显示全部楼层
不能用哦

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

发表于 2014-11-23 00:27:30 | 显示全部楼层
很强大,谢谢分享~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条

关闭

小黑屋|TC官方合作论坛 (苏ICP备18045623号)

GMT+8, 2024-5-11 22:10 , Processed in 0.048192 second(s), 20 queries .

Powered by 海安简单软件服务部

© 2008-2019 版权所有 保留所有权利

快速回复 返回顶部 返回列表