From 02a3b17e6e181306a7bd345dcd822c027bfef004 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 12 Sep 2014 15:16:46 +0000 Subject: [PATCH] fpspreadsheet: Show info on Merge cell option in XF record by BIFF explorer. Trying to improve with of color box in spready. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3555 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/spready/mainform.lfm | 59 +++++++++---------- .../examples/spready/mainform.pas | 23 ++------ .../fpspreadsheet/fpspreadsheetgrid.pas | 4 +- .../reference/BIFFExplorer/bebiffgrid.pas | 3 + components/fpspreadsheet/xlsbiff8.pas | 22 ++++--- 5 files changed, 52 insertions(+), 59 deletions(-) diff --git a/components/fpspreadsheet/examples/spready/mainform.lfm b/components/fpspreadsheet/examples/spready/mainform.lfm index b71a5fe36..1f817ab8a 100644 --- a/components/fpspreadsheet/examples/spready/mainform.lfm +++ b/components/fpspreadsheet/examples/spready/mainform.lfm @@ -4,7 +4,7 @@ object MainFrm: TMainFrm Top = 258 Width = 884 Caption = 'spready' - ClientHeight = 619 + ClientHeight = 614 ClientWidth = 884 Menu = MainMenu OnActivate = FormActivate @@ -14,7 +14,7 @@ object MainFrm: TMainFrm object Panel1: TPanel Left = 0 Height = 78 - Top = 541 + Top = 536 Width = 884 Align = alBottom BevelOuter = bvNone @@ -23,9 +23,9 @@ object MainFrm: TMainFrm TabOrder = 6 object CbShowHeaders: TCheckBox Left = 8 - Height = 19 + Height = 24 Top = 8 - Width = 93 + Width = 116 Caption = 'Show headers' Checked = True OnClick = CbShowHeadersClick @@ -34,9 +34,9 @@ object MainFrm: TMainFrm end object CbShowGridLines: TCheckBox Left = 8 - Height = 19 + Height = 24 Top = 39 - Width = 100 + Width = 125 Caption = 'Show grid lines' Checked = True OnClick = CbShowGridLinesClick @@ -45,7 +45,7 @@ object MainFrm: TMainFrm end object EdFrozenCols: TSpinEdit Left = 645 - Height = 23 + Height = 28 Top = 8 Width = 52 OnChange = EdFrozenColsChange @@ -53,7 +53,7 @@ object MainFrm: TMainFrm end object EdFrozenRows: TSpinEdit Left = 645 - Height = 23 + Height = 28 Top = 39 Width = 52 OnChange = EdFrozenRowsChange @@ -61,37 +61,37 @@ object MainFrm: TMainFrm end object Label1: TLabel Left = 560 - Height = 15 + Height = 20 Top = 13 - Width = 62 + Width = 77 Caption = 'Frozen cols:' FocusControl = EdFrozenCols ParentColor = False end object Label2: TLabel Left = 560 - Height = 15 + Height = 20 Top = 40 - Width = 66 + Width = 82 Caption = 'Frozen rows:' FocusControl = EdFrozenRows ParentColor = False end object CbReadFormulas: TCheckBox Left = 160 - Height = 19 + Height = 24 Top = 8 - Width = 96 + Width = 120 Caption = 'Read formulas' OnChange = CbReadFormulasChange TabOrder = 2 end object CbHeaderStyle: TComboBox Left = 408 - Height = 23 + Height = 28 Top = 8 Width = 116 - ItemHeight = 15 + ItemHeight = 20 ItemIndex = 2 Items.Strings = ( 'Lazarus' @@ -105,9 +105,9 @@ object MainFrm: TMainFrm end object CbAutoCalcFormulas: TCheckBox Left = 160 - Height = 19 + Height = 24 Top = 39 - Width = 128 + Width = 158 Caption = 'Calculate on change' OnChange = CbAutoCalcFormulasChange TabOrder = 3 @@ -200,19 +200,19 @@ object MainFrm: TMainFrm end object FontComboBox: TComboBox Left = 52 - Height = 23 + Height = 28 Top = 2 Width = 127 - ItemHeight = 15 + ItemHeight = 20 OnSelect = FontComboBoxSelect TabOrder = 0 end object FontSizeComboBox: TComboBox Left = 179 - Height = 23 + Height = 28 Top = 2 Width = 48 - ItemHeight = 15 + ItemHeight = 20 Items.Strings = ( '8' '9' @@ -301,7 +301,6 @@ object MainFrm: TMainFrm Height = 26 Top = 2 Width = 149 - ColorRectWidth = 8 NoneColorColor = clDefault Style = [cbPrettyNames, cbCustomColors] OnGetColors = CbBackgroundColorGetColors @@ -382,7 +381,7 @@ object MainFrm: TMainFrm end object InspectorSplitter: TSplitter Left = 648 - Height = 462 + Height = 457 Top = 79 Width = 5 Align = alRight @@ -390,7 +389,7 @@ object MainFrm: TMainFrm end object InspectorPageControl: TPageControl Left = 653 - Height = 462 + Height = 457 Top = 79 Width = 231 ActivePage = PgCellValue @@ -400,11 +399,11 @@ object MainFrm: TMainFrm OnChange = InspectorPageControlChange object PgCellValue: TTabSheet Caption = 'Cell value' - ClientHeight = 434 + ClientHeight = 424 ClientWidth = 223 object CellInspector: TValueListEditor Left = 0 - Height = 434 + Height = 424 Top = 0 Width = 223 Align = alClient @@ -445,7 +444,7 @@ object MainFrm: TMainFrm end object TabControl: TTabControl Left = 0 - Height = 462 + Height = 457 Top = 79 Width = 648 OnChange = TabControlChange @@ -453,7 +452,7 @@ object MainFrm: TMainFrm TabOrder = 3 object WorksheetGrid: TsWorksheetGrid Left = 2 - Height = 457 + Height = 452 Top = 3 Width = 644 FrozenCols = 0 @@ -470,7 +469,7 @@ object MainFrm: TMainFrm TitleStyle = tsNative OnSelection = WorksheetGridSelection ColWidths = ( - 42 + 56 64 64 64 diff --git a/components/fpspreadsheet/examples/spready/mainform.pas b/components/fpspreadsheet/examples/spready/mainform.pas index bae837297..22009a6e0 100644 --- a/components/fpspreadsheet/examples/spready/mainform.pas +++ b/components/fpspreadsheet/examples/spready/mainform.pas @@ -322,10 +322,10 @@ uses const DROPDOWN_COUNT = 24; - HORALIGN_TAG = 100; - VERTALIGN_TAG = 110; - TEXTROT_TAG = 130; - NUMFMT_TAG = 1000; // differnce 10 per format item + HORALIGN_TAG = 100; + VERTALIGN_TAG = 110; + TEXTROT_TAG = 130; + NUMFMT_TAG = 1000; // difference 10 per format item LEFT_BORDER_THIN = $0001; LEFT_BORDER_THICK = $0002; @@ -347,19 +347,6 @@ const // Use a combination of these bits for the "Tag" of the Border actions - see FormCreate. -{ Utilities } - -{ Determines the "real" size of font. Default font usually reports font size 0... - http://comments.gmane.org/gmane.comp.ide.lazarus.general/70758 } -function RealFontSize(AFont: TFont): Integer; -var - logFont: TLogFont; -begin - LCLIntf.GetObject(AFont.Reference.Handle, SizeOf(TLogFont), @logFont); - Result := abs(logFont.lfHeight); -end; - - { TMainFrm } procedure TMainFrm.AcEditExecute(Sender: TObject); @@ -821,7 +808,7 @@ begin FormatToolbar.ButtonHeight := FormatToolbar.Height - 4; CbBackgroundColor.ItemHeight := FontCombobox.ItemHeight; - //CbBackgroundColor.ColorRectWidth := RealFontSize(CbBackgroundColor.Font); + CbBackgroundColor.ColorRectWidth := round(screen.PixelsPerInch/120*CbBackgroundColor.ColorRectWidth); // Populate font combobox FontCombobox.Items.Assign(Screen.Fonts); diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 4e3251ee2..64c8b541a 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -3327,9 +3327,7 @@ procedure TsCustomWorksheetGrid.UnmergeCells; begin FWorksheet.UnmergeCells( GetWorksheetRow(Selection.Top), - GetWorksheetCol(Selection.Left), - GetWorksheetRow(Selection.Bottom), - GetWorksheetCol(Selection.Right) + GetWorksheetCol(Selection.Left) ); end; diff --git a/components/fpspreadsheet/reference/BIFFExplorer/bebiffgrid.pas b/components/fpspreadsheet/reference/BIFFExplorer/bebiffgrid.pas index d7ffa5263..502f020cc 100644 --- a/components/fpspreadsheet/reference/BIFFExplorer/bebiffgrid.pas +++ b/components/fpspreadsheet/reference/BIFFExplorer/bebiffgrid.pas @@ -4714,6 +4714,9 @@ begin if b and $10 = 0 then FDetails.Add('Bit $10 = 0: Don''t shrink content to fit into cell') else FDetails.Add('Bit $10 = 1: Shrink content to fit into cell'); + if b and $20 = 0 + then FDetails.Add('Bit $20 = 0: Merge Cell option is OFF') + else FDetails.Add('Bit $20 = 1: Merge Cell option is ON'); case (b and $C0) shr 6 of 0: FDetails.Add('Bits 6-7 = 0: Text direction according to context'); 1: FDetails.Add('Bits 6-7 = 1: Text direction left-to-right'); diff --git a/components/fpspreadsheet/xlsbiff8.pas b/components/fpspreadsheet/xlsbiff8.pas index cf25d91f4..c9ef9fbc5 100755 --- a/components/fpspreadsheet/xlsbiff8.pas +++ b/components/fpspreadsheet/xlsbiff8.pas @@ -1129,7 +1129,7 @@ procedure TsSpreadBIFF8Writer.WriteXF(AStream: TStream; AFontIndex: Word; AddBackground: Boolean = false; ABackgroundColor: TsColor = scSilver); var XFOptions: Word; - XFAlignment, XFOrientationAttrib: Byte; + XFAlignment, XFIndentShrinkMerge, XFOrientationAttrib: Byte; XFBorderDWord1, XFBorderDWord2: DWord; begin { BIFF Record header } @@ -1137,10 +1137,10 @@ begin AStream.WriteWord(WordToLE(20)); { Index to FONT record } - AStream.WriteWord(WordToLE(AFontIndex)); + AStream.WriteWord(WordToLE(AFontIndex)); // Offset 4 { Index to FORMAT record } - AStream.WriteWord(WordToLE(AFormatIndex)); + AStream.WriteWord(WordToLE(AFormatIndex)); // Offset 6 { XF type, cell protection and parent style XF } XFOptions := AXF_TYPE_PROT and MASK_XF_TYPE_PROT; @@ -1148,7 +1148,7 @@ begin if AXF_TYPE_PROT and MASK_XF_TYPE_PROT_STYLE_XF <> 0 then XFOptions := XFOptions or MASK_XF_TYPE_PROT_PARENT; - AStream.WriteWord(WordToLE(XFOptions)); + AStream.WriteWord(WordToLE(XFOptions)); // Offset 8 { Alignment and text break } XFAlignment := 0; @@ -1166,13 +1166,19 @@ begin if AWordWrap then XFAlignment := XFAlignment or MASK_XF_TEXTWRAP; - AStream.WriteByte(XFAlignment); + AStream.WriteByte(XFAlignment); // Offset 10 { Text rotation } - AStream.WriteByte(ATextRotation); // 0 is horizontal / normal + AStream.WriteByte(ATextRotation); // 0 is horizontal / normal // Offset 11 - { Indentation, shrink and text direction } - AStream.WriteByte(0); + { Indentation, shrink, merge and text direction: + see "Excel97-2007BinaryFileFormat(xls)Specification.pdf", p281 ff + Bits 0-3: Indent value + Bit 4: Shrink to fit + Bit 5: MergeCell + Bits 6-7: Reading direction } + XFIndentShrinkMerge := 0; + AStream.WriteByte(XFIndentShrinkMerge); // Offset 12 { Used attributes } XFOrientationAttrib :=