1. 程式人生 > >DBGridEh使用指南改變邊框顏色

DBGridEh使用指南改變邊框顏色

ride cal bsp getc erro ado const 使用 導出

DBGridEh使用指南

技術分享圖片 鵝倌0人評論422人閱讀2012-08-06 15:17:59

1.設置表頭,是否允許多表頭,設置是否只讀。

dbgrdh1.TitleFont.Color:=clBlue;
dbgrdh1.Flat:=True;
dbgrdh1.FixedColor:=clSkyBlue; //Flat為True背景漸變才會起作用
dbgrdh1.TitleHeight:=30;
dbgrdh1.TitleLines := 2;
dbgrdh1.ColumnDefValues.Title.Alignment:=taCenter;
dbgrdh1.UseMultiTitle := true;
dbgrdh1.Columns[0].HideDuplicates := true;//是否隱藏重復
dbgrdh1.RowSizingAllowed := True;
DBgrdh1.DataSource := nil;

2.設置表格顏色

procedure Ttablefrm.dbgrdh1GetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
begin
if dbgrdh1.DataSource <> nil then
begin
if dbgrdh1.SumList.RecNo mod 2 = 1 then
Background := $00FFC4C4
else
Background := $00FFDDDD;
end;
end;

3.添加合計。

dbgrdh1.FooterRowCount := 1;
dbgrdh1.SumList.Active := true;
dbgrdh1.Columns[0].Footer.valuetype := fvtstatictext;//靜態文本
dbgrdh1.Columns[0].Footer.value := ‘合計:‘;

for i := 0 to dbgrdh1.Columns.Count - 1 do
begin
if (i>4) and (i < 10) then
begin
dbgrdh1.Columns[i].Footer.ValueType := fvtSum;//合計sum
end;
end;

4.設置打印。

PrintDBGridEh1.DBGridEh :=dbgrdh1;
PrintDBGridEh1.SetSubstitutes([‘%[打印標題]‘,‘住院處結算單‘]);
PrintDBGridEh1.Print;

5.設置導出(excel,html,txt)。

procedure OutToFile(IADO : TADOQuery; DgEh : TDBGridEh);

procedure Tfrm_bazl.OutToFile(IADO: TADOQuery; DgEh: TDBGridEh);
var
ExpClass:TDBGridEhExportclass;
Ext:String;
FSaveDialog: TSaveDialog;
begin
try
if not IADO.IsEmpty then
begin
FSaveDialog := TSaveDialog.Create(Self);
FSaveDialog.Filter:=‘Excel 文檔 (*.xls)|*.XLS|Text files (*.txt)|*.TXT|Comma separated values (*.csv)|*.CSV|HTML file (*.htm)|*.HTM|Word 文檔 (*.rtf)|*.RTF‘;
if FSaveDialog.Execute and (trim(FSaveDialog.FileName)<>‘‘) then
begin
case FSaveDialog.FilterIndex of
1: begin ExpClass := TDBGridEhExportAsXLS; Ext := ‘xls‘; end;
2: begin ExpClass := TDBGridEhExportAsText; Ext := ‘txt‘; end;
3: begin ExpClass := TDBGridEhExportAsCSV; Ext := ‘csv‘; end;
4: begin ExpClass := TDBGridEhExportAsHTML; Ext := ‘htm‘; end;
5: begin ExpClass := TDBGridEhExportAsRTF; Ext := ‘rtf‘; end;
end;
if ExpClass <> nil then
begin
if UpperCase(Copy(FSaveDialog.FileName,Length(FSaveDialog.FileName)-2,3)) <> UpperCase(Ext) then
FSaveDialog.FileName := FSaveDialog.FileName + ‘.‘ + Ext;
if FileExists(FSaveDialog.FileName) then
begin
if application.MessageBox(‘文件名已存在,是否覆蓋 ‘, ‘提示‘, MB_ICONASTERISK or MB_OKCANCEL)<>idok then
exit;
end;
Screen.Cursor := crHourGlass;
SaveDBGridEhToExportFile(ExpClass,DgEh,FSaveDialog.FileName,true);
Screen.Cursor := crDefault;
MessageBox(Handle, ‘導出成功 ‘, ‘提示‘, MB_OK +
MB_ICONINFORMATION);
end;
end;
FSaveDialog.Destroy;
end;
except
on e: exception do
begin
Application.MessageBox(PChar(e.message), ‘錯誤‘, MB_OK + MB_ICONSTOP);
end;
end;
end;

DBGridEh使用指南改變邊框顏色