From f36775184fe1c6938b38e9d543fe8aaabab8f256 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Wed, 6 Aug 2014 10:19:42 +0000 Subject: [PATCH] TRxDBGridExportSpreadSheet - footer colors and lockup fields git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3437 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi | 16 +++++-- .../trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm | 4 ++ .../trunk/Demos/RxDBGrid/rxdbgridmainunit.pas | 12 ++++-- .../rx/trunk/rxdbgridexportspreadsheet.pas | 42 +++++++++++++------ 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi index c3c002ec7..27d9ffebd 100644 --- a/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -73,9 +73,8 @@ - - - + + @@ -101,6 +100,7 @@ + @@ -709,7 +709,7 @@ - + @@ -766,6 +766,14 @@ + + + + + + + + diff --git a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm index d86ab9643..2819a4754 100644 --- a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm +++ b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm @@ -9,6 +9,7 @@ object RxDBGridMainForm: TRxDBGridMainForm ClientWidth = 1187 Menu = MainMenu1 OnCreate = FormCreate + SessionProperties = 'RxDBGridExportSpreadSheet1.FileName;RxDBGridExportSpreadSheet1.OpenAfterExport;RxDBGridExportSpreadSheet1.Options;RxDBGridExportSpreadSheet1.PageName;RxDBGridPrint1.Options;RxDBGridPrint1.Orientation;RxDBGridPrint1.PageMargin;RxDBGridPrint1.ReportTitle;RxDBGridPrint1.ShowColumnHeaderOnAllPage' ShowHint = True LCLVersion = '1.3' object RxDBGrid1: TRxDBGrid @@ -18,6 +19,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Width = 1187 TitleButtons = True AutoSort = True + OnGetCellProps = RxDBGrid1GetCellProps Columns = < item Title.Alignment = taCenter @@ -43,6 +45,7 @@ object RxDBGridMainForm: TRxDBGridMainForm ) end item + Color = clSkyBlue Title.Alignment = taCenter Title.Caption = 'Code - ID' Title.Orientation = toVertical90 @@ -1343,6 +1346,7 @@ object RxDBGridMainForm: TRxDBGridMainForm RxDBGrid = RxDBGrid1 Caption = 'Export data' ShowSetupForm = True + FileName = 'RxDBGridDemo.ods' PageName = 'RxDBGrid demo' Options = [ressExportTitle, ressExportColors, ressExportFooter, ressOverwriteExisting] left = 504 diff --git a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas index 960d1e1a9..0280559df 100644 --- a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas +++ b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas @@ -78,6 +78,8 @@ type procedure FormCreate(Sender: TObject); procedure hlpAboutExecute(Sender: TObject); procedure RxDBGrid1Filtred(Sender: TObject); + procedure RxDBGrid1GetCellProps(Sender: TObject; Field: TField; + AFont: TFont; var Background: TColor); procedure showColumnsDialogExecute(Sender: TObject); procedure showFindDialogExecute(Sender: TObject); procedure sysExitExecute(Sender: TObject); @@ -138,9 +140,6 @@ begin RxMemoryData1.AppendRecord([16, 'Гарант', 480, 'Гарант', EncodeDate(2007, 2, 1), 3]); RxMemoryData1.First; -// RxDBGrid1.CalcStatTotals; //fix error in GotoBookmark - - end; procedure TRxDBGridMainForm.hlpAboutExecute(Sender: TObject); @@ -153,6 +152,13 @@ begin RxMemoryData1.First; end; +procedure TRxDBGridMainForm.RxDBGrid1GetCellProps(Sender: TObject; + Field: TField; AFont: TFont; var Background: TColor); +begin + if (Field = RxMemoryData1PRICE1) and (RxMemoryData1PRICE1.AsFloat>99) then + Background:=clRed; +end; + procedure TRxDBGridMainForm.showColumnsDialogExecute(Sender: TObject); begin diff --git a/components/rx/trunk/rxdbgridexportspreadsheet.pas b/components/rx/trunk/rxdbgridexportspreadsheet.pas index 3985ddf49..9ab2f644f 100644 --- a/components/rx/trunk/rxdbgridexportspreadsheet.pas +++ b/components/rx/trunk/rxdbgridexportspreadsheet.pas @@ -186,7 +186,11 @@ var CT : TRxColumnTitle; CC : TColor; scColor : TsColor; + F:TFont; + S: String; + J: Integer; begin + F:=TFont.Create; FDataSet.First; while not FDataSet.EOF do begin @@ -197,13 +201,26 @@ begin CT:=C.Title as TRxColumnTitle; if C.Visible then begin - FWorksheet.WriteUTF8Text(FCurRow, FCurCol, C.Field.DisplayText); - CC:=C.Color; - if (CC and SYS_COLOR_BASE) = 0 then + + S:=C.Field.DisplayText; + if (C.KeyList.Count > 0) and (C.PickList.Count > 0) then begin -// CC:=clWhite; - scColor:=FWorkbook.AddColorToPalette(CC); - FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, scColor); + J := C.KeyList.IndexOf(S); + if (J >= 0) and (J < C.PickList.Count) then + S := C.PickList[j]; + end; + FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S); + + if ressExportColors in FOptions then + begin + CC:=C.Color; + if Assigned(RxDBGrid.OnGetCellProps) then + RxDBGrid.OnGetCellProps(RxDBGrid, C.Field, F, CC); + if (CC and SYS_COLOR_BASE) = 0 then + begin + scColor:=FWorkbook.AddColorToPalette(CC); + FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, scColor); + end; end; FWorksheet.WriteBorders(FCurRow,FCurCol, [cbNorth, cbWest, cbEast, cbSouth]); @@ -219,6 +236,7 @@ begin inc(FCurRow); FDataSet.Next; end; + F.Free end; procedure TRxDBGridExportSpreadSheet.DoExportFooter; @@ -237,15 +255,15 @@ begin CT:=C.Title as TRxColumnTitle; if C.Visible then begin + if (CC and SYS_COLOR_BASE) = 0 then + begin + scColor:=FWorkbook.AddColorToPalette(CC); + FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, scColor); + end; + if (C.Footer.ValueType <> fvtNon) then begin FWorksheet.WriteUTF8Text(FCurRow, FCurCol, C.Footer.DisplayText); - if (CC and SYS_COLOR_BASE) = 0 then - begin - // CC:=clWhite; - scColor:=FWorkbook.AddColorToPalette(CC); - FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, scColor); - end; FWorksheet.WriteBorders(FCurRow,FCurCol, [cbNorth, cbWest, cbEast, cbSouth]); FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbNorth, scColorBlack);