Hello
I have used the ExcelIO component to export a colour coded DB Grid (ADvDbGrid component). However, the exported file always set the first row no colour coding as per the Grid it is exporting. I have tried many property settings but still I can't seem to stop it from stripping the colour coded files in the first data row of the Excel exported spread sheet. Is there a way around this?
Component version 3.14, Windows 11, Delphi 12.2.
Shows the DB Grid
Shows the image of the exported file. Note the first row of data has no colour coding.
How exactly do you set the color of cells in TDBAdvGrid? Properties? Event? Other?
Hi Bruno,
I use the onGetCellcolor event and setting the ABrush: TBrush .color property.
Regards
Tom
I do not see a problem.
I took the ADOXlsExport demo and added the OnGetCellColor event and the first row background color is exported:
Hi Bruno,
Hmm...I am not sure why it is doing this unless I have some setting in the grid properties that is interfering with the export. Is there anything that you can think off that may interfere with color coding that row. I will check out the demo that you have used and check what properties are set for that grid. It just weird that it is just that row. I feel it must have something to do with the row highlighting or selection.
I see that your record marker and focused cell highlighting is set to true; so, it not the cell highlighting. Either the default row selection or row highlighting code is overriding the colour data being exported.
Regards
Please inform when you can provide details with which we can reproduce this
Hi Bruno,
I will let you know shortly.
Regards
Hi Bruno,
I used exactly the same project with the following code:
procedure TForm1.DBAdvGrid1GetCellColor(Sender: TObject; ARow, ACol: Integer;
AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
Var Limclr: double;
begin
//Code to colour the grid
If ACol > 2 then
begin
Try
If (DBAdvGrid1.Cells[ACol,ARow] <> '') And TryStrtoFloat(DBAdvGrid1.Cells[ACol,ARow],Limclr) then
begin
If (Variant(DBAdvGrid1.Cells[ACol,ARow])) < 1 then
begin
ABrush.Color := clRed;
end
else
begin
If (Variant(DBAdvGrid1.Cells[ACol,ARow])) = 0 then
ABrush.Color := $00BCFEFC
else if (Variant(DBAdvGrid1.Cells[ACol,ARow])) >= 1 then
ABrush.Color := ClGreen
else if (Variant(DBAdvGrid1.Cells[ACol,ARow])) > 20 then
ABrush.Color := clSkyBlue
else if (Variant(DBAdvGrid1.Cells[ACol,ARow])) > 40 then
ABrush.Color := ClYellow
else if (Variant(DBAdvGrid1.Cells[ACol,ARow])) > 100 then
ABrush.Color := clSilver;
end;
end;
Except
On e:exception do
MessageDlg ('Unable to set cell colour! Error: ' + e.Message,mtError, [mbOk],0);
end;
End;
end;
I got the same result.

Note the first row of data is not colour coded.
Regards
Tom
Hi Bruno,
I have isolated the issue. Right in the beginning of checking the limits and colour coding them correctly. I placed this code:
if gdFixed in AState then
Brush.Color := clBtnFace
else if gdSelected in AState then
Brush.Color := clNone
This seems to strip the colour from the first row. Ouch. Not sure why I had the code there. I have deleted it as it is not necessary.
Okay this code dates back a number of years, maybe it was important back then.
Thanks for your assistance once again. This first row is now being exported correctly with the colour coding as desired.
Regards
1 Like