本帖最后由 chzj589 于 2022-2-24 10:28 编辑
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
; 创建应用对象并打开示例工作簿
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead 示例", "创建 Excel 应用对象发生错误." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Sales.xls");$FExcel);
Local $iRowsA = $oWorkbook.ActiveSheet.UsedRange.Rows.Count; ‘当前工作表中已使用的行数
Local $iRowsB = $oWorkbook.ActiveSheet.UsedRange.Columns.Count ;‘当前工作表中已使用的列数
Local $iRo=$iRowsA;+2
Local $L1
Global $sText1 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH']
For $i = 0 To $iRowsB - 1
$L1 = $sText1[$i] ;& '|'
Next
;MsgBox($MB_SYSTEMMODAL, "", $L1)
If @error Then
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead 示例", "打开工作簿发生错误 '" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_Close($oExcel)
Exit
EndIf
; 读取指定工作簿的表 1的单元格公式
; *****************************************************************************
Local $aResult = _Excel_RangeRead($oWorkbook, Default, "A1:"& $L1 &$iRo, 1);&$DEFAULT &$iR, 1)&$iRowsAA
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead 示例 2", "读工作簿失败." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead 示例 2", "成功读取数据." & @CRLF & "点击 < 确定 > 按钮显示表 1 单元格 A1:"& $L1 & $iRo & @CRLF &"行数=" &$iRo& @CRLF &"列数=" &$iRowsB, 2)
_ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead 示例 2 - 表 1的单元格 A1:"& $L1 & $iRo)
$oWorkbook.Close
$oExcel.quit ;退出excel进程
|