[fpc-pascal] Issue with CSVDocument
James Richters
james.richters at productionautomation.net
Mon Feb 7 14:27:38 CET 2022
I have CSVDocument working, but something odd is happening.
Everything is coming out as I expect, Except for the first cell.. it has some garbage at the beginning of it that I don't understand.
I'm on a Windows 10 64bit PC running the Win32 FPC Trunk installed today with fpcdeluxe.
Here's my code:
Uses Math,sysutils,Classes,CSVDocument;
Var
LoopRow,LoopCol:DWord;
CSVData : TCSVDocument;
Begin
If ParamCount>=1 Then
Begin
Writeln('Input From File: ',Paramstr(1));
If FileExists(ParamStr(1)) Then
Begin
CSVData:=TCSVDocument.Create;
CSVData.LoadFromFile(ParamStr(1));
Writeln('Read In: ',CSVData.RowCount,' Rows and ',CSVData.MaxColCount,' Columns');
Writeln('Press Enter to Process');
Readln;
If CSVData.RowCount >0 Then
Begin
For LoopRow := 0 to CSVData.RowCount-1 Do
Begin
Write('| ');
For LoopCol := 0 to CSVData.ColCount[LoopRow]-1 Do
Begin
Write(CSVData.Cells[LoopCol,LoopRow]+' | ');
End;
Writeln;
End;
End;
CSVData.Free;
End
Else
Begin
Writeln('File Not Found');
End;
End;
End.
Here's the output:
Input From File: x:\all_2x4s.csv
Read In: 88 Rows and 3 Columns
Press Enter to Process
| Divisions 2x4 CBC B-C1 | 30.56 | 50 |
| Divisions 2x4 CBC B-C2 | 30.56 | 50 |
| Divisions 2x4 CBC C1-C2 | 28.2 | 50 |
| Divisions 2x4 CDF C2-D1 | 34.89 | 40 |
| Divisions 2x4 CDF C2-F | 30.42 | 40 |
| Divisions 2x4 CDF D1-F | 33.47 | 40 |
Here's the top of my CSV File as created by Excel:
Divisions 2x4 CBC B-C1,30.56,50
Divisions 2x4 CBC B-C2,30.56,50
Divisions 2x4 CBC C1-C2,28.2,50
Divisions 2x4 CDF C2-D1,34.89,40
Divisions 2x4 CDF C2-F,30.42,40
Divisions 2x4 CDF D1-F,33.47,40
I don't understand where the  came from or how to get rid of it.
I've tried several CSV files, and even tried just typing a sample out with a text editor.. all have  in the first cell
Anyone have any ideas?
James
More information about the fpc-pascal
mailing list