From c10dec52eadd76db7f21c1e77ec58ccab1c377d4 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 4 Oct 2015 12:37:09 +0000 Subject: [PATCH] fpspreadsheet: Fix writing incorrect biff formats (broken in r4353) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4366 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/xlscommon.pas | 42 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index 52a8d6731..a78a28467 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -3771,7 +3771,7 @@ procedure TsSpreadBIFFWriter.WriteSELECTION(AStream: TStream; ASheet: TsWorksheet; APane: Byte); var activeCellRow, activeCellCol: Word; - i: Integer; + i, n: Integer; sel: TsCellRange; begin if FWorkbook.ActiveWorksheet <> nil then @@ -3811,25 +3811,41 @@ begin AStream.WriteWord(WordToLE(activeCellCol)); { Index into the following cell range list to the entry that contains the active cell } - i := ASheet.GetSelectionRangeIndexOfActiveCell; + i := Max(0, ASheet.GetSelectionRangeIndexOfActiveCell); AStream.WriteWord(WordToLE(i)); { Cell range array } { Count of cell ranges } - AStream.WriteWord(WordToLE(ASheet.GetSelectionCount)); - - { Write each selected cell range } - for i := 0 to ASheet.GetSelectionCount-1 do + n := ASheet.GetSelectionCount; + // Case 1: no selection + if n = 0 then 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)); + { Count of cell ranges } + AStream.WriteWord(WordToLE(1)); + { 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: Even BIFF8 writes bytes here! This is ok because BIFF supports only 256 columns } - AStream.WriteByte(sel.Col1); - AStream.WriteByte(sel.Col2); + { Note: BIFF8 writes bytes here! This is ok because BIFF supports only 256 columns} + AStream.WriteByte(activeCellCol); + AStream.WriteByte(activeCellCol); + end else + // Case 2: Selections available + begin + AStream.WriteWord(WordToLE(n)); + { Write each selected cell range } + for i := 0 to n-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 } + { 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; end;