1 Commits

Author SHA1 Message Date
2a89008a54 generate empty workbook if no data to add 2023-06-15 10:41:33 +10:00

View File

@@ -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]))