Jump to content

Import CSV to Multi Column Select --> Send to 2nd App


Recommended Posts

I am not sure if AutoIT is is the best way to go about this, or if this is possible in AutoIT; so, by all means all feedback is welcomed.

Objective:

Import CSV file into a UI, with the first row of the CSV being the colmn names of the UI. I want to be able to copy the info from the cell and paste it into an input field of another program.

2uoEIAV.png

I should be able to select the columns I want to use and where they should go on the 2nd program.

Can this be done in AutoIT, or should I use Java, Python, C#, etc?

Thanks!

Tim

Link to comment
Share on other sites

Should be possible using AutoIt.

I would first run the AutoIt Window Info tool to get the control IDs from the other program. Depending on the application it can sometimes be hard/impossible to get the control IDs.

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

You should be able to get started using a function like:

_FileReadToArray()

to get the data from the CSV file, and then parse them into the UI.

Just my 2 cents. :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

You can process the file into an array, then you can use that array in whatever way you need to populate a listview or anything else. _FileReadToArray in the latest version of AutoIt (3.3.12.0) has the ability to do a simple CSV to array capability.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I stole this from somewhere else on the forums a while ago, but this is what I have so far:

#include <file.au3>
#include <GUICONSTANTS.au3>

Global $a_cvs
$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else
    _FileReadToArray($s_Path, $a_cvs)
    GUICreate("CSV Listview", 620, 250, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_cvs[1],",","|"), 10, 10, 600, 210)
    GuiSetState()
    For $i = 2 To UBound($a_cvs) - 1
        $s_temp = StringReplace($a_cvs[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next
EndIf
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
Exit

This is the CSV file I am using:

material_name,material_alias,period,letter
HT-000001331,,r1,A1
HT-000001330,alias 3 not 4,r2,A2
dummy,,,A3
RS-000001336,,r4,A4
HT-000001335,,r2,A5
dummy,,,A6
HT-000001334,,r2,A7
HT-000001328,alias1,r1,A8
HT-000001333,,r2,B1
dummy,,,B2
dummy,,,B3
HT-000001332,,r1,B4
dummy,,,B5
HT-000001332,,r2,B6
HT-000001329,alias 2,r2,B7
dummy,,,B8
dummy,,,C1
dummy,,,C2
HT-000001329,alias 2,r1,C3
HT-000001334,,r1,C4
RS-000001336,,r1,C5
dummy,,,C6
HT-000001333,,r1,C7
dummy,,,C8
dummy,,,D1
dummy,,,D2
dummy,,,D3
dummy,,,D4
RS-000001336,,r2,D5
dummy,,,D6
HT-000001330,alias 3 not 4,r1,D7
HT-000001331,,r2,D8
dummy,,,E1
dummy,,,E2
HT-000001335,,r1,E3
RS-000001336,,r3,E4
dummy,,,E5
RS-000001336,,r5,E6
HT-000001328,alias1,r2,E7
dummy,,,E8

How do I get checkboxes at the bottom of each column, so I have a UI similar to my first post?

Thanks,

Tim

Link to comment
Share on other sites

If I'm not mistaken you'll need to create them using:

GUICtrlCreateCheckbox()

inside your own GUI.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Okay, so I can create 1 checkbox....but I can't create multiple checkboxes based on how many column names I have. This number is subject to change....

#include <file.au3>
#include <GUICONSTANTS.au3>

Global $a_csv
$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else
    _FileReadToArray($s_Path, $a_csv)
    GUICreate("CSV Listview", 620, 350, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1],",","|"), 10, 10, 600, 210)
    ;$Box = GUICtrlCreateCheckbox("this is a checkbox", 10, 300, 180, 30)
    GuiSetState()
    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next
    $checkboxName = StringSplit($a_csv[1], ",")

    For $j = 1 to $checkboxName[0]
    $Box = GUICtrlCreateCheckbox($checkboxName[1], 10, 300, 180, 30)
    ;$Box = GUICtrlCreateCheckbox($checkboxName[2], 10, 300, 190, 30)
    Next
EndIf
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

Try this.

#include <file.au3>
#include <GUICONSTANTS.au3>
#include <GUIListView.au3>
Global $a_csv
$s_Path = "F:\AutoItScripts\April2014a.csv"
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else
    _FileReadToArray($s_Path, $a_csv)
    GUICreate("CSV Listview", 620, 350, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210)
    $hListview = GUICtrlGetHandle($listview)
    ;$Box = GUICtrlCreateCheckbox("this is a checkbox", 10, 300, 180, 30)
    GUISetState()
    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next
    $checkboxName = _GUICtrlListView_GetColumnCount($hListview) ; get the count of the columns
    Local $aColumnInfo
    For $j = 0 To $checkboxName - 1
        $aColumnInfo = _GUICtrlListView_GetColumn($hListview, $j ) ; gets the text of the header column
        $Box = GUICtrlCreateCheckbox($aColumnInfo[5], 10 + (170 * $j), 300, 180, 30)
    Next
EndIf
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Exit

Ask if you have any questions.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks for help so far guys! I really appreciate it.

So thanks to BrewMan, I was able to get everything I wanted on the screen (with a little modding on my end).

What I would like to be able to do now, is make the buttons to the right of the checkbox only usuable if the checkbox is selected, and the other buttons "map sample submition" and "run program" only available once the prior is done.

Example:

Checkbox selected --> Can now map input location --> Can now sample submit button --> Can now run program

Here is the layout as of now:

#include <file.au3>
#include <GUICONSTANTS.au3>

Global $a_csv
$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else
    _FileReadToArray($s_Path, $a_csv)
    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210)
    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]
    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)

    For $j = 1 To $iCount
        ; Store controIDs of the checkboxes
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 180, 30)
        $mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)

    Next

    GUISetState()
    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

EndIf
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Exit

Thanks agian!

Edited by timdecker
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...