Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:35 pm
by pillick >> Sun, 3 Feb 2002 23:16:08 GMT
Ummm, what do you need to know? All you do is treat it as if you are writing to an ordinary text file, except you use a different extension and you use the usual conventions for that type of file.
For example, a csv file is like a table where each row is a seperate line, and each column is seperated by commas. So all you do to create a csv file is create a file with ".csv" on the end of it and start writing data into it a line at a time.
Heres a method I wrote that outputs the contents of a table into a csv file:
saveTable(table:Table ; caption:String);
vars
table2 : Table ;
saveDialog : CMDFileSave ;
fileName, line: String ;
file : File ;
pos : Integer ;
rows, columns : Integer ;
begin
table2 := table ;
create saveDialog ;
saveDialog.dialogTitle := caption ;
saveDialog.filter := "CSV File|*.csv|" ;
if saveDialog.open = 0 then
fileName := saveDialog.fileName ;
pos := 1 ;
fileName.scanUntil(".", pos) ;
if pos = 0 then
fileName := fileName & ".csv" ;
endif ;
create file ;
file.openOutput(fileName) ;
rows := 0 ;
while rows < table.rows do
rows := rows + 1 ;
columns := 0 ;
line := null ;
while columns < table.columns do
columns := columns + 1 ;
line := line & table2.accessCell(rows, columns).text & "," ;
endwhile ;
file.writeLine(line) ;
endwhile
file.close ;
endif ;
end;