1 Commits

Author SHA1 Message Date
4bffb9cbfc do some error checking before asserting orderedmap 2023-04-18 09:20:36 +10:00

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"reflect"
"time"
"unicode/utf8"
@@ -102,11 +103,18 @@ func main() {
if !ok {
fmt.Printf("Missing key for multitype array")
}
// Get an interface that we can work with to access the sub elements
vslice := vislice.([]interface{})
// 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]))
panic(error)
}
// Get the keys for the first element so we know what the column names will be
columnMap := vslice[0].(orderedmap.OrderedMap)
fmt.Printf("First vslice element is an ordered map")
columnNames := columnMap.Keys()
// Run code to add column names to the first row of the workbook