Posts: 12,147
Threads: 143
Joined: Dec 2002
Quote:Let's say I have a CSV file as such:
Filename: file.cvs
Directory = C:\CVSdb
CSV divider is "|" (and not a comma)
The file has 4 categories/columns as listed below & 2 rows:
Col-1 Col-2 Col-3 Col-4
LastName FirstName Age Sex
Ex:
Doe | John | 39 | M
Doe | Jane | 38 | F
Gintarus, could you provide me with a short example of how to:
-create this
-set the data (for example, change the name 'Jane' to 'Susan')
-get data = turn 'Susan' into a variable and then show it via 'out'
Posts: 12,147
Threads: 143
Joined: Dec 2002
Macro
Macro2448
;a CSV string for testing
str csv=
;Doe | John | 39 | M
;Doe | Jane | 38 | F
;create ICsv variable and load data
ICsv x._create
x.Separator="|" ;;change separator (default is ",")
x.FromString(csv) ;;or x.FromFile("C:\CVSdb\file.cvs")
;get a cell
str cell
cell=x.Cell(1 1) ;;0-based row and column (Jane)
out F"cell 1 1 was: {cell}"
;change cell
cell="Susan"
x.Cell(1 1)=cell
;get CSV data to string
x.ToString(csv) ;;or x.ToFile("C:\CVSdb\file.cvs")
;results
out "changed CSV:"
out csv
Posts: 111
Threads: 31
Joined: Sep 2014
Ahh!!! -perfect! Now I'm on my way with CSV elements. Thank You
Posts: 22
Threads: 4
Joined: Apr 2013
Excellent mini tutorial, it would be great if you could post further similar snippets now and again.