DataFlex
DataFlex
Create CSV File
See more CSV Examples
Demonstrates how to create a new CSV file with some simple content.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoCsv
String sCsvDoc
String sTemp1
Move False To iSuccess
// This sample code creates a new CSV file (sample.csv)
// that contains this content:
//
// year,color,country,food
// 2001,red,France,cheese
// 2005,blue,"United States",hamburger
Get Create (RefClass(cComChilkatCsv)) To hoCsv
If (Not(IsComObjectCreated(hoCsv))) Begin
Send CreateComObject of hoCsv
End
// Indicate that the 1st row
// should be treated as column names:
Set ComHasColumnNames Of hoCsv To True
Get ComSetColumnName Of hoCsv 0 "year" To iSuccess
Get ComSetColumnName Of hoCsv 1 "color" To iSuccess
Get ComSetColumnName Of hoCsv 2 "country" To iSuccess
Get ComSetColumnName Of hoCsv 3 "food" To iSuccess
Get ComSetCell Of hoCsv 0 0 "2001" To iSuccess
Get ComSetCell Of hoCsv 0 1 "red" To iSuccess
Get ComSetCell Of hoCsv 0 2 "France" To iSuccess
Get ComSetCell Of hoCsv 0 3 "cheese" To iSuccess
Get ComSetCell Of hoCsv 1 0 "2005" To iSuccess
Get ComSetCell Of hoCsv 1 1 "blue" To iSuccess
Get ComSetCell Of hoCsv 1 2 "United States" To iSuccess
Get ComSetCell Of hoCsv 1 3 "hamburger" To iSuccess
// Write the CSV to a string and display:
Get ComSaveToString Of hoCsv To sCsvDoc
Showln sCsvDoc
// Save the CSV to a file:
Get ComSaveFile Of hoCsv "out.csv" To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoCsv To sTemp1
Showln sTemp1
End
End_Procedure