From bd601224e557c280c679e68af24ae5307b85564b Mon Sep 17 00:00:00 2001 From: alexs75 Date: Thu, 11 Sep 2014 09:31:28 +0000 Subject: [PATCH] TRxDBGridExportSpreadSheet - start code for export merged title cells git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3545 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi | 40 ++++++++--- .../trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm | 66 +++++++++---------- .../trunk/Demos/RxDBGrid/rxdbgridmainunit.pas | 2 +- components/rx/trunk/rxdbgrid.pas | 4 +- .../rx/trunk/rxdbgridexportspreadsheet.pas | 30 +++++++++ 5 files changed, 95 insertions(+), 47 deletions(-) diff --git a/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi index 27d9ffebd..43a88b0eb 100644 --- a/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/trunk/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -59,7 +59,7 @@ - + @@ -73,8 +73,7 @@ - - + @@ -100,14 +99,13 @@ - - - - + + + - - + + @@ -708,8 +706,18 @@ + + + + + + + + + + - + @@ -774,6 +782,18 @@ + + + + + + + + + + + + diff --git a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm index 2819a4754..5ca9e8a67 100644 --- a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm +++ b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.lfm @@ -1,12 +1,12 @@ object RxDBGridMainForm: TRxDBGridMainForm - Left = 363 + Left = 287 Height = 721 - Top = 238 - Width = 1187 + Top = 148 + Width = 1151 ActiveControl = Panel1 Caption = 'RxDBGrid Demo' - ClientHeight = 694 - ClientWidth = 1187 + ClientHeight = 696 + ClientWidth = 1151 Menu = MainMenu1 OnCreate = FormCreate SessionProperties = 'RxDBGridExportSpreadSheet1.FileName;RxDBGridExportSpreadSheet1.OpenAfterExport;RxDBGridExportSpreadSheet1.Options;RxDBGridExportSpreadSheet1.PageName;RxDBGridPrint1.Options;RxDBGridPrint1.Orientation;RxDBGridPrint1.PageMargin;RxDBGridPrint1.ReportTitle;RxDBGridPrint1.ShowColumnHeaderOnAllPage' @@ -14,9 +14,9 @@ object RxDBGridMainForm: TRxDBGridMainForm LCLVersion = '1.3' object RxDBGrid1: TRxDBGrid Left = 0 - Height = 624 - Top = 70 - Width = 1187 + Height = 630 + Top = 66 + Width = 1151 TitleButtons = True AutoSort = True OnGetCellProps = RxDBGrid1GetCellProps @@ -297,22 +297,22 @@ object RxDBGridMainForm: TRxDBGridMainForm end object Panel1: TPanel Left = 0 - Height = 70 + Height = 66 Top = 0 - Width = 1187 + Width = 1151 Align = alTop AutoSize = True - ClientHeight = 70 - ClientWidth = 1187 + ClientHeight = 66 + ClientWidth = 1151 TabOrder = 1 object Label1: TLabel AnchorSideLeft.Control = Button2 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 270 - Height = 21 + Left = 262 + Height = 19 Top = 7 - Width = 36 + Width = 34 BorderSpacing.Around = 6 Caption = 'Mode' ParentColor = False @@ -321,9 +321,9 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = Panel1 Left = 7 - Height = 33 + Height = 31 Top = 7 - Width = 87 + Width = 85 Action = actCalcTotal AutoSize = True BorderSpacing.Around = 6 @@ -333,10 +333,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Button1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 100 - Height = 33 + Left = 98 + Height = 31 Top = 7 - Width = 164 + Width = 158 Action = actOptimizeColumnsWidthAll AutoSize = True BorderSpacing.Around = 6 @@ -347,11 +347,11 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = CheckBox2 AnchorSideTop.Side = asrBottom - Left = 499 + Left = 491 Height = 23 Hint = 'Use filter line' Top = 36 - Width = 82 + Width = 80 BorderSpacing.Left = 6 Caption = 'Use filter' OnChange = CheckBox1Change @@ -361,9 +361,9 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Label1 AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom - Left = 276 - Height = 29 - Top = 34 + Left = 268 + Height = 27 + Top = 32 Width = 217 BorderSpacing.Around = 6 ItemHeight = 0 @@ -381,11 +381,11 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = ComboBox1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 499 + Left = 491 Height = 23 Hint = 'Auto fill column width' Top = 7 - Width = 131 + Width = 125 BorderSpacing.Around = 6 Caption = 'Auto fill columns' OnChange = CheckBox2Change @@ -395,10 +395,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = CheckBox2 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 636 + Left = 622 Height = 23 Top = 7 - Width = 119 + Width = 116 BorderSpacing.Around = 6 Caption = 'Show indicator' Checked = True @@ -411,10 +411,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = CheckBox3 AnchorSideTop.Side = asrBottom - Left = 636 + Left = 622 Height = 23 Top = 36 - Width = 115 + Width = 112 BorderSpacing.Around = 6 Caption = 'Show headers' Checked = True @@ -426,10 +426,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = CheckBox3 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 761 + Left = 744 Height = 23 Top = 7 - Width = 94 + Width = 95 BorderSpacing.Around = 6 Caption = 'Word wrap' OnChange = CheckBox5Change diff --git a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas index 0280559df..e648021c1 100644 --- a/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas +++ b/components/rx/trunk/Demos/RxDBGrid/rxdbgridmainunit.pas @@ -97,7 +97,7 @@ var procedure LocalizeApp; implementation -uses rxsortmemds, FileUtil, gettext, translations, LCLVersion, rxFileUtils; +uses rxsortmemds, FileUtil, gettext, translations, rxFileUtils; procedure LocalizeApp; var diff --git a/components/rx/trunk/rxdbgrid.pas b/components/rx/trunk/rxdbgrid.pas index c96650db2..19cec3112 100644 --- a/components/rx/trunk/rxdbgrid.pas +++ b/components/rx/trunk/rxdbgrid.pas @@ -36,12 +36,10 @@ unit rxdbgrid; interface uses - Classes, SysUtils, LResources, LCLVersion, LCLType, LCLIntf, Forms, Controls, Buttons, + Classes, SysUtils, LResources, LCLType, LCLIntf, Forms, Controls, Buttons, Graphics, Dialogs, Grids, dbutils, DBGrids, DB, PropertyStorage, vclutils, LMessages, types, StdCtrls, Menus, rxspin; -{//$if ((lcl_major = 1) and (lcl_minor = 1))} - const CBadQuickSearchSymbols = [VK_UNKNOWN..VK_HELP] + [VK_LWIN..VK_SLEEP] + [VK_NUMLOCK..VK_SCROLL] + [VK_LSHIFT..VK_OEM_102] + [VK_PROCESSKEY] + diff --git a/components/rx/trunk/rxdbgridexportspreadsheet.pas b/components/rx/trunk/rxdbgridexportspreadsheet.pas index 9ab2f644f..8f220e5c5 100644 --- a/components/rx/trunk/rxdbgridexportspreadsheet.pas +++ b/components/rx/trunk/rxdbgridexportspreadsheet.pas @@ -107,6 +107,7 @@ var scColor : TsColor; CB:TsCellBorders; FMaxTitleHeight : integer; + P: TMLCaptionItem; begin FCurCol:=0; FMaxTitleHeight:=1; @@ -142,6 +143,7 @@ begin else CB:=CB - [cbEast]; + FWorksheet.WriteBorderColor(FCurRow + k ,FCurCol, cbSouth, scColorBlack); FWorksheet.WriteBorders(FCurRow + k, FCurCol, CB); @@ -149,6 +151,20 @@ begin FWorksheet.WriteHorAlignment(FCurRow + k, FCurCol, ssAligns[C.Title.Alignment]); FWorksheet.WriteUTF8Text(FCurRow + k, FCurCol, CT.CaptionLine(k).Caption); + + if Assigned(CT.CaptionLine(k).Next) and not Assigned(CT.CaptionLine(k).Prior) then + begin + //Merge title cell + P:=CT.CaptionLine(k); + CC:=FCurCol; + while Assigned(P.Next) do + begin + Inc(CC); + P:=P.Next; + end; + if CC<>FCurCol then + FWorksheet.MergeCells(FCurRow, FCurCol, FCurRow, CC); + end; end; end else @@ -176,6 +192,20 @@ begin end; end; +{ + if FMaxTitleHeight > 1 then + begin + for i:=0 to FRxDBGrid.Columns.Count-1 do + begin + C:=FRxDBGrid.Columns[i] as TRxColumn; + CT:=C.Title as TRxColumnTitle; + if CT.CaptionLinesCount < FMaxTitleHeight then + begin + FWorksheet.MergeCells( FCurRow + CT.CaptionLinesCount, I, FCurRow + FMaxTitleHeight - 1, I); + end; + end; + end; +} inc(FCurRow, FMaxTitleHeight); end;