cxGrid导出到excel中,保留背景颜色,字体颜色等设置
2011-02-07 21:31:04| 分类: 编程 | 标签:delphi cxgrid |字号 订阅
环境:Delphi 2010 , DevExpressVCL.v53
之前,要突出显示表格中的某个单元格,使用的是“onCustomDrawCell”事件,例如:
procedure TFrm_SettleDataOut.cxGrid1DBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
//当前列是11 且第24列的值=1,
if (AViewInfo.Item.ID=11) and
(AViewInfo.GridRecord.DisplayTexts[24]='1') then
begin
ACanvas.SetBrushColor(clRed);
end;
end;
这样做,表格中的确是正确的突出显示了,但是使用
ExportGridToExcel(dlgSave1.filename,Self.cxGrid1,True,True,True);
导出的excel中,单元格没有突出显示。
想起来还有一种突出单元格的方法,是使用style。
AYellowStyle: TcxStyle; //定义一个窗体级变量
//定义该style
procedure TFrm_SettleDataOut.FormCreate(Sender: TObject);
begin
//行颜色
AYellowStyle := TcxStyle.Create(Self);
AYellowStyle.Color := $0080FFFF;
AYellowStyle.TextColor := clMaroon;
end;
//使用onGetContentStyle事件,按条件定义样式
procedure TFrm_SettleDataOut.cxGrid1DBTableView1StylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
//定义行的样式
if (ARecord<>nil) and (ARecord.ValueCount>=24) and (ARecord.DisplayTexts[24]='1') then
AStyle:=AYellowStyle;
//单独定义单元格的样式 只定义第24列的样式
if (AItem<>nil) and (AItem.ID=24) and (ARecord.DisplayTexts[24]='1') then
AStyle:=AYellowStyle;
end;
使用style定义单元格的颜色,可以导出到excel中。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。