Sign in to follow this  
Followers 0
Hawkwing

_excelwritesheetfromarray error

5 posts in this topic

_excelwritesheetfromarray gives me an error when writing this array to an excel file.

a1

a2, b2

a3, b3, c3

a4, b4, c4, d4

This is the error

C:\Program Files\AutoIt3\beta\Include\Excel.au3 (571) : ==> The requested action with this object has failed.:

$oExcel.Activesheet.Cells($iStartRow, $iCurrCol).Value = $aArray[$r][$c]

$oExcel.Activesheet.Cells($iStartRow, $iCurrCol)^ ERROR

Can I fix this, or is there an alternative way to write a 2 dimensional array to excel?


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites



_excelwritesheetfromarray gives me an error when writing this array to an excel file.

a1

a2, b2

a3, b3, c3

a4, b4, c4, d4

This is the error

C:\Program Files\AutoIt3\beta\Include\Excel.au3 (571) : ==> The requested action with this object has failed.:

$oExcel.Activesheet.Cells($iStartRow, $iCurrCol).Value = $aArray[$r][$c]

$oExcel.Activesheet.Cells($iStartRow, $iCurrCol)^ ERROR

Can I fix this, or is there an alternative way to write a 2 dimensional array to excel?

The example from the help with your array works ok.

; ***************************************************************
; Example 1 - After opening a workbook and returning its object identifier.  Declare a 2-D Array, then input the Array
; *****************************************************************

#include <Excel.au3>
Local $oExcel
Local $oExcel = _ExcelBookNew();Create new book, make it visible

;Declare the Array
Local $aArray[4][4] = [["a1", "", "", ""],["a2", "b2", "", ""],["a3", "b3", "c3", ""],["a4", "b4", "c4", "d4"]];0-Base Array
_ExcelWriteSheetFromArray($oExcel, $aArray, 1, 1, 0, 0);0-Base Array parameters

MsgBox(0, "Exiting", "Press OK to  Exit")
;_ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1); Now we save it into the temp directory; overwrite existing file if necessary
_ExcelBookClose($oExcel); And finally we close out
;

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hmm, that works for me too. Is there an error in this script thats making it not work then?

http://www.autoitscript.com/forum/index.php?showtopic=95618

Edited by pigeek

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

bump


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Note the remarks in the help file about row and column 0 not being used in the array, because Excel uses 1-based numbering. Also, you created the workbook invisible, so how did you expect to debug it? With all the irrelevant stuff removed, this works:

#include <Array.au3>
#include <Excel.au3>

Dim $array[5][5] = [[5, 5], ["", "a1"], ["", "a2", "b2"], ["", "a3", "b3", "c3"], ["", "a4", "b4", "c4", "d4"]]
_ArrayDisplay($array, "Debug: $array")

arraytoexcel()

Func arraytoexcel()
    $excelfile = _ExcelBookNew()
    _ExcelWriteSheetFromArray($excelfile, $array, 1, 1)
EndFunc  ;==>arraytoexcel

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0