1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help for Imacros script. Extract data from csv file and fill form.

Discussion in 'General Scripting Chat' started by KLANN, Sep 6, 2013.

  1. KLANN

    KLANN Registered Member

    Joined:
    Dec 26, 2012
    Messages:
    63
    Likes Received:
    4
    Hello.
    I have a problem with Imacros scrpting. I need to extrapolate data from the file.csv and put it on apposite tabs but the problem is that it seems like Imacros put all data of all columns of the first line in the first tab only.
    Here's an image of the file.csv
    img.png

    and this is the script:
    Code:
    TAB T=1
    SET !DATASOURCE file.csv
    SET !DATASOURCE_COLUMNS 3
    SET !LOOP 1
    SET !DATASOURCE_LINE {{!LOOP}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:edit_post ATTR=ID:post_three CONTENT={{!COL1}}
    TAG  POS=1 TYPE=TEXTAREA FORM=NAME:source ATTR=ID:htmlSource CONTENT=<a  href={{!COL2}}<SP>title="title"<SP>target="_blank">{{!COL3}}</a>text
    TAG POS=1 TYPE=BUTTON ATTR=ID:save_button
    
    The problem is that in the tag where should be only COL1 imaBasicros put the values of COL2 and COL3 together separated by comma. Basically in COL1 i should get only the number 1, instead i get 1,4,7 and in the next loop i get 2,5,8.
    Where could possibly be the error?
    Thx
     
  2. kvmcable

    kvmcable Supreme Member

    Joined:
    Dec 28, 2010
    Messages:
    1,355
    Likes Received:
    2,815
    Occupation:
    24 year business owner - old school dude
    Location:
    KFC - BW3
    Check your csv in notepad or similar. I think you have an error in the formatting of your csv.
     
  3. cyrusdavirus

    cyrusdavirus Regular Member

    Joined:
    Aug 18, 2012
    Messages:
    470
    Likes Received:
    87
    Try commenting out "SET !DATASOURCE_COLUMNS 3". Not sure why, but I have it commented out on a similar macro and I have no problem.
     
  4. KLANN

    KLANN Registered Member

    Joined:
    Dec 26, 2012
    Messages:
    63
    Likes Received:
    4
    I triedbut maybe I did it wrong. I saved it in txt format but nothing change. Do you have any advise?ty
     
  5. KLANN

    KLANN Registered Member

    Joined:
    Dec 26, 2012
    Messages:
    63
    Likes Received:
    4
    I tried this too but I get this error: RuntimeError: Column number 2 greater than total number of columns 1, line: 26 (Error code: -953)
     
  6. kvmcable

    kvmcable Supreme Member

    Joined:
    Dec 28, 2010
    Messages:
    1,355
    Likes Received:
    2,815
    Occupation:
    24 year business owner - old school dude
    Location:
    KFC - BW3
    What are you using to create CSV file? You can't use txt file but you can open a CSV file in a text editor to make sure you don't have any extra formatting code that some programs save when saving as CSV. Notepad++ can open a CSV file correctly. It sounds like your fields aren't properly delimited if COL1 is getting data from 3 separate columns. Look and make sure your CSV columns are delimited by commas and the fields are delimited by double quotes ("). It should look like this in notepad++

    "1","4","7"
    "2","5,"8"

    and so on.

    It is quite possible (I used to do it all the time for CSV delimited by semi-colons) someone changed your delimited setting in Windows so although you're saving as a CSV the delimiter isn't a comma. That is why you open it in a txt editor to make sure what the delimiter is.
     
    • Thanks Thanks x 1
    Last edited: Sep 7, 2013
  7. KLANN

    KLANN Registered Member

    Joined:
    Dec 26, 2012
    Messages:
    63
    Likes Received:
    4
    Yes you are right! I found the error! When I save in txt the delimitation is ; and not comma. I changed with comm and it works.
    But how can I do to make csv delimit columns with comma and not ; ? I mean, the csv file is saved with the format comma delimited but this is not what really happens. how can I do the let Imacros works with csv without saving it in txt and changing all ; in commas?
     
  8. kvmcable

    kvmcable Supreme Member

    Joined:
    Dec 28, 2010
    Messages:
    1,355
    Likes Received:
    2,815
    Occupation:
    24 year business owner - old school dude
    Location:
    KFC - BW3
    Well this is how it's done in Windows XP and other versions will be similar.

    1.) Open Control Panel
    2.) Open Regional and Language Options
    3.) On First Tab (Regional Options) Click Customize
    4.) On First Tab (Numbers) Look For List Separator and Change it back to a comma

    Click the OK buttons and now when you save to CSV a comma will be the separator :)
     
    • Thanks Thanks x 1