Jump to content

Use _Excel_RangeRead to read column From Left to Right by While


Recommended Posts

Hi there, I have a file Book1.xlsx . 

I want to read infomation in A3,B3,C3,D3,E3,F3..... etc ..... P3. And I want to use While to read that. How A change into P3 when we use While ? 

In my full file, I have to read A3 --> EXL3 (4017 coulmn). 

Book1.xlsx

Link to comment
Share on other sites

Simply set parameter $vRange to "A3:EXL4017"

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Unsure if you meant you want to read specific columns within a While loop, if so you can always use _Excel_ColumnToNumber, example:

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

;~ Excel Column/Row Start
Local $sCol1 = "A"
Local $iCol1 = _Excel_ColumnToNumber($sCol1)
Local $iRow1 = 3

;~ Excel Column/Row End
Local $sCol2 = "P"
Local $iCol2 = _Excel_ColumnToNumber($sCol2)
Local $iRow2 = 3

Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox(16, "Error", "Unable to open Excel")
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Example.xlsx")
If @error Then Exit MsgBox(16, "Error", "Unable to open workbook")

Local $aRange = _Excel_RangeRead($oWorkbook, Default, $sCol1 & $iRow1 & ":" & $sCol2 & $iCol2)

;~ Read Column P
ConsoleWrite("Value of Column P3 : " & $aRange[0][$iCol2 - 1] & @CRLF & @CRLF)

;~ Read Columns A to P
For $i = ($iCol1 - 1) To ($iCol2 - 1)
    ConsoleWrite(_Excel_ColumnToLetter($i + 1) & $iRow1 & " = " & $aRange[0][$i] & @CRLF)
Next

 

Link to comment
Share on other sites

Performancewise reading cell by cell isn't the fastest solution.
Read Row by Row to an array and then process the array.
Or read the whole content (by using UsedRange) in one go.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Little confused, the script above is reading the entire row into an array and then looping through the array to show each of the results?  Not sure if that's what the OP was referring to though, it sounded like he wanted to loop through the results.

Link to comment
Share on other sites

I will wait until the OP tells us exactly why he want's to process the Workbook in the way he described.
When we know what he wants to achieve we might propose a better solution ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...