TheLazyPig
Programmer
Hi! Is it possible when COPY TO CSV the column name were capitalize instead of small letters? I haven't found yet anything related to this.
Thanks.
Thanks.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CREATE CURSOR csvTest (Column1 Integer AUTOINC, Column2 Varchar(50))
INSERT INTO csvTest (Column2) VALUES ("First row")
INSERT INTO csvTest (Column2) VALUES ("Second row")
INSERT INTO csvTest (Column2) VALUES ("Third row")
LOCAL CSV AS CsvProcessor
m.CSV = CREATEOBJECT("CSVProcessor")
m.CSV.ValueSeparator = ";" && adjust as required
WITH m.CSV.FieldMapping AS Collection
.Add("Column1", "First Column")
.Add("Column2", "Second Column")
ENDWITH
m.CSV.Export("csvTest.csv", .T.)
.Add("Column1", "First Column")
.Add("Column2", "Second Column")
.Add("Column1", FIELD(1))
.Add("Column2", FIELD(2))
USE MyTable
COPY TO D:\$INCOMING\MyCSV.CSV CSV FIELDS NAME,DESC
m.STRING = FILETOSTR("d:\$incoming\MyCSV.csv")
m.FIELDSTR = UPPER(MLINE(m.STRING,1))+CHR(13)+CHR(10)
m.NEWFILE = m.FIELDSTR+CHR(13)+CHR(10)
FOR I = 2 TO MEMLINES(m.STRING)
m.FIELDSTR = m.FIELDSTR+MLINE(M.STRING,I)+CHR(13)+CHR(10)
NEXT
STRTOFILE(m.FIELDSTR ,"d:\$incoming\MyCSV.csv")
Mike Lewis said:So, you could slightly adapt Atlope's code to make it more generic.
CREATE CURSOR csvTest (Column1 Integer AUTOINC, Column2 Varchar(50))
INSERT INTO csvTest (Column2) VALUES ("First row")
INSERT INTO csvTest (Column2) VALUES ("Second row")
INSERT INTO csvTest (Column2) VALUES ("Third row")
LOCAL CSV AS CsvProcessor
m.CSV = CREATEOBJECT("CSVProcessor")
m.CSV.Export("csvTest.csv", .T.)