Guest User

example_csv_icsv

a guest
Mar 27th, 2016
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. ;; Sample CSV file
  2.  
  3. col 0 col 1 col 2 col 3 col 4 col 5 col 6 col 7 col 8 9 col 10
  4. first_name last_name company_name address city county postal phone1 phone2 email web
  5. 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
  6. Evan Zigomalas Cap Gemini America 5 Binney St Abbey Ward Buckinghamshire HP11 2AX 01937-864715 01714-737668 [email protected] http://www.capgeminiamerica.co.uk
  7. 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
  8. 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
  9.  
  10.  
  11.  
  12. If we want to generate a list of companys with adresses, we must extract the 3 and 4th column (col 2 and col 3).
  13. Below is an example of how to extract it from a CSV file
  14.  
  15.  
  16. ;; Declare your ICSV object
  17. ICsv list_csv
  18. list_csv=CreateCsv()
  19. list_csv.Separator=";" ;; Because we are loading a .csv file, we MUST indicate what the seperator is
  20. 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)
  21.  
  22. int i j r c
  23. str cur_cell_a ;; here we store the current cell A
  24. str cur_cell_b ;; here we store the current cell B
  25. str newfile_contents;; here we create the CONTENTS of the new file that is stored in the below .csv file
  26. str path_to_newfile="c:\test\abc.csv"
  27.  
  28. for r 0 list_csv.RowCount
  29.  
  30. ;;'r' represents the ROW , '2' represents column (because '0' = FIRST column, that means that '2'=column 3)
  31. ;; We have stored the current cell (COMPANY) in a container (variable) called "cur_cell"
  32. cur_cell_a=list_csv.Cell(r 2)
  33.  
  34. ;; Here we have stored cell 3, ADDRESS (fourth cell, because we start at '0', see above 'Sample CSV file')
  35. cur_cell_b=list_csv.Cell(r 3)
  36.  
  37. ;; To create somtheing like this
  38.  
  39. Alan D Rosenburg Cpa Pc; 14 Taylor St
  40. Cap Gemini America;5 Binney St
  41.  
  42.  
  43.  
  44. The container "newfile_contents" must be build up line by line (row by row)
  45.  
  46. 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
  47.  
  48.  
  49. When we arrive here, the above line "for r 0 ..." is DONE! and the container (variable) "newfile_contents" is now fully filled
  50. and can now be written. Note that we "trim" to remove the last empty line
  51.  
  52. newfile_contents.trim
  53. out newfile_contents ;; output to see the conents
  54. newfile_contents.setfile(path_to_newfile) ;; here you WRITE the contents of "newfile_contents"
Advertisement
Add Comment
Please, Sign In to add comment