* fpspreadsheet: cosmetic: comments; harmonize code layout with existing code

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3685 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
bigchimp
2014-10-24 10:46:04 +00:00
parent 5b9f31daca
commit c1102886cc
3 changed files with 52 additions and 47 deletions

View File

@ -29,6 +29,7 @@ begin
WriteLn('Opening input file ', InputFilename); WriteLn('Opening input file ', InputFilename);
// Tab-delimited
CSVParams.Delimiter := #9; CSVParams.Delimiter := #9;
CSVParams.QuoteChar := ''''; CSVParams.QuoteChar := '''';

View File

@ -224,7 +224,7 @@ function TsCSVReader.IsNumber(AText: String; out ANumber: Double;
out ACurrencySymbol, AWarning: String): Boolean; out ACurrencySymbol, AWarning: String): Boolean;
var var
p: Integer; p: Integer;
decsep, thsep: Char; DecSep, ThousSep: Char;
begin begin
Result := false; Result := false;
AWarning := ''; AWarning := '';
@ -248,33 +248,33 @@ begin
ACurrencySymbol := ''; ACurrencySymbol := '';
if CSVParams.AutoDetectNumberFormat then if CSVParams.AutoDetectNumberFormat then
Result := TryStrToFloatAuto(AText, ANumber, decsep, thsep, AWarning) Result := TryStrToFloatAuto(AText, ANumber, DecSep, ThousSep, AWarning)
else begin else begin
Result := TryStrToFloat(AText, ANumber, CSVParams.FormatSettings); Result := TryStrToFloat(AText, ANumber, CSVParams.FormatSettings);
if Result then if Result then
begin begin
if pos(CSVParams.FormatSettings.DecimalSeparator, AText) = 0 if pos(CSVParams.FormatSettings.DecimalSeparator, AText) = 0
then decsep := #0 then DecSep := #0
else decsep := CSVParams.FormatSettings.DecimalSeparator; else DecSep := CSVParams.FormatSettings.DecimalSeparator;
if pos(CSVParams.FormatSettings.ThousandSeparator, AText) = 0 if pos(CSVParams.FormatSettings.ThousandSeparator, AText) = 0
then thsep := #0 then ThousSep := #0
else thsep := CSVParams.FormatSettings.ThousandSeparator; else ThousSep := CSVParams.FormatSettings.ThousandSeparator;
end; end;
end; end;
// Try to determine the number format // Try to determine the number format
if Result then if Result then
begin begin
if thsep <> #0 then if ThousSep <> #0 then
ANumFormat := nfFixedTh ANumFormat := nfFixedTh
else else
ANumFormat := nfGeneral; ANumFormat := nfGeneral;
// count number of decimal places and try to catch special formats // count number of decimal places and try to catch special formats
ADecimals := 0; ADecimals := 0;
if decsep <> #0 then if DecSep <> #0 then
begin begin
// Go to the decimal separator and search towards the end of the string // Go to the decimal separator and search towards the end of the string
p := pos(decsep, AText) + 1; p := pos(DecSep, AText) + 1;
while (p <= Length(AText)) do begin while (p <= Length(AText)) do begin
// exponential format // exponential format
if AText[p] in ['+', '-', 'E', 'e'] then if AText[p] in ['+', '-', 'E', 'e'] then
@ -312,6 +312,7 @@ begin
ACurrencySymbol := ''; ACurrencySymbol := '';
end; end;
{ Checks if text is quoted; strips starting and ending quotes }
function TsCSVReader.IsQuotedText(var AText: String): Boolean; function TsCSVReader.IsQuotedText(var AText: String): Boolean;
begin begin
if (Length(AText) > 1) and (CSVParams.QuoteChar <> #0) and if (Length(AText) > 1) and (CSVParams.QuoteChar <> #0) and
@ -404,23 +405,24 @@ end;
procedure TsCSVReader.ReadFromStream(AStream: TStream; AData: TsWorkbook); procedure TsCSVReader.ReadFromStream(AStream: TStream; AData: TsWorkbook);
var var
parser: TCSVParser; Parser: TCSVParser;
begin begin
FWorkbook := AData; FWorkbook := AData;
FWorksheet := AData.AddWorksheet(FWorksheetName); FWorksheet := AData.AddWorksheet(FWorksheetName);
parser := TCSVParser.Create; Parser := TCSVParser.Create;
try try
parser.Delimiter := CSVParams.Delimiter; Parser.Delimiter := CSVParams.Delimiter;
parser.LineEnding := LineEndingAsString(CSVParams.LineEnding); Parser.LineEnding := LineEndingAsString(CSVParams.LineEnding);
parser.QuoteChar := CSVParams.QuoteChar; Parser.QuoteChar := CSVParams.QuoteChar;
parser.EqualColCountPerRow := false; // Indicate column counts between rows may differ:
parser.SetSource(AStream); Parser.EqualColCountPerRow := false;
while parser.ParseNextCell do Parser.SetSource(AStream);
ReadCellValue(parser.CurrentRow, parser.CurrentCol, parser.CurrentCellText); while Parser.ParseNextCell do
ReadCellValue(Parser.CurrentRow, Parser.CurrentCol, Parser.CurrentCellText);
finally finally
parser.Free; Parser.Free;
end; end;
end; end;
{ {
@ -476,13 +478,13 @@ end;
} }
procedure TsCSVReader.ReadFromStrings(AStrings: TStrings; AData: TsWorkbook); procedure TsCSVReader.ReadFromStrings(AStrings: TStrings; AData: TsWorkbook);
var var
stream: TStringStream; Stream: TStringStream;
begin begin
stream := TStringStream.Create(AStrings.Text); Stream := TStringStream.Create(AStrings.Text);
try try
ReadFromStream(stream, AData); ReadFromStream(Stream, AData);
finally finally
stream.Free; Stream.Free;
end; end;
end; end;
@ -521,6 +523,7 @@ begin
// nothing to do // nothing to do
end; end;
{ Write boolean cell to stream formatted as string }
procedure TsCSVWriter.WriteBool(AStream: TStream; const ARow, ACol: Cardinal; procedure TsCSVWriter.WriteBool(AStream: TStream; const ARow, ACol: Cardinal;
const AValue: Boolean; ACell: PCell); const AValue: Boolean; ACell: PCell);
begin begin
@ -548,7 +551,7 @@ begin
// AppendToStream(AStream, FWorksheet.ReadAsUTF8Text(ACell)); // AppendToStream(AStream, FWorksheet.ReadAsUTF8Text(ACell));
end; end;
{ CSV does not support formulas, but we have to write the formula results to { CSV does not support formulas, but we can write the formula results to
to stream. } to stream. }
procedure TsCSVWriter.WriteFormula(AStream: TStream; const ARow, ACol: Cardinal; procedure TsCSVWriter.WriteFormula(AStream: TStream; const ARow, ACol: Cardinal;
ACell: PCell); ACell: PCell);
@ -582,6 +585,7 @@ begin
// AppendToStream(AStream, s); // AppendToStream(AStream, s);
end; end;
{ Writes a number cell to the stream. }
procedure TsCSVWriter.WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; procedure TsCSVWriter.WriteNumber(AStream: TStream; const ARow, ACol: Cardinal;
const AValue: double; ACell: PCell); const AValue: double; ACell: PCell);
var var
@ -602,8 +606,8 @@ end;
procedure TsCSVWriter.WriteSheet(AStream: TStream; AWorksheet: TsWorksheet); procedure TsCSVWriter.WriteSheet(AStream: TStream; AWorksheet: TsWorksheet);
var var
r, c: Cardinal; r, c: Cardinal;
lastRow, lastCol: Cardinal; LastRow, LastCol: Cardinal;
cell: PCell; Cell: PCell;
begin begin
FWorksheet := AWorksheet; FWorksheet := AWorksheet;
@ -614,27 +618,27 @@ begin
FCSVBuilder.QuoteChar := CSVParams.QuoteChar; FCSVBuilder.QuoteChar := CSVParams.QuoteChar;
FCSVBuilder.SetOutput(AStream); FCSVBuilder.SetOutput(AStream);
lastRow := FWorksheet.GetLastOccupiedRowIndex; LastRow := FWorksheet.GetLastOccupiedRowIndex;
lastCol := FWorksheet.GetLastOccupiedColIndex; LastCol := FWorksheet.GetLastOccupiedColIndex;
for r := 0 to lastRow do for r := 0 to LastRow do
for c := 0 to lastCol do for c := 0 to LastCol do
begin begin
cell := FWorksheet.FindCell(r, c); Cell := FWorksheet.FindCell(r, c);
if cell <> nil then if Cell <> nil then
WriteCellCallback(cell, AStream); WriteCellCallback(Cell, AStream);
if c = lastCol then if c = LastCol then
FCSVBuilder.AppendRow; FCSVBuilder.AppendRow;
end; end;
finally finally
FreeAndNil(FCSVBuilder); FreeAndNil(FCSVBuilder);
end; end;
{ {
for r := 0 to lastRow do for r := 0 to LastRow do
for c := 0 to lastCol do begin for c := 0 to LastCol do begin
cell := FWorksheet.FindCell(r, c); Cell := FWorksheet.FindCell(r, c);
if cell <> nil then if Cell <> nil then
WriteCellCallback(cell, AStream); WriteCellCallback(Cell, AStream);
if c = lastCol then if c = LastCol then
AppendToStream(AStream, FLineEnding) AppendToStream(AStream, FLineEnding)
else else
AppendToStream(AStream, CSVParams.Delimiter); AppendToStream(AStream, CSVParams.Delimiter);
@ -654,15 +658,15 @@ end;
procedure TsCSVWriter.WriteToStrings(AStrings: TStrings); procedure TsCSVWriter.WriteToStrings(AStrings: TStrings);
var var
stream: TStream; Stream: TStream;
begin begin
stream := TStringStream.Create(''); Stream := TStringStream.Create('');
try try
WriteToStream(stream); WriteToStream(Stream);
stream.Position := 0; Stream.Position := 0;
AStrings.LoadFromStream(stream); AStrings.LoadFromStream(Stream);
finally finally
stream.Free; Stream.Free;
end; end;
end; end;

View File

@ -3398,7 +3398,7 @@ procedure TsWorksheet.Sort(const ASortParams: TsSortParams;
procedure QuickSort(L,R: Integer); procedure QuickSort(L,R: Integer);
var var
I,J,K: Integer; I,J: Integer;
P: Integer; P: Integer;
index: Integer; index: Integer;
options: TsSortOptions; options: TsSortOptions;