Skip to content

Commit

Permalink
Add GetRowCount functionality to FsRangeBase
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Aug 10, 2023
1 parent aa4938c commit 05f19ae
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/FsSpreadsheet/Ranges/FsRangeBase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type FsRangeBase (rangeAddress : FsRangeAddress) =

//abstract member OnRangeAddressChanged : FsRangeAddress*FsRangeAddress -> unit

//default self.OnRangeAddressChanged (oldAddress, newAddress) =
//default this.OnRangeAddressChanged (oldAddress, newAddress) =

// Worksheet.RellocateRange(RangeType, oldAddress, newAddress);

member self.Extend(address : FsAddress) = _rangeAddress.Extend(address)
member this.Extend(address : FsAddress) = _rangeAddress.Extend(address)

member self.RangeAddress
member this.RangeAddress
with get () = _rangeAddress
and set (rangeAdress) =
if rangeAdress <> _rangeAddress then
Expand All @@ -32,10 +32,10 @@ type FsRangeBase (rangeAddress : FsRangeAddress) =
//OnRangeAddressChanged(oldAddress, _rangeAddress);

// TO DO: add description – important and complex function
member self.Cell(cellAddressInRange : FsAddress, cells : FsCellsCollection) =
member this.Cell(cellAddressInRange : FsAddress, cells : FsCellsCollection) =

let absRow = cellAddressInRange.RowNumber + self.RangeAddress.FirstAddress.RowNumber - 1;
let absColumn = cellAddressInRange.ColumnNumber + self.RangeAddress.FirstAddress.ColumnNumber - 1;
let absRow = cellAddressInRange.RowNumber + this.RangeAddress.FirstAddress.RowNumber - 1;
let absColumn = cellAddressInRange.ColumnNumber + this.RangeAddress.FirstAddress.ColumnNumber - 1;

if (absRow <= 0 || absRow > 1048576) then
failwithf "Row number must be between 1 and %i" cells.MaxRowNumber
Expand Down Expand Up @@ -67,13 +67,26 @@ type FsRangeBase (rangeAddress : FsRangeAddress) =
// has a default style, use the worksheet's default style
let newCell = FsCell.createEmptyWithAdress absoluteAddress

self.Extend(absoluteAddress)
this.Extend(absoluteAddress)

cells.Add(absRow, absColumn, newCell) |> ignore
newCell

member self.Cells(cells : FsCellsCollection) =
cells.GetCells(self.RangeAddress.FirstAddress, self.RangeAddress.LastAddress)

member self.ColumnCount() =
_rangeAddress.LastAddress.ColumnNumber - _rangeAddress.FirstAddress.ColumnNumber + 1;

/// <summary>
/// Returns the FsCells of this FsRangeBase with the given FsCellsCollection.
/// </summary>
/// <param name="cells">The FsCellsCollection where the FsCells are retrieved from.</param>
member this.Cells(cells : FsCellsCollection) =
cells.GetCells(this.RangeAddress.FirstAddress, this.RangeAddress.LastAddress)

/// <summary>
/// The number of columns in the FsRangeBase.
/// </summary>
member this.ColumnCount() =
_rangeAddress.LastAddress.ColumnNumber - _rangeAddress.FirstAddress.ColumnNumber + 1

/// <summary>
/// The number of rows in the FsRangeBase.
/// </summary>
member this.RowCount() =
_rangeAddress.LastAddress.RowNumber - _rangeAddress.FirstAddress.RowNumber + 1

0 comments on commit 05f19ae

Please sign in to comment.