Sample code for 30+ languages & platforms
AutoIt

Create CSV File

See more CSV Examples

Demonstrates how to create a new CSV file with some simple content.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; 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

$oCsv = ObjCreate("Chilkat.Csv")

; Indicate that the 1st row
; should be treated as column names:
$oCsv.HasColumnNames = True

$bSuccess = $oCsv.SetColumnName(0,"year")
$bSuccess = $oCsv.SetColumnName(1,"color")
$bSuccess = $oCsv.SetColumnName(2,"country")
$bSuccess = $oCsv.SetColumnName(3,"food")

$bSuccess = $oCsv.SetCell(0,0,"2001")
$bSuccess = $oCsv.SetCell(0,1,"red")
$bSuccess = $oCsv.SetCell(0,2,"France")
$bSuccess = $oCsv.SetCell(0,3,"cheese")

$bSuccess = $oCsv.SetCell(1,0,"2005")
$bSuccess = $oCsv.SetCell(1,1,"blue")
$bSuccess = $oCsv.SetCell(1,2,"United States")
$bSuccess = $oCsv.SetCell(1,3,"hamburger")

; Write the CSV to a string and display:
Local $sCsvDoc
$sCsvDoc = $oCsv.SaveToString()
ConsoleWrite($sCsvDoc & @CRLF)

; Save the CSV to a file:
$bSuccess = $oCsv.SaveFile("out.csv")
If ($bSuccess <> True) Then
    ConsoleWrite($oCsv.LastErrorText & @CRLF)
EndIf