Jump to content

Importing csv file & its fields


Recommended Posts

  • Moderators

Hi,

Could u plz let me know a sample snippet for importing a csv file in the autoit script editor & its fields from the csv file ?

Thanks.

You need to be much more specific in your needs, what you've attempted, and where you're failing at.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi.

Could u plz let me know a sample snippet for importing a csv file in the autoit script editor & its fields from the csv file ?

Please read the sample snippets in the help file:

CSV files are organized in lines. --> filereadline()

In each line the fields are separated by a certain CHAR. --> stringsplit()

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

The sample scenario is

- Open csv file

- Access username & password field values (file attached in txt format)

- Pass the field values(username & password) to the respective GUI components(text boxes) in the application using the Send function

Sample script created below

$file=FileOpen("C:\inputdata.csv",0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; How can i access the field values & pass it in send() function

FileClose($file)

inputdata.txt

Link to comment
Share on other sites

  • Moderators

The sample scenario is

- Open csv file

- Access username & password field values (file attached in txt format)

- Pass the field values(username & password) to the respective GUI components(text boxes) in the application using the Send function

Sample script created below

$file=FileOpen("C:\inputdata.csv",0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; How can i access the field values & pass it in send() function

FileClose($file)

_FileReadToArray() will return an array of file lines

StringSplit() can split that value to give you the rest.

However, if your csv file is that simple...

#include <array.au3>; So you can see output
Global $s_file = @HomeDrive & "\inputdata.csv"
Global $s_read = FileRead($s_file)
Global $a_user_pass = StringRegExp($s_read, "(?i)username,passwd.*?\v+(.+?),(.+?)(?:\v|\z)", 3)
_ArrayDisplay($a_user_pass)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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