diff --git a/src/Spreadsheet/DataMap.fs b/src/Spreadsheet/DataMap.fs index 0e3076d3..3a1ac207 100644 --- a/src/Spreadsheet/DataMap.fs +++ b/src/Spreadsheet/DataMap.fs @@ -7,12 +7,18 @@ open FsSpreadsheet /// Reads an datamap from a spreadsheet let fromFsWorkbook (doc : FsWorkbook) = try + let worksheets = doc.GetWorksheets() + let sheetIsEmpty (sheet : FsWorksheet) = sheet.CellCollection.Count = 0 let dataMapTable = - doc.GetWorksheets() + worksheets |> Seq.tryPick DataMapTable.tryFromFsWorksheet match dataMapTable with | Some table -> table - | None -> failwith "No DataMapTable found in workbook" + | None -> + if worksheets |> Seq.forall sheetIsEmpty then + DataMap.init() + else + failwith "No DataMapTable was found in any of the sheets of the workbook" with | err -> failwithf "Could not parse datamap: \n%s" err.Message diff --git a/tests/Spreadsheet/DataMapTests.fs b/tests/Spreadsheet/DataMapTests.fs index 68c884c7..17434329 100644 --- a/tests/Spreadsheet/DataMapTests.fs +++ b/tests/Spreadsheet/DataMapTests.fs @@ -1,4 +1,4 @@ -module DataMapTests +module DataMapTests open ARCtrl @@ -102,7 +102,7 @@ let private emptyTable = testCase "Write" (fun () -> let sheet = DataMapTable.toFsWorksheet t Expect.equal "isa_datamap" sheet.Name "Worksheet name did not match" - Expect.equal 0 sheet.Rows.Count "Row count should be 0" + Expect.equal 0 sheet.Rows.Count "Row count should be 0" ) testCase "Read" (fun () -> let sheet = DataMapTable.toFsWorksheet t @@ -168,10 +168,20 @@ let private simpleFile = ) ] +let private emptyDatamap = + testList "emptyDatamap" [ + testCase "WriteAndRead" (fun () -> + let t = DataMap.init() + let wb = DataMap.toFsWorkbook t + let datamap = DataMap.fromFsWorkbook wb + Expect.equal datamap t "DataMap was not correctly written and read" + ) + ] let main = testList "DataMapTableTests" [ simpleTable valuelessTable emptyTable simpleFile + emptyDatamap ] \ No newline at end of file