Break on
;Call all functions
$udf = Dir(@SCRIPTDIR + "\functions\*.udf")
While $udf <> "" AND @ERROR = 0
Call @SCRIPTDIR + "\functions\" + $udf
$udf = Dir()
Loop
;Remove invalid characters from the time and date.
$date = Join(Split(@DATE, "/"), "")
$time = Join(Split(@TIME, ":"), "")
;Read default customer values from ini file.
$name = ReadProfileString(@SCRIPTDIR + "\test.ini", "Custdata", "Name")
$phone = ReadProfileString(@SCRIPTDIR + "\test.ini", "Custdata", "phone")
$website = ReadProfileString(@SCRIPTDIR + "\test.ini", "Custdata", "website")
$email = ReadProfileString(@SCRIPTDIR + "\test.ini", "Custdata", "email")
;Set Excel filename
$xlFileName = @SCRIPTDIR + "\" + $name + "Feed-" + $date + "-" + $time + ".xlsx"
;Initialize excel instance
$xlPtr = xlInit()
;Create workbook.
$rc = xlBookCreate($xlPtr, 1,)
;Set format for row A to preserve the leading 0.
$rc = xlRangeFormatNum($xlPtr, "A:A", "Text", ,"Sheet1")
;Write header row.
$rc = xlRangeValue($xlPtr, "A1", "Phone",)
$rc = xlRangeValue($xlPtr, "B1", "Website",)
$rc = xlRangeValue($xlPtr, "C1", "E-mail",)
$rc = xlRangeValue($xlPtr, "D1", "Value",)
$rc = xlRangeValue($xlPtr, "E1", "Text",)
$rc = xlRangeValue($xlPtr, "F1", "Category",)
;Read feed into array.
$file = ReadFile(@SCRIPTDIR + "\test.txt")
;Set line index for Excel.
;Start at line 2 because lines 1 contains column names.
$lineindex = 2
;Do stuff for each line in the feed.
For Each $line in $file
;Split line.
$line = Split($line, "#")
;Remove leading and trailing sapces.
For $i = 0 to Ubound($line)
$line[$i] = Trim($line[$i])
Next
;Write data to excel if first ellement is not empty.
If $line[0] <> ""
$aData = xlRangeValue($xlPtr, "A" + $lineindex, $phone,)
$aData = xlRangeValue($xlPtr, "B" + $lineindex, $website,)
$aData = xlRangeValue($xlPtr, "C" + $lineindex, $email,)
$aData = xlRangeValue($xlPtr, "D" + $lineindex, $line[0],)
$aData = xlRangeValue($xlPtr, "E" + $lineindex, $line[1],)
$aData = xlRangeValue($xlPtr, "F" + $lineindex, $line[2],)
$lineindex = $lineindex + 1
EndIf
Next
;Change sheet name
$rc = xlSheetName($xlPtr, $name)
;Save excel file
$rc = xlFile($xlPtr, 2, $xlFileName)
;Quit excel
$rc = xlQuit($xlPtr)