Recent

Author Topic: RxDBGrid export to .xls/xlsx  (Read 1309 times)

flori

  • Full Member
  • ***
  • Posts: 196
RxDBGrid export to .xls/xlsx
« on: February 19, 2021, 05:37:06 pm »
Hi everyone!
i have a little demo which can export rxdbgrid contents to .xls file. The dbgrid cells has background yellow that write 'dust'
When I export dbgrid conent after I don't see it cells color on xls. (i only see it in dbrgird orange cells)
does anyone know why this is? I set RxDBGridExportSpreadSheet : export color =true

export button:
 
Code: Pascal  [Select][+][-]
  1.  if SaveDialog1.Execute then
  2.     begin
  3.      RxDBGridExportSpreadSheet1.FileName:=SaveDialog1.FileName;
  4.      RxDBGridExportSpreadSheet1.Execute;
  5.     end;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.RxDBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
  2.   Column: TColumn; AState: TGridDrawState);
  3.  
  4.   begin
  5.   if Column.FieldName='TYPE' then
  6. begin
  7. if Column.Field.AsString='dust' then
  8. begin
  9. with (Sender As TRxDBGrid) do
  10. begin
  11.  
  12.   Canvas.Brush.Color:=clYellow;
  13.   Canvas.Font.Color:=clRed;
  14.   Canvas.Font.Style:=[fsBold];
  15. end;
  16. end;
  17. end;
  18. end;

flori

  • Full Member
  • ***
  • Posts: 196
Re: RxDBGrid export to .xls/xlsx
« Reply #1 on: February 19, 2021, 08:29:17 pm »
'dust'  red color cell is not show in excel :(

Code: Pascal  [Select][+][-]
  1. procedure TForm1.RxDBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
  2.   Column: TColumn; AState: TGridDrawState);
  3. begin
  4.    if (Sender as TRxDBGrid).Datasource.Dataset.Fields[1].AsString='dust' then
  5.   begin
  6.     (Sender as TRxDBGrid).Canvas.Font.Style:=[fsBold];
  7.     (Sender as TRxDBGrid).Canvas.Brush.Color:=clred;
  8.   end;
  9. end;
« Last Edit: February 19, 2021, 09:34:45 pm by flori »

lfyey121

  • Newbie
  • Posts: 5
Re: RxDBGrid export to .xls/xlsx
« Reply #2 on: April 12, 2025, 12:41:20 pm »
When RxDbGridExportSpreadSheet export excel, if the field type is FMTBCD, then export the column is a text format rather than numerical format. If ftfmtbcd is added to NumericDataTypes in rxdbutils unit, it can be exported to numeric format:
  NumericDataTypes = IntegerDataTypes + [ftFloat, ftCurrency, ftBCD, ftfmtBCD];

 

TinyPortal © 2005-2018