Problem with Export to CSV
Page 1 of 1

Author:  sirwhale [ 12 Aug 2022, 01:56 ]
Post subject:  Problem with Export to CSV

I try to export data from grid to CSV but result was flawed.
Data was exported as one single line without any end of line.
There was 5 CRLF at file begining after that all data in one single line.
Check attached file.
  if SaveDialog1.Execute(Handle) then
    SaveDBGridEhToExportFile(TDBGridEhExportAsCSV, dbgData,
      SaveDialog1.FileName, True);

CPTreport.7z [301 Bytes]
Downloaded 23 times

Author:  souarit [ 13 Aug 2022, 19:07 ]
Post subject:  Re: Problem with Export to CSV

from help file :


so ...use SaveDBGridEhToTextFile method.

procedure TForm1.Button4Click(Sender: TObject);
  Grid: TDBGridEh;
  Path: String;
  FileName: String;
ExportOptions: TDBGridEhTextExportOptions;

  ExportOptions := TDBGridEhTextExportOptions.Create;
  ExportOptions.IsExportTitle := True;   // columns titles
  ExportOptions.IsExportFooter := False;
  ExportOptions.Encoding := TEncoding.UTF8;
  ExportOptions.WriteBOM := True;
  ExportOptions.QuoteChar := '"';
  ExportOptions.CellDelimiter :=  ';';
  ExportOptions.TrailingLineDelimiter := True;
  ExportOptions.UseEditFormat := False;
  ExportOptions.LineDelimiter :=  sLineBreak;

  FileName := Path + '\DBGridEh1Export.csv';

  SaveDBGridEhToTextFile(DBGridEh, FileName, ExportOptions);

  ShellExecute(Handle, nil, PChar(FileName), nil, nil, SW_SHOWNORMAL);


TDBGridEhStringExportOptions class contains the following properties :

property ExportSelecting: Boolean;
Specifies to unload only the selected grid area. If property = False, then the entire grid will be unloaded regardless of the presence of the selected MultiSelect area.

property CellDelimiter: String;
A string separator of cells. Default #9 (Tab code).

property LineDelimiter: String;
Line separator string. The default is sLineBreak.

property TrailingLineDelimiter: Boolean;
The property specifies whether to unload the line separator after the last unloaded line.

property QuoteChar: Char;

Use QuoteChar to get or set the quote character that is used to enclose individual cell values if the value contains a substring that matches the value of the CellDelimiter, LineDelimiter, or QuoteChar property.

property IsExportTitle: Boolean;
The property specifies whether to write the column headings in the first row of the export.

property IsExportFooter: Boolean;
The property specifies whether to unload grid footers after unloading the split data.

property UseEditFormat: Boolean;
The property specifies that when receiving cell data as a string for numeric data and DateTime data, the string format used when editing the cell must be used. If property = False, then Column.DisplayFormat property will be used for formatting.

property FormatSettings: TFormatSettings;
The property specifies the format for numeric and DateTime values to be used when converting numbers and dates to text.

property UseFormatSettings: Boolean;
Set the property to True to indicate that the FormatSettings property should be used when converting numeric data.

property ExportColumns: TColumnsEhList;
List of columns to be exported. If the property is not filled, then all visible rows of the grid will be exported.

The TDBGridEhTextExportOptions class inherits from the TDBGridEhStringExportOptions class and has the following additional properties.

property Encoding: TEncoding;
The property specifies the character encoding that will be used when writing the exported data string to a stream or file.

property WriteBOM: Boolean;
Set the property to True to indicate to the algorithm that when writing data to a stream, a Byte Order Mark must be written to the beginning of the stream, which contains the encoding code in which the text data was written. For a description of the Byte Order Mark, see here:

Author:  EhLibSupport [ 13 Aug 2022, 21:15 ]
Post subject:  Re: Problem with Export to CSV


We tested SaveDBGridEhToExportFile(TDBGridEhExportAsCSV...) on a simple Demo project and found no export issues.
EhLib 10.2.030, Delphi 11 Update 1.
Perhaps the problem depends on the grid settings, library version and Delphi.

Please write your version of the library and Delphi.
Please send a simple demo project in which the problem is reproduced.

sshot-254.png [ 54.68 KiB | Viewed 229 times ]

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group