From 2a89008a545ce515c071cbbf3cc425de048012be Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 15 Jun 2023 10:41:33 +1000 Subject: [PATCH] generate empty workbook if no data to add --- cmd/main/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/main/main.go b/cmd/main/main.go index 02bc325..48d99cf 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -153,6 +153,16 @@ func main() { // Get an interface that we can work with to access the sub elements vslice := vislice.([]interface{}) + if len(vslice) < 1 { + // There was no data but lets just log that and close off the empty workbook + fmt.Printf("No data found contained in top-level json key '%s', no work to do.\n", parentNode) + // Close off the file + if err := xlsx.SaveAs(outputFilename); err != nil { + log.Fatal(err) + } + return + } + // Check that the first element is what we expected if _, ok := vslice[0].(orderedmap.OrderedMap); !ok { error := fmt.Sprintf("Type of first vslice element is not an ordered map. It appears to be '%v'\n", reflect.TypeOf(vslice[0]))