View Issue Details

IDProjectCategoryView StatusLast Update
0022182LazarusLCLpublic2012-06-09 19:28
ReporterNukool C.Assigned ToBart Broersma 
PrioritynormalSeveritymajorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version0.9.31 (SVN)Product Build 
Target VersionFixed in Version1.1 (SVN) 
Summary0022182: TStringGrid.LoadFromCSVFile: incorrect handling of unquoted spaces and quoted fields with delimiters
DescriptionIn MS Excel, I always select
delimiter = Comma
text qualifier = "
for example in csv file there are many commas like 58,073,560.23



StringGrid1.LoadFromCSVFile(OpenDialog1.FileName,',',true)

csv file ....

I t e m , D a t e , Q u o t a t i o n N o , A m o u n t
0 1 , 0 5 / 0 5 / 2 0 1 2 , Q T T 2 3 9 , " 3 , 6 2 4 , 9 9 7 . 3 1 "

StringGrid1 ...

I t e m D a t e Q u o t a t i o n N o A m o u n t
0 1 0 5 / 0 5 / 2 0 1 2 Q T T 2 3 9 3 , 6 2 4 , 9 9 7 . 3 1

It shows 1 character in 1 cell.

What should I do to solve this probem ?

Thank you in advance ...
TagsNo tags attached.
Fixed in Revisionr37499, r37598
LazTarget-
WidgetsetWin32/Win64
Attached Files

Relationships

related to 0019610 closedMarco van de Voort FPC TStringList.delimitedtext doesn't respect quotechar 

Activities

Jesus Reyes

2012-06-03 10:41

developer   ~0060212

There seems to be something wrong with your sample cvs data, there are spaces between each character, there may be several explanations but....
It would be much better if you attach the sample csv file to this report

Juha Manninen

2012-06-03 12:53

developer   ~0060216

See also :
  http://lazarus.freepascal.org/index.php/topic,17113.msg93955.html

Bart Broersma

2012-06-03 14:32

developer   ~0060220

Please test and close if OK.

Jesus Reyes

2012-06-03 20:49

developer   ~0060237

I could test, but there is not cvs test file, please on next time when there is a problem when reading some file, please don't forget to ask for the file, I think there is nothing wrong in pasting some sample csv data, but as I said, they don't look normal and a paste will never sustitute a physical file, because of the BOM's, Encodings, etc.

Anyway, I followed the link to the mentioned topic and I probably wasn't careful enough, but I can't find a test csv file, just a repetition of what this bug report contains.

BTW, the original csv support in grids worked fine with anything I throw it, and if it doesn't effectively worked fine, then the probability that is a FPC problem is higher. While it's not bad to have temporal fix in LCL, a patch to fix the problem must be supplied to FPC and eventually the temporal fix removed from LCL.

But all this must be clear in order to better know how to proceed.

Bart Broersma

2012-06-04 09:57

developer   ~0060246

@Jesus: First there was an error when reading Tab-separated files: spaces were treated as delimiter.
So I changed behaviour to use StrictDelimiter := True.
This however introduced the behaviour described by Nukool C.
Quoted fields which contain delimiter are split on the delimiter.
This is wrong.

var
  SL: TStringList;
....
  SL.Delimiter := ',';
  SL.StrictDelimiter := True;
  SL.DelimitedText := '01,05/05/2012,QTT239,"3,624,997.31"';

Gives:

01
05/05/2012
QTT239
"3
624
997.31"

I cannot test if this is Delphi compatible or not, since my old Delphi (3) doesn't have DelimitedText.

The new implementation is a bit more forgiving when reading the data.
It now allows for spaces in unquoted fields (which effectively mostly is the case in Tab separated files), and it reverts the wrong handling of quoted fields with delimters inside.

Bart Broersma

2012-06-08 14:00

developer   ~0060377

Not quit fixed yet with regard to leading and trailing spaces in unquoted fields. (See discussion on forum and related issue 0019610).

Issue History

Date Modified Username Field Change
2012-06-03 02:51 Nukool C. New Issue
2012-06-03 02:51 Nukool C. Widgetset => Win32/Win64
2012-06-03 10:36 Jesus Reyes Status new => assigned
2012-06-03 10:36 Jesus Reyes Assigned To => Jesus Reyes
2012-06-03 10:41 Jesus Reyes LazTarget => -
2012-06-03 10:41 Jesus Reyes Note Added: 0060212
2012-06-03 10:41 Jesus Reyes Status assigned => feedback
2012-06-03 12:53 Juha Manninen Note Added: 0060216
2012-06-03 14:32 Bart Broersma Fixed in Revision => r37499
2012-06-03 14:32 Bart Broersma Status feedback => resolved
2012-06-03 14:32 Bart Broersma Fixed in Version => 1.1 (SVN)
2012-06-03 14:32 Bart Broersma Resolution open => fixed
2012-06-03 14:32 Bart Broersma Note Added: 0060220
2012-06-03 14:33 Bart Broersma Status resolved => assigned
2012-06-03 14:33 Bart Broersma Assigned To Jesus Reyes => Bart Broersma
2012-06-03 14:34 Bart Broersma Status assigned => resolved
2012-06-03 20:49 Jesus Reyes Note Added: 0060237
2012-06-04 09:57 Bart Broersma Note Added: 0060246
2012-06-07 21:20 Marco van de Voort Relationship added related to 0019610
2012-06-08 14:00 Bart Broersma Status resolved => assigned
2012-06-08 14:00 Bart Broersma Resolution fixed => reopened
2012-06-08 14:00 Bart Broersma Note Added: 0060377
2012-06-08 14:04 Bart Broersma Summary StringGrid1.LoadFromCSVFile(OpenDialog1.FileName,',',true) does not work. => TStringGrid.LoadFromCSVFile: incorrect handling of unquoted spaces and quoted fields with delimiters
2012-06-09 19:27 Bart Broersma Fixed in Revision r37499 => r37499, r37598
2012-06-09 19:27 Bart Broersma Status assigned => resolved
2012-06-09 19:27 Bart Broersma Resolution reopened => fixed