Jump to content
Churchy112

CSV to Webform

Recommended Posts

Churchy112

Good morning,

Apologies if this thread already exists or I've completely missed the answer in a similar thread. 

I'm new to Autoit since yesterday, albeit that I've had an account for 3 years, I'm only starting to get into it. I am trying to create a script which will read my CSV row by row and create a variable per cell on that row. In my job I'm going to need to fill out a webform 100 times over so I would like to input each variable into my chosen field on this webform and repeat.

I've been playing with AutoIT and this is what I've done so far, am I on the right track? I was thinking of using the StringSplit functions but I am a bit clueless to be honest. Any help would be Great to get me started.

#include <file.au3>
#include <FileConstants.au3>
#include <array.au3>

_BrowseForFile()

Global $aOutput, $FilePath

_FileReadToArray ($FilePath,$aOutput,4,",")
_ArrayDisplay($aOutput)

Func _BrowseForFile() ;Sets $FilePath
    global $FilePath=FileOpenDialog("Browse for CSV",@DesktopDir,"csv files (*.csv)",$FD_MULTISELECT + $FD_FILEMUSTEXIST)
EndFunc

 

Edited by Churchy112

Share this post


Link to post
Share on other sites
water

Yes, I think you are on the right track.
I suggest to drop function _BrowseForFile as a single line function is a lot of overhead.
As _FileReadToArray can handle CSV files now you've got a 2D array.
You would then need two loops to process each line (outer loop) and each cell in the row (inner loop).

Which browser do you use to fill the web form?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Churchy112

Thanks for your suggestions.

I'll be using Chrome but I can switch to any if more compatible. I'm hoping to apply this to other uses such as iTunes account creation. I work with schools and for every Apple device in school I need to create an Apple ID for it, so thats on average 60 Apple IDs per school :(.

Would you mind giving me a example of the loops that I could have a play with?

Share this post


Link to post
Share on other sites
water

I'm not sure you need two loops because I assume you process all fields of a reacord (row) and write them to a single web page.
So it could look like:

For $i = 1 to $aOutput[0][0]
    ; Write the first field to the web page: $aOutput[$i][0]
    ; Write the second field to the web page: $aOutput[$i][1]
    ; ...
Next

How to write the data to the web page depends on the browser you use. Easiest is IE (a UDF comes with AutoIt), more complex gets FF etc.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Churchy112

I'm not sure you need two loops because I assume you process all fields of a reacord (row) and write them to a single web page.
So it could look like:

For $i = 1 to $aOutput[0][0]
    ; Write the first field to the web page: $aOutput[$i][0]
    ; Write the second field to the web page: $aOutput[$i][1]
    ; ...
Next

How to write the data to the web page depends on the browser you use. Easiest is IE (a UDF comes with AutoIt), more complex gets FF etc.

Thanks! I just need to have a play at the emulation functions and I'll give it a go tomorrow with iTunes form at my school. 

Share this post


Link to post
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

  • Similar Content

    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Lisuter
      By Lisuter
      Hello...

      How i can write data from txt to +3 Input?
      Example:
      In txt i have:
      Michael XYZ, 21, Boston
      Olex Marshal, 17, Boston
      Alex XYZ, 19, Boston
       
      And now i want load that data to input in autoit. 

      Name          y.o          city
      [ Input1]  [Input2] [Input3]
      [ Input4]  [Input5] [Input6]
      [ Input7]  [Input8] [Input9]
       
      After load should be:
      Name               y.o            city
      [Michael XYZ]      [21]     [Boston]
      [ Olex Marshal]  [17]      [Boston]
      [ Alex XYZ]           [19]      [Boston]
       
      FileOpen("Test.txt",0)                          $aas = GUICtrlSetData($Input1, FileReadLine("Test.txt",1))             FileClose("Test.txt") But its wrong. ofcourse its load all to input 1. So now how do you load this data directly into each input separately? The comma stop sign is here. Each line is a new person
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
×