From 4eaf806c4e64bcabc762517e07001886efde4611 Mon Sep 17 00:00:00 2001 From: HLWeil Date: Mon, 12 Feb 2024 12:31:00 +0100 Subject: [PATCH] add fail for writing empty workbook #38 --- src/FsSpreadsheet.ExcelIO/FsExtensions.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FsSpreadsheet.ExcelIO/FsExtensions.fs b/src/FsSpreadsheet.ExcelIO/FsExtensions.fs index 70d3eaca..4c625679 100644 --- a/src/FsSpreadsheet.ExcelIO/FsExtensions.fs +++ b/src/FsSpreadsheet.ExcelIO/FsExtensions.fs @@ -335,8 +335,10 @@ module FsExtensions = /// Writes the FsWorkbook into a given MemoryStream. /// member self.ToStream(stream : MemoryStream) = + if self.GetWorksheets() |> Seq.isEmpty then + failwith "Cannot write an empty workbook to a stream. Workbook did not contain any Worksheets." let doc = Spreadsheet.initEmptyOnStream stream - + self.ToEmptySpreadsheet(doc) //Worksheet.setSheetData sheetData sheet |> ignore //WorkbookPart.appendWorksheet worksheet.Name sheet workbookPart |> ignore