The format CSV converter in DBF or XLS

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

The format CSV converter in DBF or XLS

#1 Post by Eugene Lutsenko »

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?

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: The format CSV converter in DBF or XLS

#2 Post by Auge_Ohr »

hi,

you can use SDFDBE or DELIMITED to create a CSV.
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: The format CSV converter in DBF or XLS

#3 Post by Eugene Lutsenko »

And if it is already created (CSV), how it will load into DBF?

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: The format CSV converter in DBF or XLS

#4 Post by rdonnay »

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.
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: The format CSV converter in DBF or XLS

#5 Post by Eugene Lutsenko »

I understand that I have a bad balance meanwhile that I receive at a forum and that I give on it: I receive much, and I give practically a zero. But nevertheless you couldn't provide the program which would address to the given function. I had a question: the database in which information from the CSV file will register, should be created to the appeal to this function? Whether if yes, that is possible to define automatically its structure and how it to make?

Post Reply