Welcome! Log In Create A New Profile

Advanced

problem reading CSV file

Posted by rdj 
rdj
problem reading CSV file
September 15, 2021 12:45PM
Hi,

I get a CSV file created from an application X. I can read and open this CSV file with
freadline no problem

from another application Y I also get a CSV file when I try to process this it is not working
Not with freadline nor with floadtext
in both cases it tells me there is only 1 line in the CSV file (and there are many more)
I can open this with Excel and convert it to Excel that is not the problem (there you go through the CSV converting process)
I can open the file as a 'txt-file' and it is normally readable.
Converting to XLS is now a workaround only not where I am looking for.
What could be the problem causing this and how can I solve this on my side (because exports from Application X and Y are standard functionality)

kind regards,

RdJ
Windev 2024/Webdev 2024
pao
Re: problem reading CSV file
September 15, 2021 01:29PM
Check the end of line char on each file, probably one have CR and the other CRLF, you can open the files using notepad++ and you will see this chars.

if this is true, you can use something like this (not tested):
// Read a data file in TXT (import)

sFileContent is string
sLine is string

// Load the file content in memory
sFileContent = fLoadText("ImportProducts.txt")

FOR EACH STRING sLine OF sFileContent SEPARATED BY charact(10)
// Process the line
...
END

Regards

Paulo Oliveira



Edited 2 time(s). Last edit at 09/15/2021 01:46PM by pao.
rdj
Re: problem reading CSV file
September 15, 2021 03:58PM
thanks, that was the trick.

kind regards,

RdJ
Windev 2024/Webdev 2024
pao
Re: problem reading CSV file
September 15, 2021 04:14PM
If you want to use the FREADLINE instead of FLOADTEXT use the separator option.
[doc.windev.com]

Regards

Paulo Oliveira
Re: problem reading CSV file
September 15, 2021 05:43PM
Hi

This depends on the locale of your Windows and the separators defined in the source system or on the source platform.
Typically for a Belgian or French locale (Windows Regional Settings) the list separator is a “;” while in the source system where the csv was generated it could be by standard be defined as “,”.

Excel uses the locale of the Windows context. So in case you change the list separator in your regional settings to “,” it will work differently.
So if in your locale you define the list separator to be a pipe “|”, Excel will save csv as fields separated by a pipe “|” and the record separator as CRLF (Windows standard).

CSV is not an Excel native format or a standardised format.
It’s just a list separated (“,”,”;”,”|”,..), record separated (“CR”,”LF”,”CRLF”) ASCII flat file format.

So ideally, in any csv parser you can define the field separator as well as the record separator to cover all cases...

My 2 cents on the topic

Peter Holemans
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: