Skip to content

Commit

Permalink
fix table id determination
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Jun 24, 2022
1 parent 1083d65 commit a227766
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/FsSpreadsheet.ExcelIO/FsExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ module FsExtensions =
Worksheet.setSheetData sheetData sheet


member self.AppendTablesToWorksheetPart(worksheetPart : DocumentFormat.OpenXml.Packaging.WorksheetPart) =
member self.AppendTablesToWorksheetPart(workbookPart : DocumentFormat.OpenXml.Packaging.WorkbookPart,worksheetPart : DocumentFormat.OpenXml.Packaging.WorksheetPart) =
self.GetTables()
|> Seq.iter (fun t ->
let table = t.ToExcelTable(self.CellCollection)
Table.addTable worksheetPart table |> ignore
Table.addTable workbookPart worksheetPart table |> ignore
)


Expand All @@ -67,7 +67,7 @@ module FsExtensions =
WorkbookPart.appendWorksheet worksheet.Name (worksheet.ToExcelWorksheet()) workbookPart
|> WorkbookPart.getOrInitWorksheetPartByName worksheet.Name

worksheet.AppendTablesToWorksheetPart(worksheetPart)
worksheet.AppendTablesToWorksheetPart(workbookPart,worksheetPart)
//Worksheet.setSheetData sheetData sheet |> ignore
//WorkbookPart.appendWorksheet worksheet.Name sheet workbookPart |> ignore
)
Expand Down
7 changes: 3 additions & 4 deletions src/FsSpreadsheet.ExcelIO/Table.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,9 @@ module Table =
t

/// Adds a table to the worksheetPart.
let addTable (worksheetPart : WorksheetPart) (table : Table) =
let addTable (workbookPart : WorkbookPart) (worksheetPart : WorksheetPart) (table : Table) =
// https://stackoverflow.com/questions/53440352/openxml-table-creation-how-do-i-create-tables-without-requiring-excel-to-repa
printfn "Start addTable."
let id = worksheetPart.TableDefinitionParts |> Seq.length |> (+) 1
let id = workbookPart.WorksheetParts |> Seq.sumBy (fun wsp -> wsp.TableDefinitionParts |> Seq.length) |> (+) 1
let tableDefinitionPart = worksheetPart.AddNewPart<TableDefinitionPart>(sprintf "rId%i" id);
table.Id <- (UInt32Value.FromUInt32(uint id))
table.Name <- StringValue(sprintf "Table%i" id)
Expand All @@ -259,7 +258,7 @@ module Table =
//tableParts.AppendChild(tablePart) |> ignore
tableParts.AppendChild(tablePart) |> ignore

printfn "TableID: %i" id
//printfn "TableID: %i" id
worksheetPart

/// Create a table object by an area. If the first row of this area contains values in the given sheet, these are chosen as headers for the table and a table is returned.
Expand Down

0 comments on commit a227766

Please sign in to comment.