Func _ReadXls_New($sFile, $sSheet = 1, $sRows= "", $sColumn = "", $eRows = "", $eColumn = "")
Local $Tablecount
Local $Tablearray[1]
$Conn = ObjCreate("ADODB.Connection")
$Cmd = ObjCreate("ADODB.Command")
$Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & $sFile & ";Extended Properties=" & '"Excel 8.0;HDR=No;IMEX=1"')
$Cmd.LockType = 3
$Cmd.CursorType = 2
$Cmd.ActiveConnection = $Conn
$Rs=$Conn.OpenSchema(20)
While Not $Rs.Eof And Not $Rs.Bof
If $Rs("TABLE_TYPE").Value = "TABLE" And Not StringRegExp($Rs("TABLE_NAME").Value, "\$_") And Not StringRegExp($Rs("TABLE_NAME").Value, "Print_Area") Then
ReDim $Tablearray[$Tablecount + 1]
$Tablearray[$Tablecount] = $Rs("TABLE_NAME").Value
$Tablecount += 1
EndIf
$Rs.MoveNext
Wend
If IsNumber($sSheet) Then
If $sSheet = 0 Or $sSheet > UBound($Tablearray) Then Return @error
$sSheet = $Tablearray[$sSheet - 1]
Else
$sSheet &= "$"
$Sheetsearch = _ArraySearch($Tablearray, $sSheet)
If @error Then Return @error
;~ If $iCount <> "" Then
EndIf
$Cmd.CommandText = "SELECT * FROM [" & $sSheet & "]"
$RsArray = $Cmd.Execute
$RsArray = $RsArray.GetRows()
_ArrayDisplay($RsArray)
$Cmd.close
$Conn.Close
Return $RsArray
EndFunc ;==>_ReadXls
这是修改好的代码,不过还有点问题,就是Excel的排序方式和我们看见的排序方式不一样。
例如我有三个表,一个叫sheet1,一个叫2012,,还有一个叫我的Excel表,三者在Excel打开时看到的顺序为Sheet1,2012,我的Excel表,但是通过Ado形式读取时顺序为2012,Sheet1,我的Excel表。 |