PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → CSV File Processing
CSV File Processing
Iniciado por guest, 22,may. 2017 22:33 - 3 respuestas
Publicado el 22,mayo 2017 - 22:33
I come from the Clarion environment where CSV files are handled with the Analysis (Dictionary) and I haven't quite grasped the way to do it using Windev. Can someone out there pleezz throw me a lifeline and send me some code samples . . .
Publicado el 22,mayo 2017 - 23:22
Hey Jose,

Take a look at my sample solution in the windev solutions section of this forum
Miembro registrado
34 mensajes
Publicado el 02,junio 2017 - 15:57
Clarion lets you get away with blue murder when importing CSV files. It is a strong point that I wish was in Windev. We have to do a little more using HImportText and watch out for the delimiters.

"1","apple","pear","orange" and 1,apple,pear,orange are the same to Clarion but not in Windev. If you try to push a numeric into a string field or a string into a numeric field then it won't like it.

I always import CSV files into a temporary Windev file as strings before moving it into my real data. I can then parse it for junk so that it does not contaminate the database or crash the program.

One gem that comes up is where some bright spark puts a comma in one of the fields (usually in addresses) like "21, The Street","Anytown","Any Place"

As I had to deal with a load of third-party produced CSV files, which were of varying quality, in the end I wrote a program that parses the CSV file and reads a record at a time, it then reads each line character by character and looks for quotes, it counts the quotes and if it's an odd number then it replaces any following comma with a space character. It then simply saves the result into a large string. At the end if I want to get rid of all the quotes I just use the command REPLACE to replace the charact(34) with a blank space and save the string as a file. You can handle very large CSV files in no time.

--
Regards,

Norman
Publicado el 02,junio 2017 - 16:54
Hi Norman

I can do you one better... :-(

I had to work with csv files coming from commence, where each text field
could contain the field separator (comma) AND the line separator (CR)...

So I had to build a parser working the whole file character by character
and using logic to determine if a comma or a CR was part of the content,
or was a separator...

I made it work, but as a result of all the tests I had to do, the result
was quite slow.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


Le 6/2/2017 à 7:57 AM, Attlebax a écrit :
Clarion lets you get away with blue murder when importing CSV files. It
is a strong point that I wish was in Windev. We have to do a little more
using HImportText and watch out for the delimiters.

"1","apple","pear","orange" and 1,apple,pear,orange are the same to
Clarion but not in Windev. If you try to push a numeric into a string
field or a string into a numeric field then it won't like it.
I always import CSV files into a temporary Windev file as strings before
moving it into my real data. I can then parse it for junk so that it
does not contaminate the database or crash the program.

One gem that comes up is where some bright spark puts a comma in one of
the fields (usually in addresses) like "21, The Street","Anytown","Any
Place"

As I had to deal with a load of third-party produced CSV files, which
were of varying quality, in the end I wrote a program that parses the
CSV file and reads a record at a time, it then reads each line character
by character and looks for quotes, it counts the quotes and if it's an
odd number then it replaces any following comma with a space character.
It then simply saves the result into a large string. At the end if I
want to get rid of all the quotes I just use the command REPLACE to
replace the charact(34) with a blank space and save the string as a
file. You can handle very large CSV files in no time.

--
Regards,

Norman