diff --git a/build/Build.fsproj b/build/Build.fsproj
index 267f6a2b..a9e91dda 100644
--- a/build/Build.fsproj
+++ b/build/Build.fsproj
@@ -28,7 +28,7 @@
-
+
diff --git a/global.json b/global.json
index 989a69ca..5d881dcb 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "8.0.100",
+ "version": "8.0.1",
"rollForward": "latestMinor"
}
}
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 4c3fe12b..a1fda40c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,15 +1,15 @@
{
"name": "@fslab/fsspreadsheet",
- "version": "6.2.0",
+ "version": "6.3.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@fslab/fsspreadsheet",
- "version": "6.2.0",
+ "version": "6.3.1",
"license": "MIT",
"dependencies": {
- "@nfdi4plants/exceljs": "^0.3.0"
+ "@nfdi4plants/exceljs": "^0.4.0"
},
"devDependencies": {
"mocha": "^10.2.0"
@@ -43,9 +43,10 @@
}
},
"node_modules/@nfdi4plants/exceljs": {
- "version": "0.3.0",
- "resolved": "https://registry.npmjs.org/@nfdi4plants/exceljs/-/exceljs-0.3.0.tgz",
- "integrity": "sha512-/IvHS3ozGyZ2jG1pYpMoUn2vz+GMzkdo8zUnhsfnn2175ajnjlQKQi7qVhp8Kgpvt/FtthcysrloOjlttbyJQQ==",
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/@nfdi4plants/exceljs/-/exceljs-0.4.0.tgz",
+ "integrity": "sha512-4x0JHxRScxmeel38D6eCh3IsvbKE0v77jiaW17c6cm8Rh2+g5tvt+0i5ZzHrlyIXIUKCoja9ekbGUjYXxdrlhw==",
+ "license": "MIT",
"dependencies": {
"archiver": "^5.0.0",
"dayjs": "^1.8.34",
diff --git a/package.json b/package.json
index 8dfda0ee..c05a0288 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,6 @@
"mocha": "^10.2.0"
},
"dependencies": {
- "@nfdi4plants/exceljs": "^0.3.0"
+ "@nfdi4plants/exceljs": "^0.4.0"
}
}
diff --git a/playground.fsx b/playground.fsx
index 342030e2..65df4f49 100644
--- a/playground.fsx
+++ b/playground.fsx
@@ -165,7 +165,7 @@ ws.CellCollection.RemoveCellAt(1, 1)
//let cellSeq = List.init 2 (fun i -> FsCell.create (i + 1) 1 "v")
//let testFCC = FsCellsCollection()
-//testFCC.Add cellSeq
+//testFCC.AddMany cellseq
//testFCC.GetCells()
//let testCells = testFCC.GetCells() |> Seq.map (fun c -> c.Copy())
//let testFCC2 = FsCellsCollection()
@@ -224,7 +224,7 @@ ws.CellCollection.RemoveCellAt(1, 1)
//let copy (this : FsCellsCollection) =
// let newCellsColl = FsCellsCollection()
// let cells : seq = this.GetCells()
-// newCellsColl.Add cells
+// newCellsColl.AddMany cells
//let testCell = FsCell.create 1 1 "Hallo"
//let dummyFsCellsCollection4 = FsCellsCollection().Add testCell
diff --git a/src/FsSpreadsheet.Interactive/FsSpreadsheet.Interactive.fsproj b/src/FsSpreadsheet.Interactive/FsSpreadsheet.Interactive.fsproj
index 9ca04596..3f7e74a8 100644
--- a/src/FsSpreadsheet.Interactive/FsSpreadsheet.Interactive.fsproj
+++ b/src/FsSpreadsheet.Interactive/FsSpreadsheet.Interactive.fsproj
@@ -30,6 +30,7 @@
+
diff --git a/src/FsSpreadsheet.Interactive/README.md b/src/FsSpreadsheet.Interactive/README.md
new file mode 100644
index 00000000..4779977e
--- /dev/null
+++ b/src/FsSpreadsheet.Interactive/README.md
@@ -0,0 +1,7 @@
+# FsSpreadsheet.Interactive
+
+This project provides interactive features for working with spreadsheets in Polyglot Notebooks, by visualizing Sheets as Tables.
+
+For usage, just reference the `#r "nuget: FsSpreadsheet.Interactive"` package in your Polyglot Notebook.
+
+
diff --git a/src/FsSpreadsheet.Js/Cell.fs b/src/FsSpreadsheet.Js/Cell.fs
index c0b3738c..9eb01f86 100644
--- a/src/FsSpreadsheet.Js/Cell.fs
+++ b/src/FsSpreadsheet.Js/Cell.fs
@@ -43,7 +43,7 @@ module JsCell =
///
let readToFsCell worksheetName rowIndex columnIndex (jsCell: Cell) =
let t = enum(jsCell.``type``)
- let fsadress = FsAddress(jsCell.address)
+ let fsadress = FsAddress.fromString(jsCell.address)
let createFscell = fun dt v -> FsCell(v,dt,address = fsadress)
let vTemp = string jsCell.value.Value
let fscell =
@@ -73,15 +73,15 @@ module JsCell =
let b = false
createFscell DataType.Boolean b
| anyElse ->
- let msg = sprintf "ValueType 'Format' (%s) is not fully implemented in FsSpreadsheet and is handled as string input. In %s: (%i,%i)" anyElse worksheetName rowIndex columnIndex
- log msg
+ //let msg = sprintf "ValueType 'Format' (%s) is not fully implemented in FsSpreadsheet and is handled as string input. In %s: (%i,%i)" anyElse worksheetName rowIndex columnIndex
+ //log msg
anyElse |> createFscell DataType.String
| ValueType.Hyperlink ->
//log (c.value.Value?text)
jsCell.value.Value?hyperlink |> createFscell DataType.String
| anyElse ->
- let msg = sprintf "ValueType `%A` (%s) is not fully implemented in FsSpreadsheet and is handled as string input. In %s: (%i,%i)" anyElse vTemp worksheetName rowIndex columnIndex
- log msg
+ //let msg = sprintf "ValueType `%A` (%s) is not fully implemented in FsSpreadsheet and is handled as string input. In %s: (%i,%i)" anyElse vTemp worksheetName rowIndex columnIndex
+ //log msg
vTemp |> createFscell DataType.String
fscell
diff --git a/src/FsSpreadsheet.Js/Contributing.md b/src/FsSpreadsheet.Js/Contributing.md
new file mode 100644
index 00000000..f54e16cb
--- /dev/null
+++ b/src/FsSpreadsheet.Js/Contributing.md
@@ -0,0 +1,3 @@
+## Increase nfdi4plants/exceljs dependency
+
+- Make sure that the version specified by the Femto syntax in FsSpreadhsheet.Js.fsproj fits the new version.
\ No newline at end of file
diff --git a/src/FsSpreadsheet.Js/FsSpreadsheet.Js.fsproj b/src/FsSpreadsheet.Js/FsSpreadsheet.Js.fsproj
index 8fd0633a..16c36d54 100644
--- a/src/FsSpreadsheet.Js/FsSpreadsheet.Js.fsproj
+++ b/src/FsSpreadsheet.Js/FsSpreadsheet.Js.fsproj
@@ -17,6 +17,7 @@
+
\
true
@@ -33,7 +34,7 @@
-
+
diff --git a/src/FsSpreadsheet.Js/Table.fs b/src/FsSpreadsheet.Js/Table.fs
index fafbab83..42a45f52 100644
--- a/src/FsSpreadsheet.Js/Table.fs
+++ b/src/FsSpreadsheet.Js/Table.fs
@@ -44,7 +44,7 @@ module JsTable =
let readToFsTable(table:ITableRef) =
let table = table.table.Value
- let tableRef = table.tableRef |> FsRangeAddress
+ let tableRef = table.tableRef |> FsRangeAddress.fromString
let tableName = if isNull table.displayName then table.name else table.displayName
let table = FsTable(tableName, tableRef, table.totalsRow, table.headerRow)
table
\ No newline at end of file
diff --git a/src/FsSpreadsheet.Net/FsExtensions.fs b/src/FsSpreadsheet.Net/FsExtensions.fs
index 96d4e374..d43403c4 100644
--- a/src/FsSpreadsheet.Net/FsExtensions.fs
+++ b/src/FsSpreadsheet.Net/FsExtensions.fs
@@ -157,7 +157,7 @@ module FsExtensions =
///
static member fromXlsxTable table =
let topLeftBoundary, bottomRightBoundary = Table.getArea table |> Table.Area.toBoundaries
- let ra = FsRangeAddress(FsAddress(topLeftBoundary), FsAddress(bottomRightBoundary))
+ let ra = FsRangeAddress(FsAddress.fromString(topLeftBoundary), FsAddress.fromString(bottomRightBoundary))
let totalsRowShown = if table.TotalsRowShown = null then false else table.TotalsRowShown.Value
FsTable(table.DisplayName, ra, totalsRowShown, true)
diff --git a/src/FsSpreadsheet.Net/FsSpreadsheet.Net.fsproj b/src/FsSpreadsheet.Net/FsSpreadsheet.Net.fsproj
index 1eaab41e..162dde06 100644
--- a/src/FsSpreadsheet.Net/FsSpreadsheet.Net.fsproj
+++ b/src/FsSpreadsheet.Net/FsSpreadsheet.Net.fsproj
@@ -35,7 +35,7 @@
-
+
diff --git a/src/FsSpreadsheet.Net/ZipArchiveReader.fs b/src/FsSpreadsheet.Net/ZipArchiveReader.fs
index e0f31fc9..bd806ac5 100644
--- a/src/FsSpreadsheet.Net/ZipArchiveReader.fs
+++ b/src/FsSpreadsheet.Net/ZipArchiveReader.fs
@@ -177,7 +177,7 @@ let parseTable (sheet : ZipArchiveEntry) =
while reader.Read() do
if XmlReader.isElemWithName reader "table" then
let area = reader.GetAttribute("ref")
- let ra = FsRangeAddress(area)
+ let ra = FsRangeAddress.fromString(area)
let totalsRowShown =
let attribute = reader.GetAttribute("totalsRowShown")
match attribute with
@@ -283,7 +283,7 @@ let parseWorksheet (name : string) (styles : Styles) (sharedStrings : SharedStri
f <- cellReader.ReadElementContentAsString()
if v <> null && v <> "" || f <> null then
let cellValue,dataType = parseCell sharedStrings styles v t s f
- let cell = FsCell(cellValue,dataType = dataType,address = FsAddress(r))
+ let cell = FsCell(cellValue,dataType = dataType,address = FsAddress.fromString(r))
ws.AddCell(cell) |> ignore
if XmlReader.isElemWithName reader "tablePart" then
let id = reader.GetAttribute("r:id")
diff --git a/src/FsSpreadsheet.Py/FsSpreadsheet.Py.fsproj b/src/FsSpreadsheet.Py/FsSpreadsheet.Py.fsproj
index 5c801546..ff6a01b5 100644
--- a/src/FsSpreadsheet.Py/FsSpreadsheet.Py.fsproj
+++ b/src/FsSpreadsheet.Py/FsSpreadsheet.Py.fsproj
@@ -18,7 +18,7 @@
-
+
diff --git a/src/FsSpreadsheet.Py/Table.fs b/src/FsSpreadsheet.Py/Table.fs
index 86c11b5a..cb084dda 100644
--- a/src/FsSpreadsheet.Py/Table.fs
+++ b/src/FsSpreadsheet.Py/Table.fs
@@ -32,4 +32,4 @@ module PyTable =
let toFsTable(table:Table) =
let name = if isNull table.displayName then table.name else table.displayName
let ref = table.ref
- FsTable(name,FsRangeAddress(ref))
+ FsTable(name,FsRangeAddress.fromString(ref))
diff --git a/src/FsSpreadsheet/Cells/FsCell.fs b/src/FsSpreadsheet/Cells/FsCell.fs
index 0bf90834..0dafd032 100644
--- a/src/FsSpreadsheet/Cells/FsCell.fs
+++ b/src/FsSpreadsheet/Cells/FsCell.fs
@@ -74,7 +74,7 @@ type FsCell (value : obj, ?dataType : DataType, ?address : FsAddress) =
let mutable _rowIndex : int = address |> Option.map (fun a -> a.RowNumber) |> Option.defaultValue 0
let mutable _columnIndex : int = address |> Option.map (fun a -> a.ColumnNumber) |> Option.defaultValue 0
- new(value: IConvertible, ?dataType : DataType, ?address : FsAddress) = FsCell(box value, ?dataType = dataType, ?address = address)
+ //new(value: IConvertible, ?dataType : DataType, ?address : FsAddress) = FsCell(box value, ?dataType = dataType, ?address = address)
/// Creates an empty FsCell, set at row 0, column 0 (1-based).
static member inline empty () = FsCell ("", DataType.Empty, FsAddress(0,0))
diff --git a/src/FsSpreadsheet/Cells/FsCellsCollection.fs b/src/FsSpreadsheet/Cells/FsCellsCollection.fs
index 64a53d35..08b42bdc 100644
--- a/src/FsSpreadsheet/Cells/FsCellsCollection.fs
+++ b/src/FsSpreadsheet/Cells/FsCellsCollection.fs
@@ -1,6 +1,7 @@
namespace FsSpreadsheet
open System.Collections.Generic
+open Fable.Core
module Dictionary =
@@ -13,6 +14,7 @@ module Dictionary =
///
///
///
+[]
type FsCellsCollection() =
// ---------
@@ -98,7 +100,7 @@ type FsCellsCollection() =
/// Derives row- and columnIndices from the FsAddress of the FsCells.
static member createFromCells (cells : seq) =
let fcc = FsCellsCollection()
- fcc.Add cells
+ fcc.AddMany cells
fcc
// TO DO: Must create deep copy methods for ALL other objects in it first, and call them here.
@@ -107,7 +109,7 @@ type FsCellsCollection() =
// let newCellsColl = FsCellsCollection()
// let oldCells : seq = this.GetCells()
// let newCells = // create deep copy here
- // newCellsColl.Add cells
+ // newCellsColl.AddMany cells
/////
///// Creates and returns a deep copy of an FsCellsCollection.
@@ -138,10 +140,12 @@ type FsCellsCollection() =
///
/// Adds an FsCell of given rowIndex and columnIndex to the FsCellsCollection.
///
- member this.Add(row : int32, column : int32, cell : FsCell) =
+ member this.Add(cell : FsCell, ?row : int32, ?column : int32) =
- cell.RowNumber <- row
- cell.ColumnNumber <- column
+ if row.IsSome then cell.RowNumber <- row.Value
+ if column.IsSome then cell.ColumnNumber <- column.Value
+ let row = cell.RowNumber
+ let column = cell.ColumnNumber
_count <- _count + 1
FsCellsCollection.IncrementUsage(_rowsUsed, row);
@@ -170,14 +174,7 @@ type FsCellsCollection() =
/// Adds an FsCell of given rowIndex and columnIndex to an FsCellsCollection.
///
static member addCellWithIndeces rowIndex colIndex (cell : FsCell) (cellsCollection : FsCellsCollection) =
- cellsCollection.Add(rowIndex, colIndex, cell)
-
- ///
- /// Adds an FsCell to the FsCellsCollection.
- ///
- /// Derives row- and columnIndex from the FsAddress of the FsCell.
- member this.Add(cell : FsCell) =
- this.Add(cell.Address.RowNumber, cell.Address.ColumnNumber, cell)
+ cellsCollection.Add(cell, rowIndex, colIndex)
///
/// Adds an FsCell to an FsCellsCollection.
@@ -191,7 +188,7 @@ type FsCellsCollection() =
/// Adds FsCells to the FsCellsCollection.
///
/// Derives row- and columnIndeces from the FsAddress of the FsCells.
- member this.Add(cells : seq) =
+ member this.AddMany(cells : seq) =
cells |> Seq.iter (this.Add >> ignore)
///
@@ -199,7 +196,7 @@ type FsCellsCollection() =
///
/// Derives row- and columnIndeces from the FsAddress of the FsCells.
static member addCells (cells : seq) (cellsCollection : FsCellsCollection) =
- cellsCollection.Add cells
+ cellsCollection.AddMany cells
cellsCollection
///
@@ -326,7 +323,7 @@ type FsCellsCollection() =
///
/// Returns the FsCells from given rowStart to rowEnd and columnStart to columnEnd and fulfilling the predicate.
///
- member this.GetCells(rowStart : int32, columnStart : int32, rowEnd : int32, columnEnd : int32, predicate : FsCell -> bool) =
+ member this.GetCellsInRangeBy(rowStart : int32, columnStart : int32, rowEnd : int32, columnEnd : int32, predicate : FsCell -> bool) =
let finalRow = if rowEnd > _maxRowUsed then _maxRowUsed else rowEnd
let finalColumn = if columnEnd > _maxColumnUsed then _maxColumnUsed else columnEnd
@@ -347,25 +344,25 @@ type FsCellsCollection() =
/// Returns the FsCells from an FsCellsCollection with given rowStart to rowEnd and columnStart to columnEnd and fulfilling the predicate.
///
static member filterCellsFromTo rowStart columnStart rowEnd columnEnd (predicate : FsCell -> bool) (cellsCollection : FsCellsCollection) =
- cellsCollection.GetCells(rowStart, columnStart, rowEnd, columnEnd, predicate)
+ cellsCollection.GetCellsInRangeBy(rowStart, columnStart, rowEnd, columnEnd, predicate)
///
/// Returns the FsCells from given startAddress to lastAddress and fulfilling the predicate.
///
- member this.GetCells(startAddress : FsAddress, lastAddress : FsAddress, predicate : FsCell -> bool) =
- this.GetCells(startAddress.RowNumber,startAddress.ColumnNumber,lastAddress.RowNumber,lastAddress.ColumnNumber, predicate)
+ member this.GetCellsInStringRangeBy(startAddress : FsAddress, lastAddress : FsAddress, predicate : FsCell -> bool) =
+ this.GetCellsInRangeBy(startAddress.RowNumber,startAddress.ColumnNumber,lastAddress.RowNumber,lastAddress.ColumnNumber, predicate)
///
/// Returns the FsCells from an FsCellsCollection with given startAddress to lastAddress and fulfilling the predicate.
///
static member filterCellsFromToAddress startAddress lastAddress (predicate : FsCell -> bool) (cellsCollection : FsCellsCollection) =
- cellsCollection.GetCells(startAddress, lastAddress, predicate)
+ cellsCollection.GetCellsInStringRangeBy(startAddress, lastAddress, predicate)
///
/// Returns the FsCells from given rowStart to rowEnd and columnStart to columnEnd.
///
- member this.GetCells(rowStart : int32, columnStart : int32, rowEnd : int32, columnEnd : int32) =
+ member this.GetCellsInRange(rowStart : int32, columnStart : int32, rowEnd : int32, columnEnd : int32) =
let finalRow = if rowEnd > _maxRowUsed then _maxRowUsed else rowEnd
let finalColumn = if columnEnd > _maxColumnUsed then _maxColumnUsed else columnEnd
seq {
@@ -385,19 +382,19 @@ type FsCellsCollection() =
/// Returns the FsCells from an FsCellsCollection with given rowStart to rowEnd and columnStart to columnEnd.
///
static member getCellsFromTo rowStart columnStart rowEnd columnEnd (cellsCollection : FsCellsCollection) =
- cellsCollection.GetCells(rowStart, columnStart, rowEnd, columnEnd)
+ cellsCollection.GetCellsInRange(rowStart, columnStart, rowEnd, columnEnd)
///
/// Returns the FsCells from given startAddress to lastAddress.
///
- member this.GetCells(startAddress : FsAddress, lastAddress : FsAddress) =
- this.GetCells(startAddress.RowNumber,startAddress.ColumnNumber,lastAddress.RowNumber,lastAddress.ColumnNumber)
+ member this.GetCellsInStringRange(startAddress : FsAddress, lastAddress : FsAddress) =
+ this.GetCellsInRange(startAddress.RowNumber,startAddress.ColumnNumber,lastAddress.RowNumber,lastAddress.ColumnNumber)
///
/// Returns the FsCells from an FsCellsCollection with given startAddress to lastAddress.
///
static member getCellsFromToAddress startAddress lastAddress (cellsCollection : FsCellsCollection) =
- cellsCollection.GetCells(startAddress, lastAddress)
+ cellsCollection.GetCellsInStringRange(startAddress, lastAddress)
//public int FirstRowUsed(int rowStart, int columnStart, int rowEnd, int columnEnd, XLCellsUsedOptions options,
// Func predicate = null)
@@ -670,7 +667,7 @@ type FsCellsCollection() =
/// Returns all FsCells in the given columnIndex.
///
member this.GetCellsInColumn(colIndex) =
- this.GetCells(1, colIndex, _maxRowUsed, colIndex)
+ this.GetCellsInRange(1, colIndex, _maxRowUsed, colIndex)
///
/// Returns all FsCells in an FsCellsCollection with the given columnIndex.
@@ -682,7 +679,7 @@ type FsCellsCollection() =
/// Returns all FsCells in the given rowIndex.
///
member this.GetCellsInRow(rowIndex) =
- this.GetCells(rowIndex, 1, rowIndex, _maxColumnUsed)
+ this.GetCellsInRange(rowIndex, 1, rowIndex, _maxColumnUsed)
///
/// Returns all FsCells in an FsCellsCollection with the given rowIndex.
diff --git a/src/FsSpreadsheet/FsAddress.fs b/src/FsSpreadsheet/FsAddress.fs
index 872d28bd..a49a06ef 100644
--- a/src/FsSpreadsheet/FsAddress.fs
+++ b/src/FsSpreadsheet/FsAddress.fs
@@ -1,5 +1,6 @@
namespace FsSpreadsheet
+open Fable.Core
/// Module containing functions to work with "A1" style excel cell references.
module CellReference =
@@ -86,11 +87,11 @@ module CellReference =
|> fun (c,r) -> c, (int64 r) + (int64 amount) |> uint32
||> ofIndices
+[]
+type FsAddress(rowNumber : int, columnNumber : int, ?fixedRow : bool, ?fixedColumn : bool) =
-type FsAddress(rowNumber : int, columnNumber : int, fixedRow : bool, fixedColumn : bool) =
-
- let mutable _fixedRow = fixedRow
- let mutable _fixedColumn = fixedColumn
+ let mutable _fixedRow = if fixedRow.IsSome then fixedRow.Value else false
+ let mutable _fixedColumn = if fixedColumn.IsSome then fixedColumn.Value else false
let mutable _rowNumber = rowNumber
let mutable _columnNumber = columnNumber
@@ -100,15 +101,9 @@ type FsAddress(rowNumber : int, columnNumber : int, fixedRow : bool, fixedColumn
// ALTERNATE CONSTRUCTORS
// ----------------------
- new (rowNumber : int, columnLetter : string, fixedRow : bool, fixedColumn : bool) =
- FsAddress(rowNumber,CellReference.colAdressToIndex columnLetter |> int,fixedRow,fixedColumn)
-
- new (rowNumber : int, columnNumber : int) =
- FsAddress(rowNumber,columnNumber,false,false)
-
- new (cellAddressString : string) =
+ static member fromString (cellAddressString : string, ?fixedRow, ?fixedColumn) =
let colIndex,rowIndex = CellReference.toIndices cellAddressString
- FsAddress(int rowIndex,int colIndex)
+ FsAddress(int rowIndex,int colIndex, ?fixedRow = fixedRow, ?fixedColumn = fixedColumn)
// ----------
// PROPERTIES
@@ -188,4 +183,16 @@ type FsAddress(rowNumber : int, columnNumber : int, fixedRow : bool, fixedColumn
/// Checks if 2 FsAddresses are equal.
static member compare (address1 : FsAddress) (address2 : FsAddress) =
- address1.Compare address2
\ No newline at end of file
+ address1.Compare address2
+
+ override this.GetHashCode (): int =
+ this.Address.GetHashCode()
+ |> HashCodes.mergeHashes this.ColumnNumber
+ |> HashCodes.mergeHashes this.RowNumber
+ |> HashCodes.mergeHashes (this.FixedColumn.GetHashCode())
+ |> HashCodes.mergeHashes (this.FixedRow.GetHashCode())
+
+ override this.Equals(other: obj) =
+ match other with
+ | :? FsAddress as other -> this.Compare other
+ | _ -> false
diff --git a/src/FsSpreadsheet/FsColumn.fs b/src/FsSpreadsheet/FsColumn.fs
index 0ba979ec..321b4b58 100644
--- a/src/FsSpreadsheet/FsColumn.fs
+++ b/src/FsSpreadsheet/FsColumn.fs
@@ -88,7 +88,7 @@ type FsColumn (rangeAddress : FsRangeAddress, cells : FsCellsCollection)=
let ra = this.RangeAddress.Copy()
let cells = this.Cells |> Seq.map (fun c -> c.Copy())
let fcc = FsCellsCollection()
- fcc.Add cells
+ fcc.AddMany cells
FsColumn(ra, fcc)
///
diff --git a/src/FsSpreadsheet/FsRow.fs b/src/FsSpreadsheet/FsRow.fs
index 368e87cc..d1067658 100644
--- a/src/FsSpreadsheet/FsRow.fs
+++ b/src/FsSpreadsheet/FsRow.fs
@@ -90,7 +90,7 @@ type FsRow (rangeAddress : FsRangeAddress, cells : FsCellsCollection) =
let ra = this.RangeAddress.Copy()
let cells = this.Cells |> Seq.map (fun c -> c.Copy())
let fcc = FsCellsCollection()
- fcc.Add cells
+ fcc.AddMany cells
FsRow(ra, fcc)
///
@@ -155,7 +155,7 @@ type FsRow (rangeAddress : FsRangeAddress, cells : FsCellsCollection) =
///
member this.InsertValueAt(colIndex, (value : 'a)) =
let cell = FsCell(value)
- cells.Add(int32 this.Index, int32 colIndex, cell)
+ cells.Add(cell, int32 this.Index, int32 colIndex)
///
/// Adds a value at the given row- and columnIndex to FsRow using.
diff --git a/src/FsSpreadsheet/FsSpreadsheet.fsproj b/src/FsSpreadsheet/FsSpreadsheet.fsproj
index 0f1c43c3..ac85f55d 100644
--- a/src/FsSpreadsheet/FsSpreadsheet.fsproj
+++ b/src/FsSpreadsheet/FsSpreadsheet.fsproj
@@ -6,6 +6,7 @@
+
@@ -55,7 +56,7 @@
-
+
diff --git a/src/FsSpreadsheet/FsWorksheet.fs b/src/FsSpreadsheet/FsWorksheet.fs
index 6a076fd0..2e1791e9 100644
--- a/src/FsSpreadsheet/FsWorksheet.fs
+++ b/src/FsSpreadsheet/FsWorksheet.fs
@@ -537,18 +537,9 @@ type FsWorksheet (name, ?fsRows, ?fsTables, ?fsCellsCollection) =
/// Adds a sequence of FsCells to the FsWorksheet. !Exception if cell address already exists!
///
member self.AddCells (cells:seq) =
- self.CellCollection.Add cells |> ignore
+ self.CellCollection.AddMany cells |> ignore
self
- ///
- /// Adds a value at the given row- and columnIndex to the FsWorksheet.
- ///
- /// If a cell exists at the given postion, it is shoved to the right.
- ///
- member self.InsertValueAt(value : System.IConvertible, rowIndex, colIndex)=
- let cell = FsCell(value)
- self.CellCollection.Add(int32 rowIndex, int32 colIndex, cell)
-
///
/// Adds a value at the given row- and columnIndex to the FsWorksheet.
///
@@ -556,7 +547,7 @@ type FsWorksheet (name, ?fsRows, ?fsTables, ?fsCellsCollection) =
///
member self.InsertValueAt(value : obj, rowIndex, colIndex)=
let cell = FsCell(value)
- self.CellCollection.Add(int32 rowIndex, int32 colIndex, cell)
+ self.CellCollection.Add(cell, int32 rowIndex, int32 colIndex)
///
/// Adds a value at the given row- and columnIndex to a given FsWorksheet.
@@ -577,7 +568,7 @@ type FsWorksheet (name, ?fsRows, ?fsTables, ?fsCellsCollection) =
c.SetValueAs value |> ignore
self
| None ->
- self.CellCollection.Add(rowIndex, colIndex, value) |> ignore
+ self.CellCollection.Add(value, rowIndex, colIndex) |> ignore
self
///
diff --git a/src/FsSpreadsheet/HashCodes.fs b/src/FsSpreadsheet/HashCodes.fs
new file mode 100644
index 00000000..a5cf6fe3
--- /dev/null
+++ b/src/FsSpreadsheet/HashCodes.fs
@@ -0,0 +1,38 @@
+module FsSpreadsheet.HashCodes
+
+let mergeHashes (hash1 : int) (hash2 : int) : int =
+ 0x9e3779b9 + hash2 + (hash1 <<< 6) + (hash1 >>> 2)
+
+let hashDateTime (dt : System.DateTime) : int =
+ let mutable acc = 0
+ acc <- mergeHashes acc dt.Year
+ acc <- mergeHashes acc dt.Month
+ acc <- mergeHashes acc dt.Day
+ acc <- mergeHashes acc dt.Hour
+ acc <- mergeHashes acc dt.Minute
+ acc <- mergeHashes acc dt.Second
+ acc
+
+
+let hash obj =
+ obj.GetHashCode()
+
+let boxHashOption (a: 'a option) : obj =
+ if a.IsSome then a.Value.GetHashCode() else (0).GetHashCode()
+ |> box
+
+let boxHashArray (a: 'a []) : obj =
+ a
+ // from https://stackoverflow.com/a/53507559
+ |> Array.fold (fun acc o ->
+ hash o
+ |> mergeHashes acc) 0
+ |> box
+
+let boxHashSeq (a: seq<'a>) : obj =
+ a
+ // from https://stackoverflow.com/a/53507559
+ |> Seq.fold (fun acc o ->
+ hash o
+ |> mergeHashes acc) 0
+ |> box
\ No newline at end of file
diff --git a/src/FsSpreadsheet/Json/Table.fs b/src/FsSpreadsheet/Json/Table.fs
index 3514660b..34d2d54f 100644
--- a/src/FsSpreadsheet/Json/Table.fs
+++ b/src/FsSpreadsheet/Json/Table.fs
@@ -20,5 +20,5 @@ let decode : Decoder =
Decode.object (fun builder ->
let n = builder.Required.Field name Decode.string
let r = builder.Required.Field range Decode.string
- FsTable(n, FsRangeAddress(r))
+ FsTable(n, FsRangeAddress.fromString(r))
)
\ No newline at end of file
diff --git a/src/FsSpreadsheet/Ranges/FsRange.fs b/src/FsSpreadsheet/Ranges/FsRange.fs
index 2705d59d..1a66a9c9 100644
--- a/src/FsSpreadsheet/Ranges/FsRange.fs
+++ b/src/FsSpreadsheet/Ranges/FsRange.fs
@@ -1,12 +1,13 @@
namespace FsSpreadsheet
+open Fable.Core
-type FsRange(rangeAddress : FsRangeAddress, styleValue) =
+[]
+type FsRange(rangeAddress : FsRangeAddress, ?styleValue) =
inherit FsRangeBase(rangeAddress)
- new (rangeAddress : FsRangeAddress) = FsRange(rangeAddress, null)
- new (rangeBase : FsRangeBase) = FsRange(rangeBase.RangeAddress, null)
+ static member fromRangeBase (rangeBase : FsRangeBase) = FsRange(rangeBase.RangeAddress, null)
member self.Row(row : int32) =
if (row <= 0 || row + base.RangeAddress.FirstAddress.RowNumber - 1 > 1048576 ) then
diff --git a/src/FsSpreadsheet/Ranges/FsRangeAddress.fs b/src/FsSpreadsheet/Ranges/FsRangeAddress.fs
index 2f7bf67c..4b5f7642 100644
--- a/src/FsSpreadsheet/Ranges/FsRangeAddress.fs
+++ b/src/FsSpreadsheet/Ranges/FsRangeAddress.fs
@@ -151,22 +151,21 @@ module Range =
printfn "Area \"%s\" could not be parsed: %s" area err.Message
false
-[]
+[][]
type FsRangeAddress(firstAddress : FsAddress, lastAddress : FsAddress) =
let mutable _firstAddress = firstAddress
let mutable _lastAddress = lastAddress
-
- new(rangeAddress) =
- let firstAdress,lastAddress = Range.toBoundaries rangeAddress
- FsRangeAddress(FsAddress(firstAdress),FsAddress(lastAddress))
+ static member fromString (rangeAddress : string) =
+ let firstAdress, lastAddress = Range.toBoundaries rangeAddress
+ FsRangeAddress(FsAddress.fromString(firstAdress),FsAddress.fromString(lastAddress))
///
/// Creates a deep copy of this FsRangeAddress.
///
member self.Copy() =
- FsRangeAddress(self.Range)
+ FsRangeAddress.fromString (self.Range)
///
/// Returns a deep copy of a given FsRangeAddress.
@@ -203,11 +202,11 @@ type FsRangeAddress(firstAddress : FsAddress, lastAddress : FsAddress) =
_lastAddress <- FsAddress(lastRow,lastColumn)
member self.Range
- with get() = Range.ofBoundaries _firstAddress.Address _lastAddress.Address
+ with get() : string = Range.ofBoundaries _firstAddress.Address _lastAddress.Address
and set(address) =
let firstAdress, lastAdress = Range.toBoundaries address
- _firstAddress <- FsAddress (firstAdress)
- _lastAddress <- FsAddress (lastAdress)
+ _firstAddress <- FsAddress.fromString (firstAdress)
+ _lastAddress <- FsAddress.fromString (lastAdress)
override self.ToString() =
self.Range
diff --git a/src/FsSpreadsheet/Ranges/FsRangeBase.fs b/src/FsSpreadsheet/Ranges/FsRangeBase.fs
index 9cbf638d..e89ab84c 100644
--- a/src/FsSpreadsheet/Ranges/FsRangeBase.fs
+++ b/src/FsSpreadsheet/Ranges/FsRangeBase.fs
@@ -1,93 +1,94 @@
-namespace FsSpreadsheet
-
-
-[][]
-type FsRangeBase (rangeAddress : FsRangeAddress) =
- //: XLStylizedBase, IXLRangeBase, IXLStylized
-
-
- let mutable _sortRows = null
- let mutable _sortColumns = null
- let mutable _rangeAddress = rangeAddress
-
-
- static let mutable IdCounter = 0;
- let _id =
- IdCounter <- IdCounter + 1
- IdCounter
-
- //abstract member OnRangeAddressChanged : FsRangeAddress*FsRangeAddress -> unit
-
- //default this.OnRangeAddressChanged (oldAddress, newAddress) =
-
- // Worksheet.RellocateRange(RangeType, oldAddress, newAddress);
-
- member this.Extend(address : FsAddress) = _rangeAddress.Extend(address)
-
- member this.RangeAddress
- with get () = _rangeAddress
- and set (rangeAdress) =
- if rangeAdress <> _rangeAddress then
- let oldAddress = _rangeAddress
- _rangeAddress <- rangeAdress
- //OnRangeAddressChanged(oldAddress, _rangeAddress);
-
- // TO DO: add description – important and complex function
- member this.Cell(cellAddressInRange : FsAddress, cells : FsCellsCollection) =
-
- 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
-
- if (absColumn <= 0 || absColumn > 16384) then
- failwithf "Column number must be between 1 and %i" cells.MaxColumnNumber
-
- let cell = cells.TryGetCell(absRow, absColumn)
-
- match cell with
- | Some cell ->
- cell
- | None ->
-
- //var styleValue = this.StyleValue;
-
- //if (styleValue == Worksheet.StyleValue)
- //{
- // if (Worksheet.Internals.RowsCollection.TryGetValue(absRow, out XLRow row)
- // && row.StyleValue != Worksheet.StyleValue)
- // styleValue = row.StyleValue;
- // else if (Worksheet.Internals.ColumnsCollection.TryGetValue(absColumn, out XLColumn column)
- // && column.StyleValue != Worksheet.StyleValue)
- // styleValue = column.StyleValue;
- //}
- let absoluteAddress = new FsAddress(absRow, absColumn, cellAddressInRange.FixedRow, cellAddressInRange.FixedColumn);
-
- // If the default style for this range base is empty, but the worksheet
- // has a default style, use the worksheet's default style
- let newCell = FsCell.createEmptyWithAdress absoluteAddress
-
- this.Extend(absoluteAddress)
-
- cells.Add(absRow, absColumn, newCell) |> ignore
- newCell
+namespace FsSpreadsheet
+
+open Fable.Core
+
+[][][]
+type FsRangeBase (rangeAddress : FsRangeAddress) =
+ //: XLStylizedBase, IXLRangeBase, IXLStylized
+
+
+ let mutable _sortRows = null
+ let mutable _sortColumns = null
+ let mutable _rangeAddress = rangeAddress
+
+
+ static let mutable IdCounter = 0;
+ let _id =
+ IdCounter <- IdCounter + 1
+ IdCounter
+
+ //abstract member OnRangeAddressChanged : FsRangeAddress*FsRangeAddress -> unit
+
+ //default this.OnRangeAddressChanged (oldAddress, newAddress) =
+
+ // Worksheet.RellocateRange(RangeType, oldAddress, newAddress);
+
+ member this.Extend(address : FsAddress) = _rangeAddress.Extend(address)
+
+ member this.RangeAddress
+ with get () = _rangeAddress
+ and set (rangeAdress) =
+ if rangeAdress <> _rangeAddress then
+ let oldAddress = _rangeAddress
+ _rangeAddress <- rangeAdress
+ //OnRangeAddressChanged(oldAddress, _rangeAddress);
+
+ // TO DO: add description – important and complex function
+ member this.Cell(cellAddressInRange : FsAddress, cells : FsCellsCollection) =
+
+ 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
+
+ if (absColumn <= 0 || absColumn > 16384) then
+ failwithf "Column number must be between 1 and %i" cells.MaxColumnNumber
+
+ let cell = cells.TryGetCell(absRow, absColumn)
+
+ match cell with
+ | Some cell ->
+ cell
+ | None ->
+
+ //var styleValue = this.StyleValue;
+
+ //if (styleValue == Worksheet.StyleValue)
+ //{
+ // if (Worksheet.Internals.RowsCollection.TryGetValue(absRow, out XLRow row)
+ // && row.StyleValue != Worksheet.StyleValue)
+ // styleValue = row.StyleValue;
+ // else if (Worksheet.Internals.ColumnsCollection.TryGetValue(absColumn, out XLColumn column)
+ // && column.StyleValue != Worksheet.StyleValue)
+ // styleValue = column.StyleValue;
+ //}
+ let absoluteAddress = new FsAddress(absRow, absColumn, cellAddressInRange.FixedRow, cellAddressInRange.FixedColumn);
+
+ // If the default style for this range base is empty, but the worksheet
+ // has a default style, use the worksheet's default style
+ let newCell = FsCell.createEmptyWithAdress absoluteAddress
+
+ this.Extend(absoluteAddress)
+
+ cells.Add(newCell, absRow, absColumn) |> ignore
+ newCell
///
/// Returns the FsCells of this FsRangeBase with the given FsCellsCollection.
///
- /// The FsCellsCollection where the FsCells are retrieved from.
- member this.Cells(cells : FsCellsCollection) =
- cells.GetCells(this.RangeAddress.FirstAddress, this.RangeAddress.LastAddress)
-
+ /// The FsCellsCollection where the FsCells are retrieved from.
+ member this.Cells(cells : FsCellsCollection) =
+ cells.GetCellsInStringRange(this.RangeAddress.FirstAddress, this.RangeAddress.LastAddress)
+
///
/// The number of columns in the FsRangeBase.
- ///
- member this.ColumnCount() =
- _rangeAddress.LastAddress.ColumnNumber - _rangeAddress.FirstAddress.ColumnNumber + 1
-
+ ///
+ member this.ColumnCount() =
+ _rangeAddress.LastAddress.ColumnNumber - _rangeAddress.FirstAddress.ColumnNumber + 1
+
///
/// The number of rows in the FsRangeBase.
- ///
- member this.RowCount() =
+ ///
+ member this.RowCount() =
_rangeAddress.LastAddress.RowNumber - _rangeAddress.FirstAddress.RowNumber + 1
\ No newline at end of file
diff --git a/src/FsSpreadsheet/Ranges/FsRangeColumn.fs b/src/FsSpreadsheet/Ranges/FsRangeColumn.fs
index 3be5a76a..d5c5029b 100644
--- a/src/FsSpreadsheet/Ranges/FsRangeColumn.fs
+++ b/src/FsSpreadsheet/Ranges/FsRangeColumn.fs
@@ -1,6 +1,8 @@
namespace FsSpreadsheet
-[]
+open Fable.Core
+
+[][]
type FsRangeColumn(rangeAddress) =
inherit FsRangeBase(rangeAddress)
@@ -9,7 +11,7 @@ type FsRangeColumn(rangeAddress) =
// let range = FsRangeAddress(FsAddress(0,0),FsAddress(0,0))
// FsRangeColumn(range)
- new(index) = FsRangeColumn(FsRangeAddress(FsAddress(0, index), FsAddress(0, index)))
+ static member fromIndex (index) = FsRangeColumn(FsRangeAddress(FsAddress(0, index), FsAddress(0, index)))
//new(rangeAddress) = FsRangeColumn()
diff --git a/src/FsSpreadsheet/Ranges/FsRangeRow.fs b/src/FsSpreadsheet/Ranges/FsRangeRow.fs
index 0631ba7b..d74f4020 100644
--- a/src/FsSpreadsheet/Ranges/FsRangeRow.fs
+++ b/src/FsSpreadsheet/Ranges/FsRangeRow.fs
@@ -1,6 +1,8 @@
namespace FsSpreadsheet
-[]
+open Fable.Core
+
+[][]
type FsRangeRow(rangeAddress) =
inherit FsRangeBase(rangeAddress)
@@ -9,7 +11,7 @@ type FsRangeRow(rangeAddress) =
// let range = FsRangeAddress(FsAddress(0,0),FsAddress(0,0))
// FsRangeColumn(range)
- new (index) = FsRangeRow (FsRangeAddress(FsAddress(index,0),FsAddress(index,0)))
+ static member fromIndex (index) = FsRangeRow (FsRangeAddress(FsAddress(index,0),FsAddress(index,0)))
member self.Index
with get() = self.RangeAddress.FirstAddress.RowNumber
diff --git a/src/FsSpreadsheet/Tables/FsTable.fs b/src/FsSpreadsheet/Tables/FsTable.fs
index c61cee0c..bdeab409 100644
--- a/src/FsSpreadsheet/Tables/FsTable.fs
+++ b/src/FsSpreadsheet/Tables/FsTable.fs
@@ -1,471 +1,471 @@
-namespace FsSpreadsheet
-
-open System.Collections.Generic
-
-open Fable.Core
-
-///
-/// Creates an FsTable from the given name and FsRangeAddres, with totals row shown and header row shown or not, accordingly.
-///
-[]
-type FsTable (name : string, rangeAddress : FsRangeAddress, ?showTotalsRow : bool, ?showHeaderRow : bool) =
-
- inherit FsRangeBase(rangeAddress)
-
- let mutable _name = name.Trim().Replace(" ","_")
-
- let mutable _lastRangeAddress = rangeAddress
- let mutable _showTotalsRow : bool = Option.defaultValue false showTotalsRow
- let mutable _showHeaderRow : bool = Option.defaultValue true showHeaderRow
-
- let mutable _fieldNames : Dictionary = Dictionary()
- let _uniqueNames : HashSet = HashSet()
-
-
- ///
- /// The name of the FsTable.
- ///
- member this.Name
- with get() = _name
-
- ///
- /// Returns all fieldnames as `fieldname*FsTableField` dictionary.
- ///
- member this.GetFieldNames (cellsCollection : FsCellsCollection) =
- if (_fieldNames <> null && _lastRangeAddress <> null && _lastRangeAddress.Equals(this.RangeAddress)) then
- _fieldNames;
- else
- _lastRangeAddress <- this.RangeAddress
-
- //this.RescanFieldNames(cellsCollection)
-
- _fieldNames;
-
- ///
- /// The FsTableFields of this FsTable.
- ///
- member this.GetFields (cellsCollection : FsCellsCollection) =
- let columnCount = base.ColumnCount()
- //let offset = base.RangeAddress.FirstAddress.ColumnNumber
- Seq.init columnCount (fun i -> this.GetFieldAt(i, cellsCollection))
-
- ///
- /// Gets or sets if the header row is shown.
- ///
- member this.ShowHeaderRow
- with get () = _showHeaderRow
- and set(showHeaderRow) = _showHeaderRow <- showHeaderRow
-
- ///
- /// Returns the header row as FsRangeRow. Scans for new fieldnames.
- ///
- []
- member this.HeadersRow() =
- if (not this.ShowHeaderRow) then null;
- else
- FsRange(base.RangeAddress).FirstRow()
-
- member this.TryGetHeaderRow(cellsCollection) =
- match this.ShowHeaderRow with
- | false -> None
- | true ->
- let rowIndex = this.RangeAddress.FirstAddress.RowNumber
- let firstAddress = FsAddress(rowIndex, this.RangeAddress.FirstAddress.ColumnNumber)
- let lastAddress = FsAddress(rowIndex, this.RangeAddress.LastAddress.ColumnNumber)
- let range = FsRangeAddress (firstAddress, lastAddress)
- FsRow(range, cellsCollection) |> Some
-
- member this.GetHeaderRow(cellsCollection) =
- match this.TryGetHeaderRow(cellsCollection) with
- | Some hr -> hr
- | None -> failwith $"""Error. Unable to get header row for table "{this.Name}" as `ShowHeaderRow` is set to `false`."""
-
- ///
- /// Returns the FsColumns from the FsTable.
- ///
- /// The FsCellsCollection associated with this FsTable.
- member this.GetColumns(cellsCollection : FsCellsCollection) =
- seq {
- for i = this.RangeAddress.FirstAddress.ColumnNumber to this.RangeAddress.LastAddress.ColumnNumber do
- let firstAddress = FsAddress(this.RangeAddress.FirstAddress.RowNumber, i)
- let lastAddress = FsAddress(this.RangeAddress.LastAddress.RowNumber, i)
- let range = FsRangeAddress (firstAddress, lastAddress)
- FsColumn(range, cellsCollection)
- }
-
- ///
- /// Returns the FsRows from the FsTable.
- ///
- /// The FsCellsCollection associated with this FsTable.
- member this.GetRows(cellsCollection : FsCellsCollection) =
- seq {
- for i = this.RangeAddress.FirstAddress.RowNumber to this.RangeAddress.LastAddress.RowNumber do
- let firstAddress = FsAddress(i, this.RangeAddress.FirstAddress.ColumnNumber)
- let lastAddress = FsAddress(i, this.RangeAddress.LastAddress.ColumnNumber)
- let range = FsRangeAddress (firstAddress, lastAddress)
- FsRow(range, cellsCollection)
- }
-
- ///
- /// Updates the FsRangeAddress of the FsTable according to the FsTableFields associated.
- ///
- member this.RescanRange() =
- let rangeAddress =
- _fieldNames.Values
- |> Seq.map (fun v -> v.Column.RangeAddress)
- |> Seq.reduce (fun r1 r2 -> r1.Union(r2))
- base.RangeAddress <- rangeAddress
-
- ///
- /// Updates the FsRangeAddress of a given FsTable according to the FsTableFields associated.
- ///
- static member rescanRange (table : FsTable) =
- table.RescanRange()
- table
-
- ///
- /// Returns a unique name consisting of the original name and an initial offset that is raised
- /// if the original name with that offset is already present.
- ///
- /// Header name that was tried to be used.
- /// First number that together with the originalName, leads to a unique column header.
- /// If true, the initial offset is always applied.
- member this.GetUniqueName(originalName : string, initialOffset : int32, enforceOffset : bool) =
- let mutable name = originalName + if enforceOffset then string initialOffset else ""
- if _uniqueNames.Contains(name) then
-
- let mutable i = initialOffset
- name <- originalName + string i
- while _uniqueNames.Contains(name) do
-
- i <- i + 1
- name <- originalName + string i
-
- _uniqueNames.Add name |> ignore
- name
-
- ///
- /// Returns a unique name consisting of the original name and an initial offset that is raised
- /// if the original name with that offset is already present.
- ///
- /// Header name that was tried to be used.
- /// First number that together with the originalName, leads to a unique column header.
- /// If true, the initial offset is always applied.
- /// The FsTable on which this function is called.
- static member getUniqueNames originalName initialOffset enforceOffset (table : FsTable) =
- table.GetUniqueName(originalName, initialOffset, enforceOffset)
-
- ///
- /// Creates and adds FsTableFields from a sequence of field names to the FsTable.
- ///
- member this.InitFields(fieldNames : seq) =
- // _fieldNames = new Dictionary(); // let's _not_ do it this way.
- //let rangeCols = FsRangeAddress.toRangeColumns base.RangeAddress
- fieldNames
- |> Seq.iteri (
- fun i fn ->
- let tableField = FsTableField(fn, i, FsRangeColumn i)
- _fieldNames.Add(fn, tableField)
- )
-
- ///
- /// Creates and adds FsTableFields from a sequence of field names to a given FsTable.
- ///
- static member initFields (fieldNames : seq) (table : FsTable) =
- table.InitFields fieldNames
- table
-
- ///
- /// Adds a sequence of FsTableFields to the FsTable.
- ///
- member this.AddFields(tableFields : seq) =
- tableFields
- |> Seq.iter (
- fun tf -> _fieldNames.Add(tf.Name, tf)
- )
-
- ///
- /// Adds a sequence of FsTableFields to a given FsTable.
- ///
- static member addFields (tableFields : seq) (table : FsTable) =
- table.AddFields tableFields
- table
-
- ///
- /// Returns the FsTableField with given name. If an FsTableField does not exist under this name in the FsTable, adds it.
- ///
- member this.Field(name : string, cellsCollection : FsCellsCollection) =
- match Dictionary.tryGet name _fieldNames with
- | Some field ->
- field
- | None ->
- let maxIndex =
- _fieldNames.Values
- |> Seq.map (fun v -> v.Index)
- |> fun s ->
- if Seq.length s = 0 then 0 else Seq.max s
- let range =
- let offset = _fieldNames.Count
- let firstAddress = FsAddress(this.RangeAddress.FirstAddress.RowNumber,this.RangeAddress.FirstAddress.ColumnNumber + offset)
- let lastAddress = FsAddress(this.RangeAddress.LastAddress.RowNumber,this.RangeAddress.FirstAddress.ColumnNumber + offset)
- FsRangeAddress(firstAddress,lastAddress)
- let column = FsRangeColumn(range)
- let newField = FsTableField(name,maxIndex + 1,column,null,null)
- if this.ShowHeaderRow then
- newField.HeaderCell(cellsCollection,true).SetValueAs name |> ignore
- _fieldNames.Add(name,newField)
- this.RescanRange()
- newField
-
- ///
- /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of this
- /// FsTable) and returns the respective FsTableField.
- ///
- /// if the header row has no field with the given name.
- member this.GetField(name : string, cellsCollection : FsCellsCollection) =
- let name = name.Replace("\r\n", "\n")
- try this.GetFieldNames(cellsCollection).Item name
- with _ -> failwith <| "The header row doesn't contain field name '" + name + "'."
-
- ///
- /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of this
- /// FsTable) and returns the respective FsTableField.
- ///
- /// if the header row has no field with the given name.
- static member getField (name : string) (cellsCollection : FsCellsCollection) (table : FsTable) =
- table.GetField(name, cellsCollection)
-
- ///
- /// Takes the index of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of
- /// this FsTable) and returns the respective FsTableField.
- ///
- /// if the FsTable has no FsTableField with the given index.
- member this.GetFieldAt(index, cellsCollection) =
- try
- this.GetFieldNames(cellsCollection).Values
- |> Seq.find (fun ftf -> ftf.Index = index)
- with _ -> failwith $"FsTableField with index {index} does not exist in the FsTable."
-
- ///
- /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of
- /// this FsTable) and returns the index of the respective FsTableField.
- ///
- /// if the header row has no field with the given name.
- member this.GetFieldIndex(name : string, cellsCollection) =
- this.GetField(name, cellsCollection).Index
-
- ///
- /// Renames a fieldname of the FsTable if it exists. Else fails.
- ///
- /// if the FsTableField does not exist in the FsTable.
- member this.RenameField(oldName : string, newName : string) =
- match Dictionary.tryGet oldName _fieldNames with
- | Some field ->
- _fieldNames.Remove(oldName) |> ignore
- _fieldNames.Add(newName, field)
- | None ->
- raise (System.ArgumentException("The FsTabelField does not exist in this FsTable", "oldName"))
-
- ///
- /// Renames a fieldname of the FsTable if it exists. Else fails.
- ///
- /// if the FsTableField does not exist in the FsTable.
- static member renameField oldName newName (table : FsTable) =
- table.RenameField(oldName, newName)
- table
-
- ///
- /// Returns the header cell from a given FsCellsCollection with the given colum index if the cell exists. Else returns None.
- ///
- member this.TryGetHeaderCellOfColumnAt(cellsCollection : FsCellsCollection, colIndex : int) =
- let fstRowIndex = this.RangeAddress.FirstAddress.RowNumber
- cellsCollection.GetCellsInColumn colIndex
- |> Seq.tryFind (fun c -> c.RowNumber = fstRowIndex)
-
- ///
- /// Returns the header cell from a given FsCellsCollection with the given column index in a given FsTable if the cell exists. Else
- /// returns None.
- ///
- static member tryGetHeaderCellOfColumnIndexAt cellsCollection (colIndex : int) (table : FsTable) =
- table.TryGetHeaderCellOfColumnAt(cellsCollection, colIndex)
-
- ///
- /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection if the cell exists. Else returns None.
- ///
- member this.TryGetHeaderCellOfColumn(cellsCollection : FsCellsCollection, column : FsRangeColumn) =
- this.TryGetHeaderCellOfColumnAt(cellsCollection, column.Index)
-
- ///
- /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection in a given FsTable if the cell exists.
- /// Else returns None.
- ///
- static member tryGetHeaderCellOfColumn cellsCollection (column : FsRangeColumn) (table : FsTable) =
- table.TryGetHeaderCellOfColumn(cellsCollection, column)
-
- ///
- /// Returns the header cell from a given FsCellsCollection with the given colum index.
- ///
- /// if the FsCell cannot be found.
- member this.GetHeaderCellOfColumnAt(cellsCollection, colIndex : int) =
- this.TryGetHeaderCellOfColumnAt(cellsCollection, colIndex).Value
-
- ///
- /// Returns the header cell from a given FsCellsCollection with the given colum index in a given FsTable.
- ///
- /// if the FsCell cannot be found.
- static member getHeaderCellOfColumnIndexAt cellsCollection (colIndex : int) (table : FsTable) =
- table.GetHeaderCellOfColumnAt(cellsCollection, colIndex)
-
- ///
- /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection.
- ///
- /// if the FsCell cannot be found.
- member this.GetHeaderCellOfColumn(cellsCollection : FsCellsCollection, column : FsRangeColumn) =
- this.TryGetHeaderCellOfColumn(cellsCollection, column).Value
-
- ///
- /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection in a given FsTable.
- ///
- /// if the FsCell cannot be found.
- static member getHeaderCellOfColumn cellsCollection (column : FsRangeColumn) (table : FsTable) =
- table.GetHeaderCellOfColumn(cellsCollection, column)
-
- ///
- /// Returns the header cell of a given FsTableField from a given FsCellsCollection.
- ///
- member this.GetHeaderCellOfTableField(cellsCollection, tableField : FsTableField) =
- tableField.HeaderCell(cellsCollection, this.ShowHeaderRow)
-
- ///
- /// Returns the header cell of a given FsTableField from a given FsCellsCollection in a given FsTable.
- ///
- static member getHeaderCellOfTableField cellsCollection (tableField : FsTableField) (table : FsTable) =
- table.GetHeaderCellOfTableField(cellsCollection, tableField)
-
- ///
- /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection if the cell exists.
- /// Else returns None.
- ///
- member this.TryGetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex : int) =
- _fieldNames.Values
- |> Seq.tryPick (
- fun tf ->
- if tf.Index = tableFieldIndex then
- Some (tf.HeaderCell(cellsCollection, this.ShowHeaderRow))
- else None
- )
-
- ///
- /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection if the cell exists
- /// in a given FsTable. Else returns None.
- ///
- static member tryGetHeaderCellOfTableFieldIndexAt cellsCollection (tableFieldIndex : int) (table : FsTable) =
- table.TryGetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex)
-
- ///
- /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection.
- ///
- /// if the FsCell cannot be found.
- member this.GetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex : int) =
- this.TryGetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex).Value
-
- ///
- /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection in a given FsTable.
- ///
- /// if the FsCell cannot be found.
- static member getHeaderCellOfTableFieldIndexAt cellsCollection (tableFieldIndex : int) (table : FsTable) =
- table.GetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex)
-
- ///
- /// Returns the header cell from an FsTableField with the given name using an FsCellsCollection in the FsTable if the cell exists.
- /// Else returns None.
- ///
- member this.TryGetHeaderCellByFieldName(cellsCollection, fieldName : string) =
- match Dictionary.tryGet fieldName _fieldNames with
- | Some tf -> Some (tf.HeaderCell(cellsCollection, this.ShowHeaderRow))
- | None -> None
-
- ///
- /// Returns the header cell from an FsTableField with the given name using an FsCellsCollection in a given FsTable if the cell exists.
- /// Else returns None.
- ///
- static member tryGetHeaderCellByFieldName cellsCollection (fieldName : string) (table : FsTable) =
- table.TryGetHeaderCellByFieldName(cellsCollection, fieldName)
-
- ///
- /// Returns the data cells from a given FsCellsCollection with the given colum index.
- ///
- /// Column index must fit the FsCellsCollection, not the FsTable!
- member this.GetDataCellsOfColumnAt(cellsCollection : FsCellsCollection, colIndex) =
- let fstRowIndex = this.RangeAddress.FirstAddress.RowNumber
- let lstRowIndex = this.RangeAddress.LastAddress.RowNumber
- [fstRowIndex + 1 .. lstRowIndex]
- |> Seq.choose (
- fun ri -> cellsCollection.TryGetCell(ri, colIndex)
- )
-
- ///
- /// Returns the data cells from a given FsCellsCollection with the given colum index in a given FsTable.
- ///
- /// Column index must fit the FsCellsCollection, not the FsTable!
- static member getDataCellsOfColumnIndexAt cellsCollection (colIndex : int) (table : FsTable) =
- table.GetDataCellsOfColumnAt(cellsCollection, colIndex)
-
- // TO DO: add equivalents of the other methods regarding header cell for data cells.
-
- ///
- /// Creates a deep copy of this FsTable.
- ///
- member this.Copy() =
- let ra = this.RangeAddress.Copy()
- let nam = this.Name
- let shr = this.ShowHeaderRow
- FsTable(nam, ra, false, shr)
-
- ///
- /// Returns a deep copy of a given FsTable.
- ///
- static member copy (table : FsTable) =
- table.Copy()
-
-
- /// Updates the TableFields according to the range of the table and the underlying cellcollection.
- ///
- /// For this, maps over the range of the table and sets the header of the table fields to the value of the cell. If no cell value is set, the header value and the underlying cell value are set to a default value.
- member this.RescanFieldNames(cellsCollection : FsCellsCollection) =
- if this.ShowHeaderRow then
- let oldFieldNames = _fieldNames
- _fieldNames <- new Dictionary()
- let headersRow = this.GetHeaderRow(cellsCollection);
- let mutable cellPos = 0
- for cell in headersRow do
- let mutable name = cell.ValueAsString() //GetString();
- match Dictionary.tryGet name oldFieldNames with
- | Some tableField ->
- tableField.Index <- cellPos
- _fieldNames.Add(name,tableField)
- cellPos <- cellPos + 1
- | None ->
-
- // Be careful here. Fields names may actually be whitespace, but not empty
- if (name = null) <> (name = "") then // TO DO: ask: shouldn't this be XOR?
-
- name <- this.GetUniqueName("Column", cellPos + 1, true)
- cell.SetValueAs(name) |> ignore
- cell.DataType <- DataType.String
-
- if (_fieldNames.ContainsKey(name)) then
- raise (System.ArgumentException("The header row contains more than one field name '" + name + "'."))
-
- _fieldNames.Add(name, new FsTableField(name, cellPos))
- cellPos <- cellPos + 1
- else
-
- let colCount = base.ColumnCount();
- for i = 1 to colCount do
-
- if _fieldNames.Values |> Seq.exists (fun v -> v.Index = i - 1) |> not then
-
- let name = "Column" + string i;
-
+namespace FsSpreadsheet
+
+open System.Collections.Generic
+
+open Fable.Core
+
+///
+/// Creates an FsTable from the given name and FsRangeAddres, with totals row shown and header row shown or not, accordingly.
+///
+[]
+type FsTable (name : string, rangeAddress : FsRangeAddress, ?showTotalsRow : bool, ?showHeaderRow : bool) =
+
+ inherit FsRangeBase(rangeAddress)
+
+ let mutable _name = name.Trim().Replace(" ","_")
+
+ let mutable _lastRangeAddress = rangeAddress
+ let mutable _showTotalsRow : bool = Option.defaultValue false showTotalsRow
+ let mutable _showHeaderRow : bool = Option.defaultValue true showHeaderRow
+
+ let mutable _fieldNames : Dictionary = Dictionary()
+ let _uniqueNames : HashSet = HashSet()
+
+
+ ///
+ /// The name of the FsTable.
+ ///
+ member this.Name
+ with get() = _name
+
+ ///
+ /// Returns all fieldnames as `fieldname*FsTableField` dictionary.
+ ///
+ member this.GetFieldNames (cellsCollection : FsCellsCollection) =
+ if (_fieldNames <> null && _lastRangeAddress <> null && _lastRangeAddress.Equals(this.RangeAddress)) then
+ _fieldNames;
+ else
+ _lastRangeAddress <- this.RangeAddress
+
+ //this.RescanFieldNames(cellsCollection)
+
+ _fieldNames;
+
+ ///
+ /// The FsTableFields of this FsTable.
+ ///
+ member this.GetFields (cellsCollection : FsCellsCollection) =
+ let columnCount = base.ColumnCount()
+ //let offset = base.RangeAddress.FirstAddress.ColumnNumber
+ Seq.init columnCount (fun i -> this.GetFieldAt(i, cellsCollection))
+
+ ///
+ /// Gets or sets if the header row is shown.
+ ///
+ member this.ShowHeaderRow
+ with get () = _showHeaderRow
+ and set(showHeaderRow) = _showHeaderRow <- showHeaderRow
+
+ ///
+ /// Returns the header row as FsRangeRow. Scans for new fieldnames.
+ ///
+ []
+ member this.HeadersRow() =
+ if (not this.ShowHeaderRow) then null;
+ else
+ FsRange(base.RangeAddress).FirstRow()
+
+ member this.TryGetHeaderRow(cellsCollection) =
+ match this.ShowHeaderRow with
+ | false -> None
+ | true ->
+ let rowIndex = this.RangeAddress.FirstAddress.RowNumber
+ let firstAddress = FsAddress(rowIndex, this.RangeAddress.FirstAddress.ColumnNumber)
+ let lastAddress = FsAddress(rowIndex, this.RangeAddress.LastAddress.ColumnNumber)
+ let range = FsRangeAddress (firstAddress, lastAddress)
+ FsRow(range, cellsCollection) |> Some
+
+ member this.GetHeaderRow(cellsCollection) =
+ match this.TryGetHeaderRow(cellsCollection) with
+ | Some hr -> hr
+ | None -> failwith $"""Error. Unable to get header row for table "{this.Name}" as `ShowHeaderRow` is set to `false`."""
+
+ ///
+ /// Returns the FsColumns from the FsTable.
+ ///
+ /// The FsCellsCollection associated with this FsTable.
+ member this.GetColumns(cellsCollection : FsCellsCollection) =
+ seq {
+ for i = this.RangeAddress.FirstAddress.ColumnNumber to this.RangeAddress.LastAddress.ColumnNumber do
+ let firstAddress = FsAddress(this.RangeAddress.FirstAddress.RowNumber, i)
+ let lastAddress = FsAddress(this.RangeAddress.LastAddress.RowNumber, i)
+ let range = FsRangeAddress (firstAddress, lastAddress)
+ FsColumn(range, cellsCollection)
+ }
+
+ ///
+ /// Returns the FsRows from the FsTable.
+ ///
+ /// The FsCellsCollection associated with this FsTable.
+ member this.GetRows(cellsCollection : FsCellsCollection) =
+ seq {
+ for i = this.RangeAddress.FirstAddress.RowNumber to this.RangeAddress.LastAddress.RowNumber do
+ let firstAddress = FsAddress(i, this.RangeAddress.FirstAddress.ColumnNumber)
+ let lastAddress = FsAddress(i, this.RangeAddress.LastAddress.ColumnNumber)
+ let range = FsRangeAddress (firstAddress, lastAddress)
+ FsRow(range, cellsCollection)
+ }
+
+ ///
+ /// Updates the FsRangeAddress of the FsTable according to the FsTableFields associated.
+ ///
+ member this.RescanRange() =
+ let rangeAddress =
+ _fieldNames.Values
+ |> Seq.map (fun v -> v.Column.RangeAddress)
+ |> Seq.reduce (fun r1 r2 -> r1.Union(r2))
+ base.RangeAddress <- rangeAddress
+
+ ///
+ /// Updates the FsRangeAddress of a given FsTable according to the FsTableFields associated.
+ ///
+ static member rescanRange (table : FsTable) =
+ table.RescanRange()
+ table
+
+ ///
+ /// Returns a unique name consisting of the original name and an initial offset that is raised
+ /// if the original name with that offset is already present.
+ ///
+ /// Header name that was tried to be used.
+ /// First number that together with the originalName, leads to a unique column header.
+ /// If true, the initial offset is always applied.
+ member this.GetUniqueName(originalName : string, initialOffset : int32, enforceOffset : bool) =
+ let mutable name = originalName + if enforceOffset then string initialOffset else ""
+ if _uniqueNames.Contains(name) then
+
+ let mutable i = initialOffset
+ name <- originalName + string i
+ while _uniqueNames.Contains(name) do
+
+ i <- i + 1
+ name <- originalName + string i
+
+ _uniqueNames.Add name |> ignore
+ name
+
+ ///
+ /// Returns a unique name consisting of the original name and an initial offset that is raised
+ /// if the original name with that offset is already present.
+ ///
+ /// Header name that was tried to be used.
+ /// First number that together with the originalName, leads to a unique column header.
+ /// If true, the initial offset is always applied.
+ /// The FsTable on which this function is called.
+ static member getUniqueNames originalName initialOffset enforceOffset (table : FsTable) =
+ table.GetUniqueName(originalName, initialOffset, enforceOffset)
+
+ ///
+ /// Creates and adds FsTableFields from a sequence of field names to the FsTable.
+ ///
+ member this.InitFields(fieldNames : seq) =
+ // _fieldNames = new Dictionary(); // let's _not_ do it this way.
+ //let rangeCols = FsRangeAddress.toRangeColumns base.RangeAddress
+ fieldNames
+ |> Seq.iteri (
+ fun i fn ->
+ let tableField = FsTableField(fn, i, FsRangeColumn.fromIndex i)
+ _fieldNames.Add(fn, tableField)
+ )
+
+ ///
+ /// Creates and adds FsTableFields from a sequence of field names to a given FsTable.
+ ///
+ static member initFields (fieldNames : seq) (table : FsTable) =
+ table.InitFields fieldNames
+ table
+
+ ///
+ /// Adds a sequence of FsTableFields to the FsTable.
+ ///
+ member this.AddFields(tableFields : seq) =
+ tableFields
+ |> Seq.iter (
+ fun tf -> _fieldNames.Add(tf.Name, tf)
+ )
+
+ ///
+ /// Adds a sequence of FsTableFields to a given FsTable.
+ ///
+ static member addFields (tableFields : seq) (table : FsTable) =
+ table.AddFields tableFields
+ table
+
+ ///
+ /// Returns the FsTableField with given name. If an FsTableField does not exist under this name in the FsTable, adds it.
+ ///
+ member this.Field(name : string, cellsCollection : FsCellsCollection) =
+ match Dictionary.tryGet name _fieldNames with
+ | Some field ->
+ field
+ | None ->
+ let maxIndex =
+ _fieldNames.Values
+ |> Seq.map (fun v -> v.Index)
+ |> fun s ->
+ if Seq.length s = 0 then 0 else Seq.max s
+ let range =
+ let offset = _fieldNames.Count
+ let firstAddress = FsAddress(this.RangeAddress.FirstAddress.RowNumber,this.RangeAddress.FirstAddress.ColumnNumber + offset)
+ let lastAddress = FsAddress(this.RangeAddress.LastAddress.RowNumber,this.RangeAddress.FirstAddress.ColumnNumber + offset)
+ FsRangeAddress(firstAddress,lastAddress)
+ let column = FsRangeColumn(range)
+ let newField = FsTableField(name,maxIndex + 1,column,null,null)
+ if this.ShowHeaderRow then
+ newField.HeaderCell(cellsCollection,true).SetValueAs name |> ignore
+ _fieldNames.Add(name,newField)
+ this.RescanRange()
+ newField
+
+ ///
+ /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of this
+ /// FsTable) and returns the respective FsTableField.
+ ///
+ /// if the header row has no field with the given name.
+ member this.GetField(name : string, cellsCollection : FsCellsCollection) =
+ let name = name.Replace("\r\n", "\n")
+ try this.GetFieldNames(cellsCollection).Item name
+ with _ -> failwith <| "The header row doesn't contain field name '" + name + "'."
+
+ ///
+ /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of this
+ /// FsTable) and returns the respective FsTableField.
+ ///
+ /// if the header row has no field with the given name.
+ static member getField (name : string) (cellsCollection : FsCellsCollection) (table : FsTable) =
+ table.GetField(name, cellsCollection)
+
+ ///
+ /// Takes the index of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of
+ /// this FsTable) and returns the respective FsTableField.
+ ///
+ /// if the FsTable has no FsTableField with the given index.
+ member this.GetFieldAt(index, cellsCollection) =
+ try
+ this.GetFieldNames(cellsCollection).Values
+ |> Seq.find (fun ftf -> ftf.Index = index)
+ with _ -> failwith $"FsTableField with index {index} does not exist in the FsTable."
+
+ ///
+ /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of
+ /// this FsTable) and returns the index of the respective FsTableField.
+ ///
+ /// if the header row has no field with the given name.
+ member this.GetFieldIndex(name : string, cellsCollection) =
+ this.GetField(name, cellsCollection).Index
+
+ ///
+ /// Renames a fieldname of the FsTable if it exists. Else fails.
+ ///
+ /// if the FsTableField does not exist in the FsTable.
+ member this.RenameField(oldName : string, newName : string) =
+ match Dictionary.tryGet oldName _fieldNames with
+ | Some field ->
+ _fieldNames.Remove(oldName) |> ignore
+ _fieldNames.Add(newName, field)
+ | None ->
+ raise (System.ArgumentException("The FsTabelField does not exist in this FsTable", "oldName"))
+
+ ///
+ /// Renames a fieldname of the FsTable if it exists. Else fails.
+ ///
+ /// if the FsTableField does not exist in the FsTable.
+ static member renameField oldName newName (table : FsTable) =
+ table.RenameField(oldName, newName)
+ table
+
+ ///
+ /// Returns the header cell from a given FsCellsCollection with the given colum index if the cell exists. Else returns None.
+ ///
+ member this.TryGetHeaderCellOfColumnAt(cellsCollection : FsCellsCollection, colIndex : int) =
+ let fstRowIndex = this.RangeAddress.FirstAddress.RowNumber
+ cellsCollection.GetCellsInColumn colIndex
+ |> Seq.tryFind (fun c -> c.RowNumber = fstRowIndex)
+
+ ///
+ /// Returns the header cell from a given FsCellsCollection with the given column index in a given FsTable if the cell exists. Else
+ /// returns None.
+ ///
+ static member tryGetHeaderCellOfColumnIndexAt cellsCollection (colIndex : int) (table : FsTable) =
+ table.TryGetHeaderCellOfColumnAt(cellsCollection, colIndex)
+
+ ///
+ /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection if the cell exists. Else returns None.
+ ///
+ member this.TryGetHeaderCellOfColumn(cellsCollection : FsCellsCollection, column : FsRangeColumn) =
+ this.TryGetHeaderCellOfColumnAt(cellsCollection, column.Index)
+
+ ///
+ /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection in a given FsTable if the cell exists.
+ /// Else returns None.
+ ///
+ static member tryGetHeaderCellOfColumn cellsCollection (column : FsRangeColumn) (table : FsTable) =
+ table.TryGetHeaderCellOfColumn(cellsCollection, column)
+
+ ///
+ /// Returns the header cell from a given FsCellsCollection with the given colum index.
+ ///
+ /// if the FsCell cannot be found.
+ member this.GetHeaderCellOfColumnAt(cellsCollection, colIndex : int) =
+ this.TryGetHeaderCellOfColumnAt(cellsCollection, colIndex).Value
+
+ ///
+ /// Returns the header cell from a given FsCellsCollection with the given colum index in a given FsTable.
+ ///
+ /// if the FsCell cannot be found.
+ static member getHeaderCellOfColumnIndexAt cellsCollection (colIndex : int) (table : FsTable) =
+ table.GetHeaderCellOfColumnAt(cellsCollection, colIndex)
+
+ ///
+ /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection.
+ ///
+ /// if the FsCell cannot be found.
+ member this.GetHeaderCellOfColumn(cellsCollection : FsCellsCollection, column : FsRangeColumn) =
+ this.TryGetHeaderCellOfColumn(cellsCollection, column).Value
+
+ ///
+ /// Returns the header cell of a given FsRangeColumn from a given FsCellsCollection in a given FsTable.
+ ///
+ /// if the FsCell cannot be found.
+ static member getHeaderCellOfColumn cellsCollection (column : FsRangeColumn) (table : FsTable) =
+ table.GetHeaderCellOfColumn(cellsCollection, column)
+
+ ///
+ /// Returns the header cell of a given FsTableField from a given FsCellsCollection.
+ ///
+ member this.GetHeaderCellOfTableField(cellsCollection, tableField : FsTableField) =
+ tableField.HeaderCell(cellsCollection, this.ShowHeaderRow)
+
+ ///
+ /// Returns the header cell of a given FsTableField from a given FsCellsCollection in a given FsTable.
+ ///
+ static member getHeaderCellOfTableField cellsCollection (tableField : FsTableField) (table : FsTable) =
+ table.GetHeaderCellOfTableField(cellsCollection, tableField)
+
+ ///
+ /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection if the cell exists.
+ /// Else returns None.
+ ///
+ member this.TryGetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex : int) =
+ _fieldNames.Values
+ |> Seq.tryPick (
+ fun tf ->
+ if tf.Index = tableFieldIndex then
+ Some (tf.HeaderCell(cellsCollection, this.ShowHeaderRow))
+ else None
+ )
+
+ ///
+ /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection if the cell exists
+ /// in a given FsTable. Else returns None.
+ ///
+ static member tryGetHeaderCellOfTableFieldIndexAt cellsCollection (tableFieldIndex : int) (table : FsTable) =
+ table.TryGetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex)
+
+ ///
+ /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection.
+ ///
+ /// if the FsCell cannot be found.
+ member this.GetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex : int) =
+ this.TryGetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex).Value
+
+ ///
+ /// Returns the header cell from an FsTableField with the given index using a given FsCellsCollection in a given FsTable.
+ ///
+ /// if the FsCell cannot be found.
+ static member getHeaderCellOfTableFieldIndexAt cellsCollection (tableFieldIndex : int) (table : FsTable) =
+ table.GetHeaderCellOfTableFieldAt(cellsCollection, tableFieldIndex)
+
+ ///
+ /// Returns the header cell from an FsTableField with the given name using an FsCellsCollection in the FsTable if the cell exists.
+ /// Else returns None.
+ ///
+ member this.TryGetHeaderCellByFieldName(cellsCollection, fieldName : string) =
+ match Dictionary.tryGet fieldName _fieldNames with
+ | Some tf -> Some (tf.HeaderCell(cellsCollection, this.ShowHeaderRow))
+ | None -> None
+
+ ///
+ /// Returns the header cell from an FsTableField with the given name using an FsCellsCollection in a given FsTable if the cell exists.
+ /// Else returns None.
+ ///
+ static member tryGetHeaderCellByFieldName cellsCollection (fieldName : string) (table : FsTable) =
+ table.TryGetHeaderCellByFieldName(cellsCollection, fieldName)
+
+ ///
+ /// Returns the data cells from a given FsCellsCollection with the given colum index.
+ ///
+ /// Column index must fit the FsCellsCollection, not the FsTable!
+ member this.GetDataCellsOfColumnAt(cellsCollection : FsCellsCollection, colIndex) =
+ let fstRowIndex = this.RangeAddress.FirstAddress.RowNumber
+ let lstRowIndex = this.RangeAddress.LastAddress.RowNumber
+ [fstRowIndex + 1 .. lstRowIndex]
+ |> Seq.choose (
+ fun ri -> cellsCollection.TryGetCell(ri, colIndex)
+ )
+
+ ///
+ /// Returns the data cells from a given FsCellsCollection with the given colum index in a given FsTable.
+ ///
+ /// Column index must fit the FsCellsCollection, not the FsTable!
+ static member getDataCellsOfColumnIndexAt cellsCollection (colIndex : int) (table : FsTable) =
+ table.GetDataCellsOfColumnAt(cellsCollection, colIndex)
+
+ // TO DO: add equivalents of the other methods regarding header cell for data cells.
+
+ ///
+ /// Creates a deep copy of this FsTable.
+ ///
+ member this.Copy() =
+ let ra = this.RangeAddress.Copy()
+ let nam = this.Name
+ let shr = this.ShowHeaderRow
+ FsTable(nam, ra, false, shr)
+
+ ///
+ /// Returns a deep copy of a given FsTable.
+ ///
+ static member copy (table : FsTable) =
+ table.Copy()
+
+
+ /// Updates the TableFields according to the range of the table and the underlying cellcollection.
+ ///
+ /// For this, maps over the range of the table and sets the header of the table fields to the value of the cell. If no cell value is set, the header value and the underlying cell value are set to a default value.
+ member this.RescanFieldNames(cellsCollection : FsCellsCollection) =
+ if this.ShowHeaderRow then
+ let oldFieldNames = _fieldNames
+ _fieldNames <- new Dictionary()
+ let headersRow = this.GetHeaderRow(cellsCollection);
+ let mutable cellPos = 0
+ for cell in headersRow do
+ let mutable name = cell.ValueAsString() //GetString();
+ match Dictionary.tryGet name oldFieldNames with
+ | Some tableField ->
+ tableField.Index <- cellPos
+ _fieldNames.Add(name,tableField)
+ cellPos <- cellPos + 1
+ | None ->
+
+ // Be careful here. Fields names may actually be whitespace, but not empty
+ if (name = null) <> (name = "") then // TO DO: ask: shouldn't this be XOR?
+
+ name <- this.GetUniqueName("Column", cellPos + 1, true)
+ cell.SetValueAs(name) |> ignore
+ cell.DataType <- DataType.String
+
+ if (_fieldNames.ContainsKey(name)) then
+ raise (System.ArgumentException("The header row contains more than one field name '" + name + "'."))
+
+ _fieldNames.Add(name, new FsTableField(name, cellPos))
+ cellPos <- cellPos + 1
+ else
+
+ let colCount = base.ColumnCount();
+ for i = 1 to colCount do
+
+ if _fieldNames.Values |> Seq.exists (fun v -> v.Index = i - 1) |> not then
+
+ let name = "Column" + string i;
+
_fieldNames.Add(name, new FsTableField(name, i - 1));
\ No newline at end of file
diff --git a/src/FsSpreadsheet/Tables/FsTableField.fs b/src/FsSpreadsheet/Tables/FsTableField.fs
index 04622e73..1e9143da 100644
--- a/src/FsSpreadsheet/Tables/FsTableField.fs
+++ b/src/FsSpreadsheet/Tables/FsTableField.fs
@@ -1,37 +1,19 @@
namespace FsSpreadsheet
+open Fable.Core
+
///
/// Creates an FsTableFiled with given name, index, FsRangeColumn, totalRowLabel, and the totalsRowFunction.
///
-[]
-type FsTableField (name : string, index : int, column : FsRangeColumn, totalsRowLabel, totalsRowFunction) =
+[][]
+type FsTableField (name : string, ?index : int, ?column : FsRangeColumn, ?totalsRowLabel, ?totalsRowFunction) =
- let mutable _totalsRowsFunction = totalsRowFunction
- let mutable _totalsRowLabel = totalsRowLabel
- let mutable _column = column
- let mutable _index = index
+ let mutable _totalsRowsFunction = totalsRowFunction |> Option.defaultValue null
+ let mutable _totalsRowLabel = totalsRowLabel |> Option.defaultValue null
+ let mutable _column = column |> Option.defaultValue null
+ let mutable _index = index |> Option.defaultValue 0
let mutable _name = name
- ///
- /// Creates an empty FsTableField.
- ///
- new() = FsTableField("", 0, null, null, null)
-
- ///
- /// Creates an FsTableField with the given name.
- ///
- new(name : string) = FsTableField(name, 0, null, null, null)
-
- ///
- /// Creates an FsTableField with the given name and index.
- ///
- new(name : string, index : int) = FsTableField(name, index, null, null, null)
-
- ///
- /// Creates an FsTableField with the given name, index, and FsRangeColumn.
- ///
- new(name, index, column) = FsTableField(name, index, column, null, null)
-
///
/// Gets or sets the FsRangeColumn of this FsTableField.
///
diff --git a/src/FsSpreadsheet/Tables/FsTableRow.fs b/src/FsSpreadsheet/Tables/FsTableRow.fs
index 24ceb43b..368a92e8 100644
--- a/src/FsSpreadsheet/Tables/FsTableRow.fs
+++ b/src/FsSpreadsheet/Tables/FsTableRow.fs
@@ -1,6 +1,8 @@
namespace FsSpreadsheet
-[]
+open Fable.Core
+
+[][]
type FsTableRow (rangeAddress : FsRangeAddress) =
inherit FsRangeRow(rangeAddress)
\ No newline at end of file
diff --git a/tests/FsSpreadsheet.Js.Tests/DefaultIO.Tests.fs b/tests/FsSpreadsheet.Js.Tests/DefaultIO.Tests.fs
index ff2d412f..e2ec4daa 100644
--- a/tests/FsSpreadsheet.Js.Tests/DefaultIO.Tests.fs
+++ b/tests/FsSpreadsheet.Js.Tests/DefaultIO.Tests.fs
@@ -23,7 +23,7 @@ let private tests_Read = testList "Read" [
let! wb = readFromTestFile DefaultTestObject.TestFiles.FableExceljs |> Async.AwaitPromise
Expect.isDefaultTestObject wb
}
- ptestCaseAsync "ClosedXML" <| async {
+ testCaseAsync "ClosedXML" <| async {
let! wb = readFromTestFile DefaultTestObject.TestFiles.ClosedXML |> Async.AwaitPromise
Expect.isDefaultTestObject wb
}
diff --git a/tests/FsSpreadsheet.Js.Tests/Workbook.Tests.fs b/tests/FsSpreadsheet.Js.Tests/Workbook.Tests.fs
index 6cf36b61..8ea2f906 100644
--- a/tests/FsSpreadsheet.Js.Tests/Workbook.Tests.fs
+++ b/tests/FsSpreadsheet.Js.Tests/Workbook.Tests.fs
@@ -72,7 +72,7 @@ let private tests_toFsWorkbook = testList "toFsWorkbook" [
Expect.equal (fsTable.RangeAddress.Range) ("B1:C1") "RangeAddress"
let getCellValue (address: string) =
let ws = fswb.GetWorksheetAt 1
- let range = FsAddress(address)
+ let range = FsAddress.fromString(address)
ws.GetCellAt(range.RowNumber, range.ColumnNumber).Value
//fsTable.Cell(FsAddress(address), (fswb.GetWorksheetAt 1).CellCollection).Value //bugged in FsSpreadsheet v3.1.1
Expect.equal (getCellValue "B1") "Column 1 nice" "B1"
@@ -112,7 +112,7 @@ let private tests_toFsWorkbook = testList "toFsWorkbook" [
let fswb = JsWorkbook.readToFsWorkbook jswb
let getCellValue (address: string) =
let ws = fswb.GetWorksheetAt 1
- let range = FsAddress(address)
+ let range = FsAddress.fromString(address)
ws.GetCellAt(range.RowNumber, range.ColumnNumber)
//fsTable.Cell(FsAddress(address), (fswb.GetWorksheetAt 1).CellCollection).Value //bugged in FsSpreadsheet v3.1.1
let inline expectCellValue (address: string) (getas: FsCell -> 'A) (expectedValue: 'A) =
@@ -168,9 +168,9 @@ let tests_toJsWorkbook = testList "toJsWorkbook" [
testCase "table, no body" <| fun _ ->
let fswb = new FsWorkbook()
let fsws = fswb.InitWorksheet("My Awesome Worksheet")
- let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress("B1")))
- let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress("C1")))
- let t = FsTable("My_New_Table", FsRangeAddress("B1:C1"))
+ let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress.fromString("B1")))
+ let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress.fromString("C1")))
+ let t = FsTable("My_New_Table", FsRangeAddress.fromString("B1:C1"))
let _ = fsws.AddTable(t)
Expect.passWithMsg "Create jswb"
let jswb = JsWorkbook.writeFromFsWorkbook fswb
@@ -188,16 +188,16 @@ let tests_toJsWorkbook = testList "toJsWorkbook" [
testCase "table, with body" <| fun _ ->
let fswb = new FsWorkbook()
let fsws = fswb.InitWorksheet("My Awesome Worksheet")
- let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress("B1")))
- let _ = fsws.AddCell(FsCell(2,address=FsAddress("B2")))
- let _ = fsws.AddCell(FsCell(20,address=FsAddress("B3")))
- let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress("C1")))
- let _ = fsws.AddCell(FsCell("row2",address=FsAddress("C2")))
- let _ = fsws.AddCell(FsCell("row20",address=FsAddress("C3")))
- let _ = fsws.AddCell(FsCell("My Column 3",address=FsAddress("D1")))
- let _ = fsws.AddCell(FsCell(true,address=FsAddress("D2")))
- let _ = fsws.AddCell(FsCell(false,address=FsAddress("D3")))
- let t = FsTable("My_New_Table", FsRangeAddress("B1:D3"))
+ let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress.fromString("B1")))
+ let _ = fsws.AddCell(FsCell(2,address=FsAddress.fromString("B2")))
+ let _ = fsws.AddCell(FsCell(20,address=FsAddress.fromString("B3")))
+ let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress.fromString("C1")))
+ let _ = fsws.AddCell(FsCell("row2",address=FsAddress.fromString("C2")))
+ let _ = fsws.AddCell(FsCell("row20",address=FsAddress.fromString("C3")))
+ let _ = fsws.AddCell(FsCell("My Column 3",address=FsAddress.fromString("D1")))
+ let _ = fsws.AddCell(FsCell(true,address=FsAddress.fromString("D2")))
+ let _ = fsws.AddCell(FsCell(false,address=FsAddress.fromString("D3")))
+ let t = FsTable("My_New_Table", FsRangeAddress.fromString("B1:D3"))
let _ = fsws.AddTable(t)
Expect.passWithMsg "Create jswb"
let jswb = JsWorkbook.writeFromFsWorkbook fswb
@@ -216,16 +216,16 @@ let tests_toJsWorkbook = testList "toJsWorkbook" [
testCase "table, with body, check cells" <| fun _ ->
let fswb = new FsWorkbook()
let fsws = fswb.InitWorksheet("My Awesome Worksheet")
- let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress("B1")))
- let _ = fsws.AddCell(FsCell(2,DataType.Number,address=FsAddress("B2")))
- let _ = fsws.AddCell(FsCell(20,DataType.Number,address=FsAddress("B3")))
- let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress("C1")))
- let _ = fsws.AddCell(FsCell("row2",address=FsAddress("C2")))
- let _ = fsws.AddCell(FsCell("row20",address=FsAddress("C3")))
- let _ = fsws.AddCell(FsCell("My Column 3",address=FsAddress("D1")))
- let _ = fsws.AddCell(FsCell(true, DataType.Boolean, address=FsAddress("D2")))
- let _ = fsws.AddCell(FsCell(false, DataType.Boolean, address=FsAddress("D3")))
- let t = FsTable("My_New_Table", FsRangeAddress("B1:D3"))
+ let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress.fromString("B1")))
+ let _ = fsws.AddCell(FsCell(2,DataType.Number,address=FsAddress.fromString("B2")))
+ let _ = fsws.AddCell(FsCell(20,DataType.Number,address=FsAddress.fromString("B3")))
+ let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress.fromString("C1")))
+ let _ = fsws.AddCell(FsCell("row2",address=FsAddress.fromString("C2")))
+ let _ = fsws.AddCell(FsCell("row20",address=FsAddress.fromString("C3")))
+ let _ = fsws.AddCell(FsCell("My Column 3",address=FsAddress.fromString("D1")))
+ let _ = fsws.AddCell(FsCell(true, DataType.Boolean, address=FsAddress.fromString("D2")))
+ let _ = fsws.AddCell(FsCell(false, DataType.Boolean, address=FsAddress.fromString("D3")))
+ let t = FsTable("My_New_Table", FsRangeAddress.fromString("B1:D3"))
let _ = fsws.AddTable(t)
fsws.RescanRows()
Expect.passWithMsg "Create jswb"
@@ -244,16 +244,16 @@ let tests_toJsWorkbook = testList "toJsWorkbook" [
testCase "table ColumnCount()" <| fun _ ->
let fswb = new FsWorkbook()
let fsws = fswb.InitWorksheet("My Awesome Worksheet")
- let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress("B1")))
- let _ = fsws.AddCell(FsCell(2,DataType.Number,address=FsAddress("B2")))
- let _ = fsws.AddCell(FsCell(20,DataType.Number,address=FsAddress("B3")))
- let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress("C1")))
- let _ = fsws.AddCell(FsCell("row2",address=FsAddress("C2")))
- let _ = fsws.AddCell(FsCell("row20",address=FsAddress("C3")))
- let _ = fsws.AddCell(FsCell("My Column 3",address=FsAddress("D1")))
- let _ = fsws.AddCell(FsCell(true, DataType.Boolean, address=FsAddress("D2")))
- let _ = fsws.AddCell(FsCell(false, DataType.Boolean, address=FsAddress("D3")))
- let t = FsTable("My_New_Table", FsRangeAddress("B1:D3"))
+ let _ = fsws.AddCell(FsCell("My Column 1",address=FsAddress.fromString("B1")))
+ let _ = fsws.AddCell(FsCell(2,DataType.Number,address=FsAddress.fromString("B2")))
+ let _ = fsws.AddCell(FsCell(20,DataType.Number,address=FsAddress.fromString("B3")))
+ let _ = fsws.AddCell(FsCell("My Column 2",address=FsAddress.fromString("C1")))
+ let _ = fsws.AddCell(FsCell("row2",address=FsAddress.fromString("C2")))
+ let _ = fsws.AddCell(FsCell("row20",address=FsAddress.fromString("C3")))
+ let _ = fsws.AddCell(FsCell("My Column 3",address=FsAddress.fromString("D1")))
+ let _ = fsws.AddCell(FsCell(true, DataType.Boolean, address=FsAddress.fromString("D2")))
+ let _ = fsws.AddCell(FsCell(false, DataType.Boolean, address=FsAddress.fromString("D3")))
+ let t = FsTable("My_New_Table", FsRangeAddress.fromString("B1:D3"))
let _ = fsws.AddTable(t)
fsws.RescanRows()
let table = fsws.Tables.[0]
@@ -270,7 +270,7 @@ let tests_toJsWorkbook = testList "toJsWorkbook" [
fsws.Row(1).[4].SetValueAs "My Column 2"
fsws.Row(2).[4].SetValueAs true
fsws.Row(3).[4].SetValueAs false
- let t = FsTable("My New Table", FsRangeAddress("B1:D3"))
+ let t = FsTable("My New Table", FsRangeAddress.fromString("B1:D3"))
let _ = fsws.AddTable(t)
fsws.RescanRows()
let table = fsws.Tables.[0]
diff --git a/tests/FsSpreadsheet.Net.Tests/DefaultIO.Tests.fs b/tests/FsSpreadsheet.Net.Tests/DefaultIO.Tests.fs
index 69127753..4208e223 100644
--- a/tests/FsSpreadsheet.Net.Tests/DefaultIO.Tests.fs
+++ b/tests/FsSpreadsheet.Net.Tests/DefaultIO.Tests.fs
@@ -12,8 +12,8 @@ let tests_Read = testList "Read" [
| _ -> FsWorkbook.fromXlsxFile($"{DefaultTestObject.testFolder}/{testFile.asFileName}")
testCase "FsCell equality" <| fun _ ->
- let c1 = FsCell(1, DataType.Number, FsAddress("A2"))
- let c2 = FsCell(1, DataType.Number, FsAddress("A2"))
+ let c1 = FsCell(1, DataType.Number, FsAddress.fromString("A2"))
+ let c2 = FsCell(1, DataType.Number, FsAddress.fromString("A2"))
let isStructEqual = c1.StructurallyEquals(c2)
Expect.isTrue isStructEqual ""
testCase "Excel" <| fun _ ->
diff --git a/tests/FsSpreadsheet.Net.Tests/OpenXml/FsExtensions.fs b/tests/FsSpreadsheet.Net.Tests/OpenXml/FsExtensions.fs
index 94f7bfa3..9616c787 100644
--- a/tests/FsSpreadsheet.Net.Tests/OpenXml/FsExtensions.fs
+++ b/tests/FsSpreadsheet.Net.Tests/OpenXml/FsExtensions.fs
@@ -36,7 +36,7 @@ dummyFsCellsCollection3.Add dummyFsCells[2] |> ignore
let dummyFsCellsCollection4 = FsCellsCollection()
dummyFsCellsCollection4.Add dummyFsCells[3] |> ignore
dummyFsCellsCollection4.Add dummyFsCells[4] |> ignore
-let dummyFsTable = FsTable("Table2", FsRangeAddress("A1:D13"))
+let dummyFsTable = FsTable("Table2", FsRangeAddress.fromString("A1:D13"))
let dummyFsWorksheet1 = FsWorksheet("StringSheet", ResizeArray(), ResizeArray(), dummyFsCellsCollection1)
let dummyFsWorksheet2 = FsWorksheet("NumericSheet", ResizeArray(), ResizeArray(), dummyFsCellsCollection2)
let dummyFsWorksheet3 = FsWorksheet("TableSheet", ResizeArray(), ResizeArray([dummyFsTable]), dummyFsCellsCollection3)
diff --git a/tests/FsSpreadsheet.Net.Tests/Table.fs b/tests/FsSpreadsheet.Net.Tests/Table.fs
index f6b084f7..1074dd90 100644
--- a/tests/FsSpreadsheet.Net.Tests/Table.fs
+++ b/tests/FsSpreadsheet.Net.Tests/Table.fs
@@ -22,9 +22,9 @@ let transformTable =
let columnNames = [|"My Column 1";"My Column 2"|]
- ws.AddCell(FsCell(columnNames.[0],address=FsAddress("B1"))) |> ignore
- ws.AddCell(FsCell(columnNames.[1],address=FsAddress("C1"))) |> ignore
- let t = FsTable("My_New_Table", FsRangeAddress("B1:C2"))
+ ws.AddCell(FsCell(columnNames.[0],address=FsAddress.fromString("B1"))) |> ignore
+ ws.AddCell(FsCell(columnNames.[1],address=FsAddress.fromString("C1"))) |> ignore
+ let t = FsTable("My_New_Table", FsRangeAddress.fromString("B1:C2"))
ws.AddTable(t) |> ignore
diff --git a/tests/FsSpreadsheet.Net.Tests/ZipArchiveReader.fs b/tests/FsSpreadsheet.Net.Tests/ZipArchiveReader.fs
index 03a10240..2becb9f1 100644
--- a/tests/FsSpreadsheet.Net.Tests/ZipArchiveReader.fs
+++ b/tests/FsSpreadsheet.Net.Tests/ZipArchiveReader.fs
@@ -16,8 +16,8 @@ let tests_Read = testList "Read" [
FsWorkbook.fromXlsxFile(p)
testCase "FsCell equality" <| fun _ ->
- let c1 = FsCell(1, DataType.Number, FsAddress("A2"))
- let c2 = FsCell(1, DataType.Number, FsAddress("A2"))
+ let c1 = FsCell(1, DataType.Number, FsAddress.fromString("A2"))
+ let c2 = FsCell(1, DataType.Number, FsAddress.fromString("A2"))
let isStructEqual = c1.StructurallyEquals(c2)
Expect.isTrue isStructEqual ""
testCase "Excel" <| fun _ ->
diff --git a/tests/FsSpreadsheet.Py.Tests/Table.fs b/tests/FsSpreadsheet.Py.Tests/Table.fs
index 7e6bb9e8..4eaee0e0 100644
--- a/tests/FsSpreadsheet.Py.Tests/Table.fs
+++ b/tests/FsSpreadsheet.Py.Tests/Table.fs
@@ -11,7 +11,7 @@ open Fable.Core
let fromFsTable = testList "fromFsTable" [
testCase "Table" <| fun _ ->
let rangeString = "A1:E5"
- let fsTable = FsTable("MyTable", FsRangeAddress(rangeString))
+ let fsTable = FsTable("MyTable", FsRangeAddress.fromString(rangeString))
let pyTable = PyTable.fromFsTable fsTable
let expected = Table.create("MyTable", rangeString)
@@ -25,7 +25,7 @@ let toFsTable = testList "toFsTable" [
testCase "Table" <| fun _ ->
let pyTable = Table.create("MyTable", "A1:E5")
let fsTable = PyTable.toFsTable pyTable
- let expected = FsTable("MyTable", FsRangeAddress("A1:E5"))
+ let expected = FsTable("MyTable", FsRangeAddress.fromString("A1:E5"))
Expect.equal fsTable.Name expected.Name ""
Expect.equal fsTable.RangeAddress.Range expected.RangeAddress.Range ""
diff --git a/tests/FsSpreadsheet.Py.Tests/Worksheet.Tests.fs b/tests/FsSpreadsheet.Py.Tests/Worksheet.Tests.fs
index 5e1c5cd3..81125940 100644
--- a/tests/FsSpreadsheet.Py.Tests/Worksheet.Tests.fs
+++ b/tests/FsSpreadsheet.Py.Tests/Worksheet.Tests.fs
@@ -20,7 +20,7 @@ let fromFsWorksheet = testList "fromFsWorksheet" [
testCase "Simple" <| fun _ ->
let wb = Workbook.create()
let fsWS = FsWorksheet(wsName)
- let cell = FsCell("Hello", address = FsAddress("A1"))
+ let cell = FsCell("Hello", address = FsAddress.fromString("A1"))
fsWS.AddCell(cell) |> ignore
let pyWS = PyWorksheet.fromFsWorksheet wb fsWS
diff --git a/tests/FsSpreadsheet.Tests/FsAddressTests.fs b/tests/FsSpreadsheet.Tests/FsAddressTests.fs
index f91d3931..a48f2140 100644
--- a/tests/FsSpreadsheet.Tests/FsAddressTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsAddressTests.fs
@@ -4,11 +4,11 @@ open Fable.Pyxpecto
open FsSpreadsheet
-let testAddress1 = FsAddress("B5")
+let testAddress1 = FsAddress.fromString("B5")
let testAddress2 = FsAddress(3, 2)
let testAddress3 = FsAddress(4, 8, true, true)
-let testAddress4 = FsAddress(2, "D", true, true)
-let testAddress5 = FsAddress("Z69")
+let testAddress4 = FsAddress.fromString("D2", true, true)
+let testAddress5 = FsAddress.fromString("Z69")
let testAddress6 = FsAddress(5, 2)
let main =
@@ -82,13 +82,29 @@ let main =
]
]
testList "Compare" [
- testList "address" [
- testCase "testAddress1 vs testAddress2" <| fun _ ->
- let result = testAddress1.Compare testAddress2
- Expect.isFalse result "Addresses do not differ"
- testCase "testAddress1 vs testAddress6" <| fun _ ->
- let result = testAddress1.Compare testAddress6
- Expect.isTrue result "Addresses differ"
- ]
+ testCase "testAddress1 vs testAddress2" <| fun _ ->
+ let result = testAddress1.Compare testAddress2
+ Expect.isFalse result "Addresses do not differ"
+ testCase "testAddress1 vs testAddress6" <| fun _ ->
+ let result = testAddress1.Compare testAddress6
+ Expect.isTrue result "Addresses differ"
+ ]
+ testList "Equals" [
+ testCase "testAddress1 vs testAddress2" <| fun _ ->
+ let result = testAddress1.Equals testAddress2
+ Expect.isFalse result "Addresses do not differ"
+ testCase "testAddress1 vs testAddress6" <| fun _ ->
+ let result = testAddress1.Equals testAddress6
+ Expect.isTrue result "Addresses differ"
+ ]
+ testList "GetHashCode" [
+ testCase "testAddress1 vs testAddress2" <| fun _ ->
+ let hash1 = testAddress1.GetHashCode()
+ let hash2 = testAddress2.GetHashCode()
+ Expect.isFalse (hash1 = hash2) "Hash codes do not differ"
+ testCase "testAddress1 vs testAddress6" <| fun _ ->
+ let hash1 = testAddress1.GetHashCode()
+ let hash2 = testAddress6.GetHashCode()
+ Expect.isTrue (hash1 = hash2) "Hash codes differ"
]
]
\ No newline at end of file
diff --git a/tests/FsSpreadsheet.Tests/FsColumnTests.fs b/tests/FsSpreadsheet.Tests/FsColumnTests.fs
index 1849c89b..9ce9d21a 100644
--- a/tests/FsSpreadsheet.Tests/FsColumnTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsColumnTests.fs
@@ -19,12 +19,12 @@ let main =
]
testList "ColumnFromRange" [
let dummyWorkSheet = getDummyWorkSheet()
- let range = FsRangeAddress("B1:B3")
+ let range = FsRangeAddress.fromString("B1:B3")
let column = FsColumn(range, dummyWorkSheet.CellCollection)
testCase "CorrectIndex" <| fun _ ->
Expect.equal column.Index 2 "Column index is not correct"
testCase "CorrectRange" <| fun _ ->
- let expectedRange = FsRangeAddress("B1:B3")
+ let expectedRange = FsRangeAddress.fromString("B1:B3")
Expect.equal column.RangeAddress.Range expectedRange.Range "Column index is not correct"
testCase "CorrectCellCount" <| fun _ ->
Expect.equal (column.Cells |> Seq.length) 3 "Column length is not correct"
@@ -39,7 +39,7 @@ let main =
testCase "CorrectIndex" <| fun _ ->
Expect.equal column.Index 2 "Column index is not correct"
testCase "CorrectRange" <| fun _ ->
- let expectedRange = FsRangeAddress("B1:B3")
+ let expectedRange = FsRangeAddress.fromString("B1:B3")
Expect.equal column.RangeAddress.Range expectedRange.Range "Column index is not correct"
testCase "CorrectCellCount" <| fun _ ->
Expect.equal (column.Cells |> Seq.length) 3 "Column length is not correct"
@@ -74,12 +74,12 @@ let main =
testList "ToDenseColumn" [
testCase "is correct" (fun _ ->
let cellsCollWithEmpty = FsCellsCollection()
- cellsCollWithEmpty.Add [
+ cellsCollWithEmpty.AddMany [
FsCell.create 1 1 "Kevin"
- FsCell.createEmptyWithAdress(FsAddress("A2"))
+ FsCell.createEmptyWithAdress(FsAddress.fromString("A2"))
FsCell.create 3 1 "Schneider"
]
- let column = FsColumn(FsRangeAddress("A1:A3"), cellsCollWithEmpty)
+ let column = FsColumn(FsRangeAddress.fromString("A1:A3"), cellsCollWithEmpty)
let actual = FsColumn.toDenseColumn column |> Seq.map FsCell.getValueAsString |> Seq.toList
let expected = ["Kevin"; ""; "Schneider"]
Expect.mySequenceEqual actual expected "Column values differ"
@@ -89,7 +89,7 @@ let main =
testCase "can be retrieved" <| fun _ ->
let cellsColl = FsCellsCollection()
cellsColl.Add (FsCell.create 1 1 "Kevin")
- let column = FsColumn(FsRangeAddress("A1:A1"), cellsColl)
+ let column = FsColumn(FsRangeAddress.fromString("A1:A1"), cellsColl)
let firstCell = column.Cells |> Seq.head
Expect.equal (FsCell.getValueAsString firstCell) "Kevin" "Did not retrieve"
]
@@ -97,7 +97,7 @@ let main =
testCase "can be retrieved" <| fun _ ->
let cellsColl = FsCellsCollection()
cellsColl.Add (FsCell.create 1 1 "Kevin")
- let column = FsColumn(FsRangeAddress("A1:A1"), cellsColl)
+ let column = FsColumn(FsRangeAddress.fromString("A1:A1"), cellsColl)
let minRowIndex = column.MinRowIndex
Expect.equal minRowIndex 1 "Incorrect index"
]
@@ -105,7 +105,7 @@ let main =
testCase "can be retrieved" <| fun _ ->
let cellsColl = FsCellsCollection()
cellsColl.Add (FsCell.create 1 1 "Kevin")
- let column = FsColumn(FsRangeAddress("A1:A1"), cellsColl)
+ let column = FsColumn(FsRangeAddress.fromString("A1:A1"), cellsColl)
let maxRowIndex = column.MaxRowIndex
Expect.equal maxRowIndex 1 "Incorrect index"
]
diff --git a/tests/FsSpreadsheet.Tests/FsRowTests.fs b/tests/FsSpreadsheet.Tests/FsRowTests.fs
index 09fffd35..b36ecb44 100644
--- a/tests/FsSpreadsheet.Tests/FsRowTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsRowTests.fs
@@ -43,12 +43,12 @@ let rowOperations =
]
testList "RowFromRange" [
let dummyWorkSheet = getDummyWorkSheet()
- let range = FsRangeAddress("A2:C2")
+ let range = FsRangeAddress.fromString("A2:C2")
let row = FsRow(range, dummyWorkSheet.CellCollection)
testCase "CorrectIndex" <| fun _ ->
Expect.equal row.Index 2 "Row index is not correct"
testCase "CorrectRange" <| fun _ ->
- let expectedRange = FsRangeAddress("A2:C2")
+ let expectedRange = FsRangeAddress.fromString("A2:C2")
Expect.equal row.RangeAddress.Range expectedRange.Range "Row index is not correct"
testCase "CorrectCellCount" <| fun _ ->
Expect.equal (row.Cells |> Seq.length) 3 "Row length is not correct"
@@ -63,7 +63,7 @@ let rowOperations =
testCase "CorrectIndex" <| fun _ ->
Expect.equal row.Index 2 "Row index is not correct"
testCase "CorrectRange" <| fun _ ->
- let expectedRange = FsRangeAddress("A2:C2")
+ let expectedRange = FsRangeAddress.fromString("A2:C2")
Expect.equal row.RangeAddress.Range expectedRange.Range "Row index is not correct"
testCase "CorrectCellCount" <| fun _ ->
Expect.equal (row.Cells |> Seq.length) 3 "Row length is not correct"
@@ -98,12 +98,12 @@ let rowOperations =
testList "ToDenseRow" [
testCase "is correct" (fun _ ->
let cellsCollWithEmpty = FsCellsCollection()
- cellsCollWithEmpty.Add [
+ cellsCollWithEmpty.AddMany [
FsCell.create 1 1 "Kevin"
- FsCell.createEmptyWithAdress(FsAddress("B1"))
+ FsCell.createEmptyWithAdress(FsAddress.fromString("B1"))
FsCell.create 1 3 "Schneider"
]
- let row = FsRow(FsRangeAddress("A1:C1"), cellsCollWithEmpty)
+ let row = FsRow(FsRangeAddress.fromString("A1:C1"), cellsCollWithEmpty)
let actual = FsRow.toDenseRow row |> Seq.map FsCell.getValueAsString |> Seq.toList
let expected = ["Kevin"; ""; "Schneider"]
Expect.mySequenceEqual actual expected "Row values differ"
@@ -113,7 +113,7 @@ let rowOperations =
testCase "can be retrieved" <| fun _ ->
let cellsColl = FsCellsCollection()
cellsColl.Add (FsCell.create 1 1 "Kevin")
- let row = FsRow(FsRangeAddress("A1:A1"), cellsColl)
+ let row = FsRow(FsRangeAddress.fromString("A1:A1"), cellsColl)
let firstCell = row.Cells |> Seq.head
Expect.equal (FsCell.getValueAsString firstCell) "Kevin" "Did not retrieve"
]
@@ -121,7 +121,7 @@ let rowOperations =
testCase "can be retrieved" <| fun _ ->
let cellsColl = FsCellsCollection()
cellsColl.Add (FsCell.create 1 1 "Kevin")
- let row = FsRow(FsRangeAddress("A1:A1"), cellsColl)
+ let row = FsRow(FsRangeAddress.fromString("A1:A1"), cellsColl)
let minColIndex = row.MinColIndex
Expect.equal minColIndex 1 "Incorrect index"
]
@@ -129,7 +129,7 @@ let rowOperations =
testCase "can be retrieved" <| fun _ ->
let cellsColl = FsCellsCollection()
cellsColl.Add (FsCell.create 1 1 "Kevin")
- let row = FsRow(FsRangeAddress("A1:A1"), cellsColl)
+ let row = FsRow(FsRangeAddress.fromString("A1:A1"), cellsColl)
let maxColIndex = row.MaxColIndex
Expect.equal maxColIndex 1 "Incorrect index"
]
diff --git a/tests/FsSpreadsheet.Tests/FsTableFieldTests.fs b/tests/FsSpreadsheet.Tests/FsTableFieldTests.fs
index 70e80f8c..7a3380b4 100644
--- a/tests/FsSpreadsheet.Tests/FsTableFieldTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsTableFieldTests.fs
@@ -3,7 +3,7 @@
open FsSpreadsheet
open Fable.Pyxpecto
-let dummyFsRangeAddress = FsRangeAddress("C1:C3")
+let dummyFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let dummyFsRangeColumn = FsRangeColumn(dummyFsRangeAddress)
let dummyFsTableField = FsTableField("dummyFsTableField", 0, dummyFsRangeColumn, obj, obj)
let dummyFsCells = [
@@ -15,13 +15,13 @@ let dummyFsCells = [
FsCell.createWithDataType DataType.String 3 4 "second data cell in B col"
]
let dummyFsCellsCollection = FsCellsCollection()
-dummyFsCellsCollection.Add dummyFsCells |> ignore
+dummyFsCellsCollection.AddMany dummyFsCells |> ignore
let main =
testList "FsTableField" [
testList "Constructors" [
testList "unit" [
- let testFsTableField = FsTableField()
+ let testFsTableField = FsTableField("")
testCase "Index is 0" <| fun _ ->
Expect.equal testFsTableField.Index 0 "Index is not 0"
testCase "Name is empty" <| fun _ ->
@@ -51,7 +51,7 @@ let main =
// TO DO: add testCases for totalsRowLabel & totalsRowFunction as soon as they are implemented
]
testList "name : string, index : int, column : FsRangeColumn" [
- let testFsRangeAddress = FsRangeAddress("C1:C3")
+ let testFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
let testFsTableField = FsTableField("testName", 3, testFsRangeColumn)
testCase "Index is 3" <| fun _ ->
@@ -73,7 +73,7 @@ let main =
testFsTableField.Index <- 4
Expect.equal testFsTableField.Index 4 "Index is not 4"
testCase "Sets column index correctly" <| fun _ ->
- let testFsRangeAddress = FsRangeAddress("C1:C3")
+ let testFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
let testFsTableField = FsTableField("testName", 3, testFsRangeColumn)
testFsTableField.Index <- 4
@@ -82,10 +82,10 @@ let main =
]
testList "Column" [
testList "Setter" [
- let testFsRangeAddress = FsRangeAddress("C1:C3")
+ let testFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
let testFsTableField = FsTableField("testName", 3, testFsRangeColumn)
- let testFsRangeAddress = FsRangeAddress "B1:B3"
+ let testFsRangeAddress = FsRangeAddress.fromString "B1:B3"
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
testFsTableField.Column <- testFsRangeColumn
testCase "Sets Column correctly, check Index" <| fun _ ->
@@ -97,7 +97,7 @@ let main =
]
testList "Methods" [
testList "HeaderCell" [
- let testFsRangeAddress = FsRangeAddress("C1:C3")
+ let testFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
let testFsTableField = FsTableField("testName", 3, testFsRangeColumn)
let testFsCellsCollection = FsCellsCollection()
@@ -106,13 +106,13 @@ let main =
|> List.map (
fun c -> FsCell.createWithDataType c.DataType c.RowNumber c.ColumnNumber c.Value
)
- testFsCellsCollection.Add testFsCells |> ignore
+ testFsCellsCollection.AddMany testFsCells |> ignore
let headerCell = testFsTableField.HeaderCell(testFsCellsCollection, true)
testCase "Gets correct header cell" <| fun _ ->
Expect.equal headerCell.Value "I am the Header!" "Value is not I am the Header!"
]
testList "SetName" [
- let testFsRangeAddress = FsRangeAddress("C1:C3")
+ let testFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
let testFsTableField = FsTableField("testName", 3, testFsRangeColumn)
let testFsCellsCollection = FsCellsCollection()
@@ -121,7 +121,7 @@ let main =
|> List.map (
fun c -> FsCell.createWithDataType c.DataType c.RowNumber c.ColumnNumber c.Value
)
- testFsCellsCollection.Add testFsCells |> ignore
+ testFsCellsCollection.AddMany testFsCells |> ignore
testCase "Sets fieldname correctly" <| fun _ ->
testFsTableField.SetName("testName2", testFsCellsCollection, true)
Expect.equal testFsTableField.Name "testName2" "Name is not testName2"
@@ -131,7 +131,7 @@ let main =
Expect.equal headerCell.Value "testName2" "Value is not testName2"
]
testList "DataCells" [
- let testFsRangeAddress = FsRangeAddress("C1:C3")
+ let testFsRangeAddress = FsRangeAddress.fromString("C1:C3")
let testFsRangeColumn = FsRangeColumn testFsRangeAddress
let testFsTableField = FsTableField("testName", 3, testFsRangeColumn)
let testFsCellsCollection = FsCellsCollection()
@@ -140,7 +140,7 @@ let main =
|> List.map (
fun c -> FsCell.createWithDataType c.DataType c.RowNumber c.ColumnNumber c.Value
)
- testFsCellsCollection.Add testFsCells |> ignore
+ testFsCellsCollection.AddMany testFsCells |> ignore
testList "showHeaderRow = true" [
testCase "Returns correct data cells" <| fun _ ->
let dataCells = testFsTableField.DataCells(testFsCellsCollection)
diff --git a/tests/FsSpreadsheet.Tests/FsTableTests.fs b/tests/FsSpreadsheet.Tests/FsTableTests.fs
index 242e1583..3b34b375 100644
--- a/tests/FsSpreadsheet.Tests/FsTableTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsTableTests.fs
@@ -46,7 +46,7 @@ let dummyFsRangeColumns =
>> FsRangeColumn
)
let dummyFsCellsCollection = FsCellsCollection()
-dummyFsCellsCollection.Add dummyFsCells |> ignore
+dummyFsCellsCollection.AddMany dummyFsCells |> ignore
let dummyFsCellsCollectionFirstAddress = dummyFsCellsCollection.GetFirstAddress()
let dummyFsCellsCollectionLastAddress = dummyFsCellsCollection.GetLastAddress()
let dummyFsTable = FsTable("dummyFsTable", FsRangeAddress(dummyFsCellsCollectionFirstAddress, dummyFsCellsCollectionLastAddress))
diff --git a/tests/FsSpreadsheet.Tests/FsWorkbookTests.fs b/tests/FsSpreadsheet.Tests/FsWorkbookTests.fs
index 5d42c4c6..5976b963 100644
--- a/tests/FsSpreadsheet.Tests/FsWorkbookTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsWorkbookTests.fs
@@ -9,8 +9,8 @@ let dummyWorksheet1 = FsWorksheet("dummyWorksheet1")
let dummyWorksheet2 = FsWorksheet("dummyWorksheet2")
let dummyWorksheetList = [dummyWorksheet1; dummyWorksheet2]
let dummyTables = [|
- FsTable("dummyTable1", FsRangeAddress("A1:B2"))
- FsTable("dummyTable2", FsRangeAddress("C3:F5"))
+ FsTable("dummyTable1", FsRangeAddress.fromString("A1:B2"))
+ FsTable("dummyTable2", FsRangeAddress.fromString("C3:F5"))
|]
dummyWorkbook.AddWorksheet dummyWorksheet1 |> ignore
dummyWorkbook.AddWorksheet dummyWorksheet2 |> ignore
diff --git a/tests/FsSpreadsheet.Tests/FsWorksheetTests.fs b/tests/FsSpreadsheet.Tests/FsWorksheetTests.fs
index 7465adce..f8aa1003 100644
--- a/tests/FsSpreadsheet.Tests/FsWorksheetTests.fs
+++ b/tests/FsSpreadsheet.Tests/FsWorksheetTests.fs
@@ -5,8 +5,8 @@ open Fable.Pyxpecto
open FsSpreadsheet
let dummyCellsColl = FsCellsCollection()
-let dummyTable1 = FsTable("dummyTable1", FsRangeAddress("A1:B2"))
-let dummyTable2 = FsTable("dummyTable2", FsRangeAddress("D1:F3"))
+let dummyTable1 = FsTable("dummyTable1", FsRangeAddress.fromString("A1:B2"))
+let dummyTable2 = FsTable("dummyTable2", FsRangeAddress.fromString("D1:F3"))
let dummySheet1 = FsWorksheet("dummySheet1", ResizeArray(), ResizeArray(), dummyCellsColl)
let dummySheet2 = FsWorksheet("dummySheet2", ResizeArray(), ResizeArray([dummyTable1; dummyTable2]), dummyCellsColl)
let bigDummySheetName = "My Awesome Worksheet"
diff --git a/tests/JS/Exceljs.js b/tests/JS/Exceljs.js
index 2af82b54..58af8574 100644
--- a/tests/JS/Exceljs.js
+++ b/tests/JS/Exceljs.js
@@ -1,7 +1,7 @@
import { equal } from 'assert';
import { Xlsx } from './FsSpreadsheet.Js/Xlsx.js';
import { FsWorkbook } from "./FsSpreadsheet.Js/FsSpreadsheet/FsWorkbook.js";
-import { FsRangeAddress_$ctor_Z721C83C5, FsRangeAddress__get_Range } from "./FsSpreadsheet.Js/FsSpreadsheet/Ranges/FsRangeAddress.js";
+import { FsRangeAddress } from "./FsSpreadsheet.Js/FsSpreadsheet/Ranges/FsRangeAddress.js";
import { FsTable } from "./FsSpreadsheet.Js/FsSpreadsheet/Tables/FsTable.js";
import { writeFromFsWorkbook, readToFsWorkbook } from "./FsSpreadsheet.Js/Workbook.js";
@@ -94,7 +94,7 @@ describe('FsSpreadsheet.Js', function () {
fsws.Row(1).Item(4).SetValueAs("My Column 3");
fsws.Row(2).Item(4).SetValueAs(true);
fsws.Row(3).Item(4).SetValueAs(false);
- const table = new FsTable("MyNewTable", FsRangeAddress_$ctor_Z721C83C5("B1:D3"));
+ const table = new FsTable("MyNewTable", FsRangeAddress.fromString("B1:D3"));
fsws.AddTable(table);
fsws.RescanRows()
await Xlsx.toXlsxFile(path, fswb)
diff --git a/tests/TestUtils/DefaultTestObjects.fs b/tests/TestUtils/DefaultTestObjects.fs
index 9fd27e9b..7f9fcf2e 100644
--- a/tests/TestUtils/DefaultTestObjects.fs
+++ b/tests/TestUtils/DefaultTestObjects.fs
@@ -49,7 +49,7 @@ type WriteTestFiles =
module ExpectedRows =
let headerRow (range:string) cc =
- let row = FsRow(FsRangeAddress(range),cc)
+ let row = FsRow(FsRangeAddress.fromString(range),cc)
row[1].SetValueAs "Numbers"
row[2].SetValueAs "Strings"
row[3].SetValueAs "DateTime"
@@ -58,7 +58,7 @@ module ExpectedRows =
row[6].SetValueAs "ARCtrl Column "
row
let firstRow(range: string) cc =
- let row = FsRow(FsRangeAddress(range),cc)
+ let row = FsRow(FsRangeAddress.fromString(range),cc)
row[1].SetValueAs 1.
row[2].SetValueAs "Hello"
row[3].SetValueAs (System.DateTime(2023,10,14,0,0,0))
@@ -67,7 +67,7 @@ module ExpectedRows =
row[6].SetValueAs "(A) This is part 2 of 2"
row
let secondRow(range:string) cc =
- let row = FsRow(FsRangeAddress(range),cc)
+ let row = FsRow(FsRangeAddress.fromString(range),cc)
row[1].SetValueAs 2.
row[2].SetValueAs "World"
row[3].SetValueAs (System.DateTime(2023,10,15, 18,0,0))
@@ -75,14 +75,14 @@ module ExpectedRows =
row[6].SetValueAs "Tests if column names with whitespace at end can be unique"
row
let thirdRow(range:string) cc =
- let row = FsRow(FsRangeAddress(range),cc)
+ let row = FsRow(FsRangeAddress.fromString(range),cc)
row[1].SetValueAs 3.
row[2].SetValueAs "Bye"
row[3].SetValueAs (System.DateTime(2023,10,16, 20,0,0))
row[4].SetValueAs true
row
let fourthRow(range:string) cc =
- let row = FsRow(FsRangeAddress(range),cc)
+ let row = FsRow(FsRangeAddress.fromString(range),cc)
row[1].SetValueAs 4.269
row[2].SetValueAs "Outer Space"
row[3].SetValueAs (System.DateTime(2023,10,17,0,0,0))
@@ -119,7 +119,7 @@ module Sheet3 =
let defaultTestObject() =
let wb = new FsWorkbook()
- let table1 = new FsTable(Sheet1.tableName, FsRangeAddress(FsAddress("A1"),FsAddress("F5")))
+ let table1 = new FsTable(Sheet1.tableName, FsRangeAddress(FsAddress.fromString("A1"),FsAddress.fromString("F5")))
let sheet1 = wb.InitWorksheet(Sheet1.sheetName)
for row in ExpectedRows.rowCollectionA1 do
for c in row do
@@ -129,7 +129,7 @@ let defaultTestObject() =
for row in ExpectedRows.rowCollectionA1 do
for c in row do
sheet2.AddCell c |> ignore
- let table2 = new FsTable(Sheet3.tableName, FsRangeAddress(FsAddress("B4"),FsAddress("G8")))
+ let table2 = new FsTable(Sheet3.tableName, FsRangeAddress(FsAddress.fromString("B4"),FsAddress.fromString("G8")))
let sheet3 = wb.InitWorksheet(Sheet3.sheetName)
for row in ExpectedRows.rowCollectionB4 do
for c in row do