The problem with xlRangeValue is resolved. Seems that neither of us read the header completely. It states quite clearly that when writing it expects an Array Of Arrays - we were providing a simple array. I verified that my old code worked with the current library, then dug into what we were feeding the function.

The solution is to introduce a new array - $xlData - and assign each row we read from the CSV file to a record in that array. The result is an array of arrays, and the xlRangeValue function is then called once after the data from the CSV file is exhausted. The code below works, creating a workbook with a single sheet, populated with data.

Note the key changes -
Addition of a $xlData array
Defining the index pointer to -1; incrementing it before referencing the array; using it to re-dimension the array
Calling xlRangeValue with the $xlData array after closing the input CSV file.

BTW - I get a format warning when opening the .XLS file in Excel 2K7, but it opens fine.

Glenn


;; KixGenerated: 2008/07/30 14:49:36 
Break On
 
Global $DEBUG				; debug flag  
Global $MSG_LOG_			; Message Log file for MSG/DBG UDFs (not used at this time) 
 
Dim $					; generic var 
Dim $Row, $Col				; row and column references  
Dim $I					; index pointer  
Dim $IFile, $OFile			; input/output file names 
Dim $aryData, $xlData[0]		; data array from CSV, array to write to Excel 
Dim $oXL, $oWB				; excel pointer vars 
Dim $Range				; range string (A1) 
 
; Load UDFs 
call @ScriptDir + "\xlLib.udf"
call @ScriptDir + "\csv.UDF"
call @ScriptDir + "\msg.UDF"
 
$DEBUG = 1				; enable debugging  
 
$OFile = 'C:\temp\test.xls'
$IFile = 'C:\Temp\test.csv'
$I = -1					; set the output array index pointer 
$Row = 3				; Start at row 3 and column A 
$Col = 'A'
 
 
$oXL = xlInit()				; instantiate Excel 
Dbg('Init: ' + @SERROR)
 
$wBO = xlBookCreate($oXL, 1)		; create a new workbook with one worksheet 
Dbg('NewBook: ' + @SERROR)
 
$ = xlSheetSelect($oXL, "Sheet1")	; make it active 
Dbg('SheetSelect: ' + @SERROR)
 
If Open(2,$IFile) = 0			; open a source CSV file 
  $aryData = CSV(ReadLine(2))		; read a record and return an array 
  While Not @ERROR
 
    ; for debugging only 
    Dbg('' + (UBound($aryData) + 1) + ' fields were returned by CSV()')
    $I = $I + 1				; increment index pointer  
    ReDim Preserve $xlData[$I]		; resize the Excel array 
    $xlData[$I] = $aryData		; add the CSV data to the Excel array row 
 
    $aryData = CSV(ReadLine(2))		; read next row from input file, if any  
 
  Loop
  $ = Close(2)
  ; write the Excel data array to the defined sheet 
  $ = xlRangeValue($oXL, $Col + CStr($Row), $xlData, 'Sheet1')
  Dbg('RangeValue: ' + @SERROR)
Else
  MessageBox(@SERROR, "ERROR", 64)
EndIf
 
$ = xlFile($oXL, 2, $OFile)
Dbg('Save: ' + @SERROR)
$ = xlQuit($oXL)
Dbg('quit: ' + @SERROR)
 
_________________________
Actually I am a Rocket Scientist! \:D