Jump to content

Simple Excel Array Read


Recommended Posts

Greetings. I am a long time reader of this forum, first time poster. So thank you all for your patience and past help. :idea:

I am trying to do the following:

- A user will enter data in a single column in Excel then run an AutoIT script

The script will:

- Copy the data in that column to an array

- Combine the array data to a url prefix and load it in a browser ie. ( http://www.website.com/page.php?<data from cell1>)

I've been attempting this for a few hours now without success, and finally I am giving in and asking for your help.

Specifically I need to know how to:

copy the data to an array from excel

pull data from that array and loop a function that will:

1. open the url

2. perform other tasks I actually know how to program

and perform this loop until each item in the array has been used (ie. each url has loaded)

The data in column A will have a dynamic number of rows depending on how the user is editing the file.

Sadly all I have to show for myself is the following:

#include <IE.au3>
#include <Array.au3>
#include <Excel.au3>
Local $sheet = @ScriptDir & "\file.xlsx" ; to be used later

WinWaitActive("Microsoft Excel - file.xlsx")

Any help would be greatly appreciated.

Link to comment
Share on other sites

Heres what I used to do at work: Have the user run my script, my script opens a .txt file on the c:\ drive via excel. User enters data into excel. When the user closes the excel file, excel will ask you if you want to save. When the user hits the 'X' to close excel, autoit will take over, use autoit to say 'NO' to save file, and use excel macros to copy every row and column the user has entered. Grab the copied text and loop through to save it to a the .txt (the extension can be anything you want it to be really) file (thats if you want to save what the user inputed) then loop through the copied text.

Opening the browser goes like this:

#include <IE.au3>

$oIE = _IECreate ('http://www.website.com/page.php?' & $datafromcell)

I have all the code somewhere lemme know if you need it.

Link to comment
Share on other sites

Is this what you want?

#include <IE.au3>
#include <Excel.au3>
Local $sheet = @ScriptDir & "\file.xlsx" ; to be used later
WinWaitActive("Microsoft Excel - file.xlsx")
$oExcel = _ExcelBookAttach($sheet) ;points autoit to the right open excelbook
While 1
    Sleep(500) ;reduce cpu usage
    $array = _ExcelReadSheetToArray($oExcel) ;read the sheet into an array
    If @error Then ContinueLoop ;try again if it fails
    $url = "prefix" 
    $url &= $array[1][1] 
    $url &= "suffix"
    If Ping($array[1][1]) Then ExitLoop ;check if the url exists (probably not the best way) and end the loop if so.
WEnd
_IECreate($url) ;navigate to the url
Link to comment
Share on other sites

Hey guys, thank you both so much for the tips. I rewrote the script in a completely different way which does not require arrays and I'm good to go.

All the best and thank you again for your replies.

Link to comment
Share on other sites

I rewrote the script in a completely different way which does not require arrays and I'm good to go.

That's too bad. It's a shame you lost the opportunity to learn an indispensable fundamental to good scripting.

:idea:

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