From 7905e5a72e854bdbc0695ec6522a5989956b33d3 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 7 Feb 2023 16:54:19 +0000 Subject: [PATCH] fpspreadsheet: Support the csv reader/writer options IgnoreOuterWhiteSpace and QuoteOuterWhiteSpace (see https://forum.lazarus.freepascal.org/index.php/topic,62151.0.html) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8696 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/source/common/fpscsv.pas | 2 ++ components/fpspreadsheet/source/common/fpstypes.pas | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/components/fpspreadsheet/source/common/fpscsv.pas b/components/fpspreadsheet/source/common/fpscsv.pas index d1162979b..4fe898df6 100644 --- a/components/fpspreadsheet/source/common/fpscsv.pas +++ b/components/fpspreadsheet/source/common/fpscsv.pas @@ -187,6 +187,7 @@ begin Parser.Delimiter := CSVParams.Delimiter; Parser.LineEnding := LineEndingAsString(CSVParams.LineEnding); Parser.QuoteChar := CSVParams.QuoteChar; + Parser.IgnoreOuterWhiteSpace := CSVParams.IgnoreOuterWhiteSpace; // Indicate column counts between rows may differ: Parser.EqualColCountPerRow := false; Parser.SetSource(AStream); @@ -345,6 +346,7 @@ begin FCSVBuilder.Delimiter := CSVParams.Delimiter; FCSVBuilder.LineEnding := LineEndingAsString(CSVParams.LineEnding); FCSVBuilder.QuoteChar := CSVParams.QuoteChar; + FCSVBuilder.IgnoreOuterWhiteSpace := CSVParams.IgnoreOuterWhiteSpace; FCSVBuilder.SetOutput(AStream); n := sheet.GetCellCount; diff --git a/components/fpspreadsheet/source/common/fpstypes.pas b/components/fpspreadsheet/source/common/fpstypes.pas index 559145391..d0b1abf72 100644 --- a/components/fpspreadsheet/source/common/fpstypes.pas +++ b/components/fpspreadsheet/source/common/fpstypes.pas @@ -92,6 +92,8 @@ type @member LineEnding Specification for the line endings to be written (write-only) @member Delimiter Column delimiter (read/write) @member QuoteChar Character used for quoting text in special cases (read/write) + @member QuoteOuterWhiteSpace ...Determines whether cell content beginning/ending with white space will be quoted (write-only) + @member IgnoreOuterWhiteSpace...Ignores white space before/after cell content (read-only) @member Encoding String identifying the endoding of the file, such as 'utf8', 'cp1252' etc (read/write) @member DetectContentType Try to convert strings to their content type (read-only) @member NumberFormat If empty numbers are written like in worksheet, otherwise this format string is applied (write-only) @@ -104,6 +106,8 @@ type LineEnding: TsCSVLineEnding; // W: Specification for line ending to be written Delimiter: Char; // RW: Column delimiter QuoteChar: Char; // RW: Character for quoting texts + QuoteOuterWhiteSpace: Boolean; // W: Quote when cell content begins/ends with white space. + IgnoreOuterWhiteSpace: Boolean; // R: Ignores white space before/after cell content. Encoding: String; // RW: Encoding of file (code page, such as "utf8", "cp1252" etc) DetectContentType: Boolean; // R: try to convert strings to content types NumberFormat: String; // W: if empty write numbers like in sheet, otherwise use this format @@ -203,6 +207,8 @@ var LineEnding: leSystem; Delimiter: ';'; QuoteChar: '"'; + QuoteOuterWhiteSpace: true; + IgnoreOuterWhiteSpace: false; Encoding: ''; // '' = auto-detect when reading, UTF8 when writing DetectContentType: true; NumberFormat: '';