From 6a82944c1cb78cb9e997babccd03dde797c579ca Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 23 Sep 2015 13:28:24 +0000 Subject: [PATCH] fpspreadsheet: biff writers store selected ranges now. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4353 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpspreadsheet.pas | 17 +++++++++++++ components/fpspreadsheet/xlscommon.pas | 29 ++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index e3c30b747..a89759003 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -449,6 +449,7 @@ type function GetSelection: TsCellRangeArray; function GetSelectionAsString: String; function GetSelectionCount: Integer; + function GetSelectionRangeIndexOfActiveCell: Integer; procedure SetSelection(const ASelection: TsCellRangeArray); // Comments @@ -3609,6 +3610,22 @@ begin Result := Length(FSelection); end; +{@@ ---------------------------------------------------------------------------- + Returns the index of the selected block which contains the active cell +-------------------------------------------------------------------------------} +function TsWorksheet.GetSelectionRangeIndexOfActiveCell: Integer; +var + sel: TsCellRange; +begin + for Result := 0 to High(FSelection) do + begin + sel := FSelection[Result]; + if (FActiveCellRow >= sel.Row1) and (FActiveCellRow <= sel.Row2) and + (FActiveCellCol >= sel.Col1) and (FActiveCellCol <= sel.Col2) then exit; + end; + Result := -1; +end; + {@@ ---------------------------------------------------------------------------- Marks an array of cell ranges as "selected". Only needed for visual controls -------------------------------------------------------------------------------} diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index e8456610d..8439b474b 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -3730,6 +3730,8 @@ procedure TsSpreadBIFFWriter.WriteSELECTION(AStream: TStream; ASheet: TsWorksheet; APane: Byte); var activeCellRow, activeCellCol: Word; + i: Integer; + sel: TsCellRange; begin if FWorkbook.ActiveWorksheet <> nil then begin @@ -3768,21 +3770,26 @@ begin AStream.WriteWord(WordToLE(activeCellCol)); { Index into the following cell range list to the entry that contains the active cell } - AStream.WriteWord(WordToLE(0)); // there's only 1 item + i := ASheet.GetSelectionRangeIndexOfActiveCell; + AStream.WriteWord(WordToLE(i)); { Cell range array } - { Count of items } - AStream.WriteWord(WordToLE(1)); // only 1 item + { Count of cell ranges } + AStream.WriteWord(WordToLE(ASheet.GetSelectionCount)); - { Index to first and last row - are the same here } - AStream.WriteWord(WordTOLE(activeCellRow)); - AStream.WriteWord(WordTOLE(activeCellRow)); - - { Index to first and last column - they are the same here again. } - { Note: BIFF8 writes bytes here! } - AStream.WriteByte(activeCellCol); - AStream.WriteByte(activeCellCol); + { Write each selected cell range } + for i := 0 to ASheet.GetSelectionCount-1 do + begin + sel := ASheet.GetSelection[i]; + { Index to first and last row of this selected range } + AStream.WriteWord(WordToLE(sel.Row1)); + AStream.WriteWord(WordToLE(sel.Row2)); + { Index to first and last column - they are the same here again. } + { Note: Even BIFF8 writes bytes here! This is ok because BIFF supports only 256 columns } + AStream.WriteByte(sel.Col1); + AStream.WriteByte(sel.Col2); + end; end; procedure TsSpreadBIFFWriter.WriteSelections(AStream: TStream;