Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Simple Excel Array Read


  • Please log in to reply
4 replies to this topic

#1 cdDan

cdDan

    Seeker

  • Active Members
  • 9 posts

Posted 07 May 2010 - 08:28 PM

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.







#2 TouchOdeath

TouchOdeath

    Seeker

  • Active Members
  • 23 posts

Posted 07 May 2010 - 09:38 PM

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.

#3 Tvern

Tvern

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 972 posts

Posted 07 May 2010 - 10:37 PM

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


#4 cdDan

cdDan

    Seeker

  • Active Members
  • 9 posts

Posted 15 May 2010 - 01:24 AM

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.

#5 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 17 May 2010 - 03:21 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users