Skip to content

Commit f951b78

Browse files
committed
fix: wrong BOM characters written to grid export files, when encoding is set to "UTF-8 BOM" for instance
1 parent d34be7f commit f951b78

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

source/exportgrid.pas

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,13 +699,14 @@ procedure TfrmExportGrid.btnOKClick(Sender: TObject);
699699

700700
// Prepare stream
701701
// Note that TStringStream + TEncoding.UTF8 do not write a BOM (which is nice),
702-
// although it should do so according to TUTF8Encoding.GetPreamble.
702+
// although it has a property TUTF8Encoding.GetPreamble.
703703
// Now, only newer Excel versions need that BOM, so we add it explicitly here
704704
// P.S.: Note the boolean/False parameter for OwnsEncoding, so our global encodings are not destroyed after usage
705705
S := TStringStream.Create('', Encoding, False);
706-
if (CurrentExportFormat = efExcel) and (Encoding = TEncoding.UTF8) and radioOutputFile.Checked then begin
707-
Bom := TBytes.Create($EF, $BB, $BF);
708-
S.Write(Bom, 3);
706+
if radioOutputFile.Checked then begin
707+
Bom := Encoding.GetPreamble;
708+
if Length(Bom) > 0 then
709+
S.WriteBuffer(Bom[0], Length(Bom));
709710
end;
710711

711712
Header := '';

0 commit comments

Comments
 (0)