The format CSV converter in DBF or XLS
Posted: Tue Aug 21, 2012 6:27 am
Whether there is in Alaska or eXpress ++ a function converting a CSV format in DBF or XLS (it is better in DBF)? If yes, that as it to use?
Donnay Software Web Forums
http://bb.mobile.donnay-software.com/Donnay/
http://bb.mobile.donnay-software.com/Donnay/viewtopic.php?f=2&t=830
Code: Select all
// This function loads a CSV file into a work area.
// The top line of the CSV file must contain the field names that match the work area.
FUNCTION DC_CSV2WorkArea( cCsvFileName )
LOCAL nHandle, cLine, aTokens, aFields, lStatus, cFieldName, aStru, ;
oRecord, cValue, i, nFound, nFieldType
nHandle := DC_TxtOpen( cCsvFileName )
IF nHandle <= 0
RETURN .f.
ENDIF
oRecord := DC_DbRecord():new()
cLine := DC_TxtLine( nHandle )
aFields := DC_TokenArray( cLine, ',' )
aStru := dbStruct()
DC_TxtSkip(nHandle,1)
DO WHILE !DC_TxtEof(nHandle)
cLine := DC_TxtLine(nHandle)
aTokens := DC_TokenArray(cLine,',')
dbGoTo(0)
DC_DbScatter(oRecord)
FOR i := 1 TO Len(aFields)
IF !Empty(cFieldName := Upper(Alltrim(aFields[i]))) .AND. Len(aTokens) == Len(aFields)
IF IsFieldVar(cFieldName)
nFound := AScan(aStru,{|a|Upper(Alltrim(a[1]))==cFieldName})
cValue := Alltrim(aTokens[i])
IF nFound > 0
nFieldType := aStru[nFound,2]
IF nFieldType $ 'CM'
oRecord:&(cFieldName) := cValue
ELSEIF nFieldType == 'N'
oRecord:&(cFieldName) := Val(cValue)
ELSEIF nFieldType == 'L'
oRecord:&(cFieldName) := ' ' + Upper(Alltrim(cValue)) + ' ' $ ' Y YES .T. TRUE T '
ELSEIF nFieldType == 'D'
oRecord:&(cFieldName) := CtoD(cValue)
ENDIF
ENDIF
ENDIF
ENDIF
NEXT
DC_DbGather(oRecord,.t.)
DC_TxtSkip(nHandle,1)
ENDDO
DC_TxtClose( nHandle )
RETURN .t.