Re: CSV, with Header,, easy way to rename headers,

55 views
Skip to first unread message

Karl Faller

unread,
May 14, 2021, 5:15:44 PMMay 14
to
Phil,
something along....

LOCAL cHeaderLine, cNewLine AS STRING
...
cHeaderLine :=FReadLine(ptrHandle, cFilename)
cNewLine := StrTran(cHeaderLine, " ", "")
FWrite(Upper(cNewLine)
FClose()

?

But that might cause problems, as your line will shrink, so i'd rather
replace the blanks with underscores...



On Thu, 13 May 2021 23:01:05 -0700 (PDT), Phil McGuinness wrote:

>Quick, easy way to rename Headers of columns as they have spaces and mixed case and I want to import to PostGRES..
>
>Have to manually fix... easy first time but need to do it on same export from other clients data.
>
>Thanks in advance
>
>I was thinking maybe "Excel.application" load and some function that did this..
>
>Any ideas welcome
Regards

Karl

Phil McGuinness

unread,
May 16, 2021, 2:24:40 AMMay 16
to
Karl

cCSVContent := MemoRead(GetDefault() +"TheDataAs.csv")
//
aCSVdata := Conv2Array( cCSVContent, CRLF )
aHeaders := Conv2Array( aCSVdata[1], [,] ) // The header
//
FOR xx := 1 TO ALen(aHeaders)
aHeaders[xx] := AllTrim(Lower(aHeaders[xx]))
aHeaders[xx] := StrTran(aHeaders[xx], _CHR(32))
cNewCSVHeader += aHeaders[xx] + [,]
NEXT
//
cNewCSVHeader := substr(cNewCSVHeader,1, slen(cNewCSVHeader)-1)
//
aCSVdata[1] := cNewCSVHeader+ CRLF
//
FOR xx := 1 TO ALen(aCSVdata)
cCSVFixed += aCSVdata[xx]+CRLF
NEXT
//

MemoWrit( GetDefault() +"TheDataFixed.csv", cCSVFixed )

Phil
--
Reply all
Reply to author
Forward
0 new messages