Reputation: 1084
In visual foxpro, i have a cursor which is the result of a sql query, when i export the content of that cursor to a csv file using the statement :
COPY TO "c:\test.csv" type DELIMITED
all data is messed up, i do not pecify any delimiter so basically foxpro takes the default, which is every column in that cursor. bow when i run the same command to an xls file, and then convert it to a csv file...it works very well:
COPY TO "c:\test.xls" type XL5
anyone has had such issue, any one still using foxpro and doing stuff like those?
Upvotes: 1
Views: 23051
Reputation: 2773
Personally I never liked the built-in DBF to CSV converters. They always seemed to do things I did not want them to do. So I just wrote my own. Here is some code to get you started.
LOCAL lnFields
SELECT DBF
lnFieldCount = AFIELDS(laFields)
lnHandle = FOPEN("filename.csv", 1)
ASSERT lnHandle > 0 MESSAGE "Unable to create CSV file"
SCAN
lcRow = ""
FOR lnFields = 1 TO lnFieldCount
IF INLIST(laFields[lnFields,2], 'C', 'M')
lcRow = lcRow + IIF(EMPTY(lcRow), "", ",") + '"' + ;
STRTRAN(EVALUATE(laFields[lnFields,1]),'"', '""') + '"'
ELSE
lcRow = lcRow + IIF(EMPTY(lcRow), "", ",") + ;
TRANSFORM(EVALUATE(laFields[lnFields,1]))
ENDIF
ENDFOR
FWRITE(lnHandle, lcRow)
ENDSCAN
FCLOSE(lnHandle)
Upvotes: 1