Author Topic: fpSpread and CSV  (Read 199 times)


  • Full Member
  • ***
  • Posts: 190
fpSpread and CSV
« on: August 07, 2020, 06:01:50 pm »
May I know whether the following are the normal behaviour, or is there anything wrong with my installation  (eg. wrong version) :-

1. WriteToFile(csvname, sfCSV) -- output files are separated by ';' (semi-colon) instead of comma.  Similarly, ReadFromFile method assumes the separator is ';' ?  (unless I set  CSVParams.Delimiter := ',')

2. ReadFromFile method cannot correctly read utf8-csv file unless I set CSVParams.Encoding to 'utf8'. I thought the reader will detect the encoding automaticaly by default?

Thank you.


  • Hero Member
  • *****
  • Posts: 7620
Re: fpSpread and CSV
« Reply #1 on: August 07, 2020, 07:06:46 pm »
(1) The CSVOptions work like a "state machine". You change one settings, and it will be used for all read/write operations until you change it again. Since reading and writing of CSV share the same delimiter your observation is correct.

(2) Since CSV files do not contain information about the encoding (except for the BOM in some cases) there is no way how to detect the encoding (without a complex semantic analysis). This is the order of priorities, taken from the fpsCSV source:
Code: Pascal  [Select][+][-]
  1.   if CSVParams.Encoding = '' then
  2.     encoding := GuessEncoding(s)
  3.   else
  4.     encoding := CSVParams.Encoding;
  5.   if encoding = '' then
  6.     encoding := DEFAULT_ENCODING;  
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...


TinyPortal © 2005-2018