01-18-2010, 09:32 AM
Function CsvAddColumn
;/
function ICsv&csv column
;Adds CSV column.
;It will be empty. Use Cell(r c)="value" to set its value.
;column - 0-based index of the new column. To add to the end, can be >= column count or -1.
int i j nr(csv.RowCount) nc(csv.ColumnCount)
ARRAY(str) a.create(nr)
if(column<0 or column>nc) column=nc
nc+1
for i 0 nr
,str& s=a[i]
,for j 0 nc
,,if(j=column)
,,,s.fromn(s s.len "" 1)
,,else
,,,lpstr v=csv.Cell(i j-(j>column))
,,,s.fromn(s s.len v len(v)+1)
csv.Clear
for i 0 nr
,csv.AddRowMS(i nc a[i])