Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Sample CSV file
- col 0 col 1 col 2 col 3 col 4 col 5 col 6 col 7 col 8 9 col 10
- first_name last_name company_name address city county postal phone1 phone2 email web
- Aleshia Tomkiewicz Alan D Rosenburg Cpa Pc 14 Taylor St St. Stephens Ward Kent CT2 7PP 01835-703597 01944-369967 [email protected] http://www.alandrosenburgcpapc.co.uk
- Evan Zigomalas Cap Gemini America 5 Binney St Abbey Ward Buckinghamshire HP11 2AX 01937-864715 01714-737668 [email protected] http://www.capgeminiamerica.co.uk
- France Andrade Elliott, John W Esq 8 Moor Place East Southbourne and Tuckton W Bournemouth BH6 3BE 01347-368222 01935-821636 [email protected] http://www.elliottjohnwesq.co.uk
- Ulysses Mcwalters Mcmahan, Ben L 505 Exeter Rd Hawerby cum Beesby Lincolnshire DN36 5RP 01912-771311 01302-601380 [email protected] http://www.mcmahanbenl.co.uk
- If we want to generate a list of companys with adresses, we must extract the 3 and 4th column (col 2 and col 3).
- Below is an example of how to extract it from a CSV file
- ;; Declare your ICSV object
- ICsv list_csv
- list_csv=CreateCsv()
- list_csv.Separator=";" ;; Because we are loading a .csv file, we MUST indicate what the seperator is
- list_csv.FromFile("E:\__qm_testdirs\csv\testfree\test.csv") ;; Path to the sample CSV file "test.csv" (it contains the above mentioned 'Sample CSV file' and more lines)
- int i j r c
- str cur_cell_a ;; here we store the current cell A
- str cur_cell_b ;; here we store the current cell B
- str newfile_contents;; here we create the CONTENTS of the new file that is stored in the below .csv file
- str path_to_newfile="c:\test\abc.csv"
- for r 0 list_csv.RowCount
- ;;'r' represents the ROW , '2' represents column (because '0' = FIRST column, that means that '2'=column 3)
- ;; We have stored the current cell (COMPANY) in a container (variable) called "cur_cell"
- cur_cell_a=list_csv.Cell(r 2)
- ;; Here we have stored cell 3, ADDRESS (fourth cell, because we start at '0', see above 'Sample CSV file')
- cur_cell_b=list_csv.Cell(r 3)
- ;; To create somtheing like this
- Alan D Rosenburg Cpa Pc; 14 Taylor St
- Cap Gemini America;5 Binney St
- The container "newfile_contents" must be build up line by line (row by row)
- newfile_contents.from(newfile_contents cur_cell_a ";" cur_cell_b "[]") ;; "[]" = ENTER (line break), very important because then EACH added line will be on a newline! BUT it leaves an extra empty line after the LAST one is processed
- When we arrive here, the above line "for r 0 ..." is DONE! and the container (variable) "newfile_contents" is now fully filled
- and can now be written. Note that we "trim" to remove the last empty line
- newfile_contents.trim
- out newfile_contents ;; output to see the conents
- newfile_contents.setfile(path_to_newfile) ;; here you WRITE the contents of "newfile_contents"
Advertisement
Add Comment
Please, Sign In to add comment