Jump to content

excel printing


Rskm
 Share

Recommended Posts

hi, i am using commands like the below to print values to excel, the array has 20 values, do i have to manually type as a1, b1, c1, d1.... till t1 or is there a short cut(loop) by which i can get the 20 elements printed in a particular row(here row 1) of excel?

_Excel_RangeWrite($oWorkbook, 1, $array[1], "a1")

_Excel_RangeWrite($oWorkbook, 1, $array[2], "b1")

_Excel_RangeWrite($oWorkbook, 1, $array[3], "c1")

 

thanks

Link to comment
Share on other sites

  • Moderators

Loop through it with a for loop, like so:

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

Local $aArray[20] = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'January', 'February', 'March', 'April', _
                     'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', '2017', '2018']


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

For $a = 0 To UBound($aArray) - 1
    _Excel_RangeWrite($oWorkbook, 1, $aArray[$a], "A" & $a)
Next

 

"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

3 minutes ago, JLogan3o13 said:

Loop through it with a for loop, like so:

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

Local $aArray[20] = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'January', 'February', 'March', 'April', _
                     'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', '2017', '2018']


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

For $a = 0 To UBound($aArray) - 1
    _Excel_RangeWrite($oWorkbook, 1, $aArray[$a], "A" & $a)
Next

 

Hello JLogan,  thanks for the initiative, the above example you mentioned prints output in column A, ie; in cells A1, A2, A3 till A20... what i need is to print the 20 elements in rows ie; A1, B1, C1 .... T1

Link to comment
Share on other sites

  • Moderators

@Rskm look through the help file, it is your friend in these situations. There is a function both for converting column letters to numbers and numbers to letters. Pretty easy to come up with a quick conversion that will suit your needs.

"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

Just something simple to exemplify..

#include <Excel.au3>


ColRange("a", "qq")
ColRange("ZZ", "A", 5)

Func ColRange($sStart, $sEnd, $iStep = 1);iStep --Increment by this many columns -- defaults to 1
    Local $iSt = _Excel_ColumnToNumber ( $sStart )
    Local $iEnd = _Excel_ColumnToNumber ( $sEnd )

    If $iSt > $iEnd Then $iStep = -$iStep ;Need to step backwards

    For $i = $iSt To $iEnd Step $iStep
        consoleWrite(_Excel_ColumnToLetter ( $i ) & ", ") ; Convert the numbers back to letters and append ', '
    Next

    consoleWrite(@CRLF) ;Newline
EndFunc

 

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...