About DBGRIDEH Export data to CSV

zhaozj2021-02-16  56

In normal case, the data from the CSV exported to CSV is like this.

"a", "b", "c"

Maybe we don't want it to display like this, it is possible to see it as a state

A, B, C

If you want this, we can modify the dbgridehimpexp.pas file inside DBGRIDEH.

The specific modifications are as follows: Add a class that exported to CSV

{TMyDBGridEhExportAsCVS} TMyDBGridEhExportAsCVS = class (TDBGridEhExportAsText) private FSeparator: Char; protected procedure CheckFirstCell; override; procedure WriteTitle (ColumnsList: TColumnsEhList); override; procedure WriteDataCell (Column: TColumnEh; FColCellParamsEh: TColCellParamsEh); override; procedure WriteFooterCell (DataCol, Row : Integer; Column: TColumnEh; aFont: TFont; Background: TColor; Alignment: TAlignment; Text: String); override; public constructor Create; override; property Separator: Char read FSeparator write FSeparator; end; {TMyDBGridEhExportAsCVS} procedure TMyDBGridEhExportAsCVS.CheckFirstCell Var s: string; begin if firstCell = false damwritestring (stream, s); // stream.write (pchar (s) ^, Length (s)) end else firstcell: = false; End CONSTRUCTOR TMYDBGRIDEHEXPORTASCVS.CREATE; Begin Separator: = ','; Inherited Create; End; Procedure TmydbGrideHexportascvs.WriteDataCell (Column: Tcolumneh; Fcol CellParamsEh: TColCellParamsEh); var s: String; begin CheckFirstCell; s: = FColCellParamsEh.Text; StreamWriteString (Stream, s); // Stream.Write (PChar (s) ^, Length (s)); end; procedure TMyDBGridEhExportAsCVS. WriteFooterCell (DataCol, Row: Integer; Column: TColumnEh; aFont: TFont; Background: TColor; Alignment: TAlignment; Text: String); var s: String; begin CheckFirstCell; s: = Text; StreamWriteString (Stream, s); / / stream.Write (PChar (s) ^, Length (s)); end; procedure TMyDBGridEhExportAsCVS.WriteTitle (ColumnsList: TColumnsEhList); var i: Integer; s: String; begin CheckFirstRec; for i: = 0 to ColumnsList.Count - 1 Do Begin S: = ColumnList [i] .title.caption; if i <>

Columnlist.count - 1 THEN S: = S Separator; Streamwritestring (stream, s); // stream.write (pchar (s) ^, length (s)); end; end; good luck!

转载请注明原文地址:https://www.9cbs.com/read-19490.html

New Post(0)