CSV import into StringGrid omits first line
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
As discussed in the forum (http://forum.lazarus.freepascal.org/index.php/topic,28932.msg181815.html#msg181815) the CSV import into a StringGrid fails to import the first data line if the parameter WithHeaders is false. See attached screenshot of the import of this data file:
1;Smith;Jim;Utah;111-111111
2;Adams;Joshua;New York;222-222222
3;Woodbridge;James;Alabama;333-333333
4;Woodgate;John;North Carolina;444-444444
5;Hamilton;Steven;Louisiana;555-555555
It is seen that the first line is missing in each of the two grid of this demo (the first grid uses predefined columns, while the second one does not).
The provided patch fixes this issue. In addition it takes care of cases when the data file contains text to be ignored above the import lines.
Steps to reproduce:
The attached demo project shows the issue with the current version of Lazaraus, and it can be used to verify the improvements due to this patch.
Several data files are provided for the test; all of them contain 5 data lines like in the example above.
"NoHeader_0.txt" - no header line, data start immediately at the top
"NoHeader_1.txt" - no header line, 1 additional line to be ignored above the first data line
"NoHeader_2.txt" - no header line, 2 additional lines to be ignored above the first data line
"Header_0.txt" - a header line immediately at the top, data lines follow
"Header_1.txt" - one line to be ignored, then the header line, then the data lines
"Header_2.txt" - two lines to be skipped, then the header line, then the data lines
The demo program contains a combobox for selecting one of these input files. The parameter "WithHeaders" of the grid's method "LoadFromCVSFile" is set according to the state of the checkbox "File with headers". In addition, the combobox "Skip..." allows to skip no, one or two data lines above the imported lines (used by the patched version only!)
To reproduce the described behavior and the screenshot, load the file "NoHeader_0.txt" and uncheck the "WithHeaders" box.
In addition, load "No_Header_1.txt" or "NoHeader_2.txt" --> the dummy lines are imported as well which is not expected.
Load "Header_1.txt" with "File with Header" checked --> the predefined headers of the upper grid are partly overwritten by the dummy text, the headers of the lower grid (no predefined headers) are not detected correctly as well.
Apply the patch and repeat the tests. The patch introduces an additonal (optional) parameter "SkipLines" to the "LoadFromCSVFile" method which can be selected in the gui by means of the "Skip..." combobox.
Whenever the parameters selected by "File with header" and "Skip..." match the structure of the file the data are corrected imported.
Mantis conversion info:
- Mantis ID: 28582
- Version: 1.5 (SVN)
- Fixed in version: 1.5 (SVN)
- Fixed in revision: 49735 (#0ca49a5f), 49754 (#3a209ed4)
- Monitored by: » @flyingsheep (Bart Broersma)
- Target version: 1.6