CSV export issues
Brian K. White
brian at aljex.com
Wed Jul 5 08:01:27 PDT 2017
On 7/1/2017 4:44 PM, Jean-Pierre Radley via Filepro-list wrote:
> I am trying to generate a spreadsheet using
>
> export word rpt= /usr/tmp/report.csv
>
> The filePro file is an inventory of metal parts. In the Description
> field the single or double quote may show up as the conventional
> abbreviation for feet or inches, e.g.:
>
> 6" DIAL CALIPER WHITE FACE
I think the most likely to be accepted is to just double the
double-quote. Wherever there is a ", write out "".
That's what MS Excel does, and because of that, that's what a lot of
other things accept.
It doesn't screw up filepro, at least not while exporting. Any
field/record delimiter ambiguity is all in the receiver.
This will require a gosub to walk through the field byte-at-a-time, or
using mid, to insert a 2nd " for every ". xlate won't work because it's
one byte in two bytes out.
The gosub isn't very long, but since it has to walk the field
byte-at-a-time, or at least it has to use instr() & mid(), it can slow
down the export if you have to do it on very many fields.
You could also use xlate() to convert " to some single arbitrary special
byte that will never be in the input, like something non-printable or
above 127, and then post-process that with "sed -i" to change that to
"". Could do that right in the same process table in a system() in @done
as long as you have closed the export before doing the system(). That
sounds Rube Goldberg, but it might be faster for big data sets.
...
z = 22 ; gosub "dqt" ; csv(22) = z
z = 23 ; gosub "dqt" ; csv(23) = z
z = 24 ; gosub "dqt" ; csv(24) = z
...
z ' data in to / out from gosub
t ' temp internal copy of input
p(5,.0) ' position
l(5,.0) ' length
i(1) ' input character
o ' output "character"
e(2) = chr("34") & chr("34") ' double double-quote
dqt: '*** double all double-quotes in Z ***
then: p = "1" ; t = z{"" ; l = len(t) ; z = ""
nxtchr:
then: i = mid(t,p,"1") ; o = i
if: asc(i) eq "34"
then: o = e
then: z = z & o
if: p lt l
then: p = p + "1" ; goto nxtchr
then: return ' dqt
--
bkw
More information about the Filepro-list
mailing list