Created
January 8, 2020 18:29
-
-
Save blainne/3eb2b24eafe518cb4ba01103937c0517 to your computer and use it in GitHub Desktop.
F# version of sample from https://docs.microsoft.com/en-us/office/open-xml/how-to-create-a-spreadsheet-document-by-providing-a-file-name
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
let CreateSpreadsheetWorkbook (filepath:string) = | |
// Create a spreadsheet document by supplying the filepath. | |
// By default, AutoSave = true, Editable = true, and Type = xlsx. | |
let spreadsheetDocument:SpreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook) | |
// Add a WorkbookPart to the document. | |
let workbookpart = spreadsheetDocument.AddWorkbookPart() | |
workbookpart.Workbook <- new Workbook() | |
// Add a WorksheetPart to the WorkbookPart. | |
let worksheetPart = workbookpart.AddNewPart<WorksheetPart>() | |
worksheetPart.Worksheet <- new Worksheet(new SheetData()) | |
// Add Sheets to the Workbook. | |
let sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets()); | |
// Append a new worksheet and associate it with the workbook. | |
let sheet = new Sheet | |
( | |
Id = new StringValue(spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart)), | |
SheetId = UInt32Value.FromUInt32(1u), | |
Name = new StringValue("mySheet") | |
) | |
sheets.Append(sheet); | |
workbookpart.Workbook.Save(); | |
// Close the document. | |
spreadsheetDocument.Close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment