-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add preliminary stylesheet functionality for cell datetime writing (wip)
- Loading branch information
Showing
7 changed files
with
194 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
namespace FsSpreadsheet.ExcelIO | ||
|
||
open DocumentFormat.OpenXml.Spreadsheet | ||
open DocumentFormat.OpenXml.Packaging | ||
open DocumentFormat.OpenXml | ||
|
||
module Stylesheet = | ||
|
||
//module Font = | ||
|
||
// let getDefault() = Font().Color | ||
|
||
|
||
let get (doc : SpreadsheetDocument) = | ||
|
||
doc.WorkbookPart.WorkbookStylesPart.Stylesheet | ||
|
||
let getOrInit (doc : SpreadsheetDocument) = | ||
|
||
match doc.WorkbookPart.WorkbookStylesPart with | ||
| null -> | ||
let ssp = doc.WorkbookPart.AddNewPart<WorkbookStylesPart>() | ||
ssp.Stylesheet <- new Stylesheet() | ||
ssp.Stylesheet.CellFormats <- new CellFormats() | ||
ssp.Stylesheet | ||
| ssp -> ssp.Stylesheet | ||
|
||
let tryGet (doc : SpreadsheetDocument) = | ||
match doc.WorkbookPart.WorkbookStylesPart with | ||
| null -> None | ||
| ssp -> Some(ssp.Stylesheet) | ||
|
||
module CellFormat = | ||
|
||
let updateCount (stylesheet : Stylesheet) = | ||
let newCount = stylesheet.CellFormats.Elements<CellFormat>() |> Seq.length | ||
stylesheet.CellFormats.Count <- UInt32Value(uint32 newCount) | ||
|
||
let count (stylesheet : Stylesheet) = | ||
if stylesheet.CellFormats = null then 0 | ||
elif stylesheet.CellFormats.Count = null then 0 | ||
else stylesheet.CellFormats.Count.Value |> int | ||
|
||
let getAt (index : int) (stylesheet : Stylesheet) = | ||
stylesheet.CellFormats.Elements<CellFormat>() |> Seq.item index | ||
|
||
let tryGetAt (index : int) (stylesheet : Stylesheet) = | ||
stylesheet.CellFormats.Elements<CellFormat>() |> Seq.tryItem index | ||
|
||
let setAt (index : int) (cf : CellFormat) (stylesheet : Stylesheet) = | ||
if count stylesheet > index then | ||
let previousChild = getAt index stylesheet | ||
stylesheet.CellFormats.ReplaceChild(cf, previousChild) |> ignore | ||
if count stylesheet = index then | ||
stylesheet.CellFormats.AppendChild(cf) |> ignore | ||
else failwith "Cannot insert style into stylesheet: Index out of range" | ||
updateCount stylesheet | ||
|
||
let append (cf : CellFormat) (stylesheet : Stylesheet) = | ||
stylesheet.CellFormats.AppendChild(cf) |> ignore | ||
updateCount stylesheet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.