[Answered by wp] Saved csf file codepage problem lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- totya · 2018-03-18 20:24 Hi! When I save WorksheetGrid to csv file, the produced csv file codepage is wrong, because the exel (2007) opened incorrectly. It seems to mee, the produced csv file codepage is "UTF8 without boom" but excel need as I see: "UTF8 with boom". Thank you! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,  fpspreadsheetgrid; type   { TForm1 }   TForm1 = class(TForm)    sWorksheetGrid1: TsWorksheetGrid;    procedure FormCreate(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  with sWorksheetGrid1 do  begin    sWorksheetGrid1.Worksheet.WriteText(0,0,'öüóőúéáűíÖÜÓŐÚÉÁŰÍ');    sWorksheetGrid1.SaveToSpreadsheetFile('test.csv');  end;end; end.  Edit.: But it seems to me, save csv file with ANSI codepage is better, because if I open "; tagged" (csv file) utf8 (with boom) file in Excel, then I save again, the result: ";" changed to tabulator. LOL. ---------------------------------------------------------------------- wp · 2018-03-18 21:36 Since csv has so many "undefined" options fpspreadsheet declares a global record CSVParams in unit fpscsv in which you can define specific parameters: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TsCSVParams = record   // W = writing, R = reading, RW = reading/writing    SheetIndex: Integer;             // W: Index of the sheet to be written    LineEnding: TsCSVLineEnding;     // W: Specification for line ending to be written    Delimiter: Char;               // RW: Column delimiter    QuoteChar: Char;                 // RW: Character for quoting texts    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    AutoDetectNumberFormat: Boolean; // R: automatically detects decimal/thousand separator used in numbers    TrueText: String;              // RW: String for boolean TRUE    FalseText: String;             // RW: String for boolean FALSE    FormatSettings: TFormatSettings; // RW: add'l parameters for conversion  end;   var  CSVParams: TsCSVParams = (    SheetIndex: 0;    LineEnding: leSystem;    Delimiter: ';';    QuoteChar: '"';    Encoding: '';    // '' = auto- detect when reading, UTF8 when writing    DetectContentType: true;    NumberFormat: '';    AutoDetectNumberFormat: true;    TrueText: 'TRUE';    FalseText: 'FALSE';  ); Therefore, you can fine-tune the encoding of the file you just have to adjust CSVParams.Encoding accordingly before writing. So, if Excel wants "UTF8 with BOM", set CSVParams.Encoding := 'utf8bom', or set CSVParams.Encoding := 'cp1252' to write an ANSI file in the central- European codepage. See also: http://wiki.lazarus.freepascal.org/FPSpreadsheet#Reading_and _writing_of_CSV_files ---------------------------------------------------------------------- totya · 2018-03-18 22:04 Hi! Very thank you for answer! I can try only tomorrow, but I suggest, change the default csv codepage from utf8-without-boom to utf8-with-boom. Why? Because I try open this csv file open from LibreOffice (v5.2.2.2) too, and codepage- detect is bad again. With utf8 with boom, the libre office autodetect is OK, like as Excel 2007. Thank you! ---------------------------------------------------------------------- wp · 2018-03-18 23:11 At first I thought: Good idea, and uploaded a new version with utf8bom as default encoding for CSV files. But then I changed my mind and reverted this: fpspreadsheet is a library spreadsheet files, so if you want to create data for Excel or Calc you would of course write in their native format, not in the crooked CSV. On the other hand, if you write CSV files it is most probably for other programs, and I estimate that most of them will not expect to have a BOM at the beginning of a text file. Delphi 7, for example, chokes if you load a UTF8-BOM source file. Luckily the situation is very flexible. If your program is supposed to write a CSV for Excel/Calc just change CSVParams.Encoding to 'utf8bom'. ---------------------------------------------------------------------- totya · 2018-03-18 23:13 Hi! I see, you changed the default codepage, and later you changed back... but no problem, these lines: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ...fpscsv...  and Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i CSVParams.Encoding:= 'cp1250';  ... solve my problem. And yes, my need cp1250 codepage, and not cp1252. With cp1252 few chars missing, see demo app in the first message. Thank you for all, master! ps.: Why I need csv file? Because I can compare excel files easily...