找回密码
 加入
搜索
查看: 4386|回复: 9

[AU3基础] [已解决]麻烦高手给个如何读取当前正在打开的excel文件的方法

[复制链接]
发表于 2008-7-5 16:04:31 | 显示全部楼层 |阅读模式
本帖最后由 silvay22 于 2013-4-25 19:50 编辑

如题:读取当前excel中4行3列的值
发表于 2008-7-5 18:48:51 | 显示全部楼层
不知道为何你要读取EXCEL,读ini不行吗?
 楼主| 发表于 2008-7-5 19:36:47 | 显示全部楼层

我晕!

读ini我也会,问题就是要用到excel才这样提问的。
发表于 2008-7-5 20:33:49 | 显示全部楼层
可能要用到建立对象来解决。
发表于 2008-7-5 20:39:10 | 显示全部楼层
$FilePath=@TempDir & "\temp.xls"
$oExcel=_ExcelBookOpen($FilePath)
$sReadCell = _ExcelReadCell($oExcel, "C4")
MsgBox(0, "Cell C4", $sReadCell)
_ExcelBookClose($oExcel)


Func _ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1)
        If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
        If NOT StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then
                If $sRangeOrRow < 1 Then Return SetError(2, 0, 0)
                If $iColumn < 1 Then Return SetError(2, 1, 0)
                Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value
        Else
                Return $oExcel.Activesheet.Range($sRangeOrRow).Value
        EndIf
EndFunc        ;==>_ExcelReadCell

Func _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False, $sPassword = "", $sWritePassword = "")
        Local $oExcel = ObjCreate("Excel.Application")
        If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
        If NOT FileExists($sFilePath) Then Return SetError(2, 0, 0)
        If $fVisible > 1 Then $fVisible = 1
        If $fVisible < 0 Then $fVisible = 0
        If $fReadOnly > 1 Then $fReadOnly = 1
        If $fReadOnly < 0 Then $fReadOnly = 0
        With $oExcel
                .Visible = $fVisible
                If $sPassword <> "" And $sWritePassword <> "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, $sPassword, $sWritePassword)
                If $sPassword = "" And $sWritePassword <> "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, Default, $sWritePassword)
                If $sPassword <> "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, $sPassword, Default)
                If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)
                .ActiveWorkbook.Sheets(1).Select()
        EndWith
        Return $oExcel
EndFunc ;==>_ExcelBookOpen

Func _ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)
        If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
        If $fSave > 1 Then $fSave = 1
        If $fSave < 0 Then $fSave = 0
        If $fAlerts > 1 Then $fAlerts = 1
        If $fAlerts < 0 Then $fAlerts = 0
        $oExcel.Application.DisplayAlerts = $fAlerts
        $oExcel.Application.ScreenUpdating = $fAlerts
        If $fSave Then
                $oExcel.ActiveWorkBook.Save
        EndIf
        $oExcel.Application.DisplayAlerts = True
        $oExcel.Application.ScreenUpdating = True
        $oExcel.Quit
        Return 1
EndFunc ;==>_ExcelBookClose
发表于 2008-7-6 03:23:35 | 显示全部楼层
原帖由 xwjsyyx 于 2008-7-5 20:39 发表
$FilePath=@TempDir & "\temp.xls"
$oExcel=_ExcelBookOpen($FilePath)
$sReadCell = _ExcelReadCell($oExcel, "C4")
MsgBox(0, "Cell C4", $sReadCell)
_ExcelBookClose($oExcel)


Func _ExcelReadCell($oE ...

强。 直接把库文件给贴出来了
发表于 2009-4-29 15:55:54 | 显示全部楼层
高人强啊~~~~
发表于 2009-7-23 16:07:54 | 显示全部楼层
同问
发表于 2009-7-24 10:48:22 | 显示全部楼层
有没有直接读取DBF的UDF呢?
发表于 2009-7-24 13:58:53 | 显示全部楼层
有没有直接读取DBF的UDF呢?
menfan 发表于 2009-7-24 10:48


http://www.autoitx.com/forum.php?mod=viewthread&tid=2943&page=1

比较难啊。。。au3支持不好
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-13 16:36 , Processed in 0.078733 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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