diff --git a/src/FsSpreadsheet/Tables/FsTable.fs b/src/FsSpreadsheet/Tables/FsTable.fs
index ff6c953c..2f7fffdc 100644
--- a/src/FsSpreadsheet/Tables/FsTable.fs
+++ b/src/FsSpreadsheet/Tables/FsTable.fs
@@ -2,6 +2,9 @@
open System.Collections.Generic
+///
+/// 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, showTotalsRow, showHeaderRow) =
inherit FsRangeBase(rangeAddress)
@@ -15,15 +18,27 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
let mutable _fieldNames : Dictionary = Dictionary()
let _uniqueNames : HashSet = HashSet()
+ ///
+ /// Creates an FsTable from the given name and FsRangeAddres, with header row shown or not, accordingly.
+ ///
+ /// `showTotalsRow` is false by default.
new (name, rangeAddress, showHeaderRow) = FsTable (name, rangeAddress, false, showHeaderRow)
+ ///
+ /// Creates an FsTable from the given name and FsRangeAddres.
+ ///
+ /// `showTotalsRow` is false and `showHeaderRow` true, by default.
new (name, rangeAddress) = FsTable (name, rangeAddress, false, true)
- /// The name of the FsTable.>/summary>
+ ///
+ /// The name of the FsTable.
+ ///
member self.Name
with get() = _name
- /// Returns all fieldnames as `fieldname*FsTableField` dictionary.
+ ///
+ /// Returns all fieldnames as `fieldname*FsTableField` dictionary.
+ ///
member self.FieldNames
with get(cellsCollection) =
if (_fieldNames <> null && _lastRangeAddress <> null && _lastRangeAddress.Equals(self.RangeAddress)) then
@@ -35,19 +50,25 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
_fieldNames;
- /// The FsTableFields of this FsTable.
+ ///
+ /// The FsTableFields of this FsTable.
+ ///
member self.Fields
with get(cellsCollection) =
let columnCount = base.ColumnCount()
let offset = base.RangeAddress.FirstAddress.ColumnNumber
Seq.init columnCount (fun i -> self.GetField(i + offset, cellsCollection))
- /// Gets or sets if the header row is shown.
+ ///
+ /// Gets or sets if the header row is shown.
+ ///
member self.ShowHeaderRow
with get () = _showHeaderRow
and set(showHeaderRow) = _showHeaderRow <- showHeaderRow
- /// Returns the header row as FsRangeRow. Scans for fieldnames if `scanForNewFieldsNames` is true.
+ ///
+ /// Returns the header row as FsRangeRow. Scans for fieldnames if `scanForNewFieldsNames` is true.
+ ///
member self.HeadersRow(scanForNewFieldsNames : bool) =
if (not self.ShowHeaderRow) then null;
@@ -59,11 +80,13 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
FsRange(base.RangeAddress).FirstRow();
- /// Returns the header row as FsRangeRow. Scans for new fieldnames.
+ ///
+ /// Returns the header row as FsRangeRow. Scans for new fieldnames.
+ ///
member self.HeadersRow() =
self.HeadersRow(true)
- /// Takes the respective FsCellsCollection for this FsTable and creates a new _fieldNames dictionary if the current one does not match.
+ /// Takes the respective FsCellsCollection for this FsTable and creates a new _fieldNames dictionary if the current one does not match.
// TO DO: maybe HLW can specify above description a bit...
member private self.RescanFieldNames(cellsCollection : FsCellsCollection) =
printfn "Start RescanFieldNames"
@@ -151,24 +174,45 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
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.AddFields(fieldNames : seq) =
-
- // _fieldNames = new Dictionary();
-
- // Int32 cellPos = 0;
- let mutable cellPos = 0
- let range = base.RangeAddress.FirstAddress. // NEED: FsRangeBase.toFsRangeColumns
+ // _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)
+ )
+ this
+
+ ///
+ /// Creates and adds FsTableFields from a sequence of field names to a given FsTable.
+ ///
+ static member addFieldsFromNames (fieldNames : seq) (table : FsTable) =
+ table.AddFields fieldNames
+
+ ///
+ /// Adds a sequence of FsTableFields to the FsTable.
+ ///
+ member this.AddFields(tableFields : seq) =
+ tableFields
|> Seq.iter (
- fun fn ->
- _fieldNames.Add(fn, FsTableField())
+ fun tf -> _fieldNames.Add(tf.Name, tf)
)
- // foreach (var name in fieldNames)
- // {
- // _fieldNames.Add(name, new XLTableField(this, name) { Index = cellPos++ });
- // }
+ this
- /// Returns the FsTableField with given name. If an FsTableField does not exist under this name in the FsTable, adds it.
+ ///
+ /// Adds a sequence of FsTableFields to a given FsTable.
+ ///
+ static member addFields (tableFields : seq) (table : FsTable) =
+ table.AddFields tableFields
+
+ ///
+ /// Returns the FsTableField with given name. If an FsTableField does not exist under this name in the FsTable, adds it.
+ ///
member self.Field(name : string, cellsCollection : FsCellsCollection) =
match Dictionary.tryGet name _fieldNames with
| Some field ->
@@ -192,19 +236,28 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
self.RescanRange()
newField
- /// Takes a name of an FsTableField and an FsCellsCollection (belonging to the FsWorksheet of this FsTable) and returns the respective FsTableField.
+ ///
+ /// 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 self.GetField(name : string, cellsCollection : FsCellsCollection) =
let name = name.Replace("\r\n", "\n")
try self.FieldNames(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.
+ ///
+ /// 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 getFieldByName (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.
+ ///
+ /// 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 self.GetField(index, cellsCollection) =
try
@@ -212,12 +265,17 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
|> 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.
+ ///
+ /// 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 self.GetFieldIndex(name : string, cellsCollection) =
self.GetField(name, cellsCollection).Index
- /// Renames a fieldname of the FsTable if it exists. Else fails.
+ ///
+ /// 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
@@ -227,7 +285,9 @@ type FsTable (name : string, rangeAddress, showTotalsRow, showHeaderRow) =
| None ->
raise (System.ArgumentException("The FsTabelField does not exist in this FsTable", "oldName"))
- /// Renames a fieldname of the FsTable if it exists. Else fails.
+ ///
+ /// 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)
\ No newline at end of file