Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Export to csv with | and no quotes??
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01682536
Message ID:
01682539
Views:
47
>I'm trying to generate a file so someone else can import it.
>
>Needs:
>1. No quotes around character files
>2. delimited with a | (pipe character)
>3. headers (column names) in 1st row.
>
>I can't seem to pull this off -- anyone know the syntax?
>
>This is close but no header names
>COPY TO (lcoutfile) DELIMITED WITH CHARACTER | WITH ""
>
>..and of course this doesn't work at all lol
>COPY TO (lcoutfile) DELIMITED WITH CHARACTER | WITH "" TYPE CSV

Victor,

You can STRTOFILE() the header row, execute the working but headerless COPY TO command, and then STRTOFILE() the result into the header file.

Or you can use the CSVProcessor at https://github.com/atlopes/csv class:
* the cursor
CREATE CURSOR SampleData (charData Varchar(20), numData Double(4))

INSERT INTO SampleData VALUES ('ABC', RAND())
INSERT INTO SampleData VALUES ('DEF', RAND())
INSERT INTO SampleData VALUES ('GHI', RAND())
INSERT INTO SampleData VALUES ('JKL', RAND())
INSERT INTO SampleData VALUES ('MNO', RAND())

* the csv file
LOCAL OutFile AS String

m.OutFile = ADDBS(SYS(2023)) + "~vfp_piped.csv"

* build the csv file
LOCAL CSVP AS CSVProcessor

m.CSVP = CREATEOBJECT("CSVProcessor")

m.CSVP.ValueSeparator = "|"
m.CSVP.ValueDelimiter = ""

m.CSVP.Export(m.OutFile, .T.)

* check on the csv contents
MODIFY FILE (m.OutFile) NOEDIT

* and then delete it
ERASE (m.OutFile)
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform