Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 07 Oct 2022, 08:13

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 12 Aug 2022, 01:56 
Offline

Joined: 16 May 2019, 12:00
Posts: 1
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.
Image
Code:
  if SaveDialog1.Execute(Handle) then
  begin
    SaveDBGridEhToExportFile(TDBGridEhExportAsCSV, dbgData,
      SaveDialog1.FileName, True);
  end;


Attachments:
CPTreport.7z [301 Bytes]
Downloaded 20 times
Top
 Profile  
 
PostPosted: 13 Aug 2022, 19:07 
Offline

Joined: 29 Oct 2013, 11:58
Posts: 12
from help file :

Image


so ...use SaveDBGridEhToTextFile method.


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

begin
  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;


  GetDir(0,Path);
  FileName := Path + '\DBGridEh1Export.csv';

  SaveDBGridEhToTextFile(DBGridEh, FileName, ExportOptions);
  ExportOptions.Free;

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

end;





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: https://en.wikipedia.org/wiki/Byte_order_mark


Last edited by souarit on 13 Aug 2022, 21:39, edited 2 times in total.

Top
 Profile  
 
PostPosted: 13 Aug 2022, 21:15 
Offline

Joined: 08 May 2014, 18:06
Posts: 560
Hello

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.


Attachments:
sshot-254.png
sshot-254.png [ 54.68 KiB | Viewed 165 times ]

_________________
Best regards
EhLib Support Team
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group