Что нового

Не работают функции Excel после _ExcelBookAttach

vovsla

Осваивающий
Сообщения
607
Репутация
36
После прикрепления окна командой
Код:
$oExcel = _ExcelBookAttach('имя окна', 'Title')

работает функция _ExcelReadCell, функция_ExcelBookSaveAs не работает, выдает @error 4.
Но это просто пример того, что стандартная библиотечная функция не работает, по сути нужно чтобы работала вот эта функция
Код:
;~ -----------------------------------------------------------------------------_ExcelReadSheetToArrayQuick----------------------------------------------------------------------------
Func _ExcelReadSheetToArrayQuick($oExcel, $iStartRow = 1, $iStartColumn = 1, $iRowCnt = 0, $iColCnt = 0)
    Local $avRET[1][2] = [[0, 0]] ; 2D return array
    ; Test inputs
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $iStartRow < 1 Then Return SetError(2, 0, 0)
    If $iStartColumn < 1 Then Return SetError(2, 1, 0)
    If $iRowCnt < 0 Then Return SetError(3, 0, 0)
    If $iColCnt < 0 Then Return SetError(3, 1, 0)

    ; Get size of current sheet as R1C1 string
    ;     Note: $xlCellTypeLastCell and $x1R1C1 are constants declared in ExcelCOM_UDF.au3
    ;Local $sLastCell = $oExcel.Application.Selection.SpecialCells($xlCellTypeLastCell).Address(True, True, $xlR1C1)
    Local $sLastCell = $oExcel.Activesheet.Cells.SpecialCells($xlCellTypeLastCell).Address(True, True, $xlR1C1) ; изменено

    ; Extract integer last row and col
    $sLastCell = StringRegExp($sLastCell, "\A[^0-9]*(\d+)[^0-9]*(\d+)\Z", 3)
    Local $iLastRow = $sLastCell[0]
    Local $iLastColumn = $sLastCell[1]

    ; Return 0's if the sheet is blank
    If $sLastCell = "R1C1" And $oExcel.Activesheet.Cells($iLastRow, $iLastColumn).Value = "" Then Return $avRET

    ; Check input range is in bounds
    If $iStartRow > $iLastRow Then Return SetError(2, 0, 0)
    If $iStartColumn > $iLastColumn Then Return SetError(2, 1, 0)
    If $iStartRow + $iRowCnt - 1 > $iLastRow Then Return SetError(3, 0, 0)
    If $iStartColumn + $iColCnt - 1 > $iLastColumn Then Return SetError(3, 1, 0)

    ; Check for defaulted counts
    If $iRowCnt = 0 Then $iRowCnt = $iLastRow - $iStartRow + 1
    If $iColCnt = 0 Then $iColCnt = $iLastColumn - $iStartColumn + 1

    ; Size the return array
    ReDim $avRET[$iRowCnt][$iColCnt]
    ;$avRET[0][0] = $iRowCnt
    ;$avRET[0][1] = $iColCnt
    $avRET = $oExcel.Application.WorksheetFunction.Transpose($oExcel.Activesheet.Cells($iStartRow, $iStartColumn).Resize($iRowCnt, $iColCnt).Value)
    ;Return data
    Return $avRET
EndFunc   ;==>_ExcelReadSheetFromArrayQuick
 

InnI

AutoIT Гуру
Сообщения
4,922
Репутация
1,432
http://autoit-script.ru/index.php?topic=15863.msg98461#msg98461
 
Верх