Jump to content

Need help _Excel_RangeWrite


Recommended Posts

  • I need to save the text with excel, each save is 1 row and 2 columns, i did and it does not work please help me
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookNew($oExcel)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf

For $i = 1 To 10
Local $aArray2D[1][2] = [[$i],[2222]]
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray2D, "A"&$i&"")
Next

error_excel.bmp

Link to comment
Share on other sites

  • Moderators

You are creating an array with 1 row and 2222 columns, and the error tells you what is wrong. I would suggest looking at the Wiki article regarding arrays, specifically the section on Multi-Dimensional arrays, and learn how to initialize them correctly.

Edit: Or just wait until someone writes it for you :)

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

You also should create your array before writing to Excel for example:
NB: Example below shows how to initialize 2D Array with Values and another for Initializing 2D Array without values, although as JLogan3o13 mentioned you should read the section on Multi-Dimensional arrays as you'll find it helpful.

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

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)

;~ Initialize 2D Array with values
Local $aArray2D[1][2] = [[1, 2222]]
_ArrayDisplay($aArray2D)

;~ Initialize 2D Array without values
Local $aArray2D[0][2]
For $i = 1 To 10
    ;~ Add Data to 2D Array you could also use ReDim but _ArrayAdd is easier
    _ArrayAdd($aArray2D, $i & "|" & 2222)
Next
;~ Result of 2D Array
_ArrayDisplay($aArray2D)
;~ Write Array to Excel from A1
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray2D, "A1")

 

Link to comment
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
 Share

×
×
  • Create New...