do formatting to heading row of empty worksheet
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2024-06-28 09:19:25 +10:00
parent bfa2afbb6c
commit d5a803644b

View File

@@ -162,16 +162,35 @@ func main() {
// Run code to add column names to the first row of the workbook based off the keyOrder, if defined // Run code to add column names to the first row of the workbook based off the keyOrder, if defined
if len(config.keyOrder) > 0 { if len(config.keyOrder) > 0 {
// Create a slice to hold the values
var columnHeadings []string var columnHeadings []string
// Iterate over the map and append each value to the slice
for _, value := range config.keyOrder { for _, value := range config.keyOrder {
columnHeadings = append(columnHeadings, value) columnHeadings = append(columnHeadings, value)
} }
createHeadingRow(xlsx, worksheetName, columnHeadings) createHeadingRow(xlsx, worksheetName, columnHeadings)
headerStyle, err := xlsx.NewStyle(&excelize.Style{
Font: &excelize.Font{
Bold: true,
},
})
if err != nil {
fmt.Printf("Error generating header style : '%s'\n", err)
} else {
// Set the style if there was no error generating it
if boldTopRow {
err = xlsx.SetRowStyle(worksheetName, 1, 1, headerStyle)
if err != nil {
fmt.Printf("Error setting header style : '%s'\n", err)
}
}
}
if autoWidth {
err = SetColAutoWidth(xlsx, worksheetName)
if err != nil {
fmt.Printf("Error setting auto width : '%s'\n", err)
}
}
} }
// Close off the file // Close off the file
@@ -224,13 +243,13 @@ func main() {
}) })
if err2 != nil { if err2 != nil {
fmt.Printf("Error generating header style : '%s'\n", err2) fmt.Printf("Error generating header style : '%s'\n", err2)
} } else {
// Set the style if there was no error generating it
// Set the style if boldTopRow {
if boldTopRow { err = xlsx.SetRowStyle(worksheetName, 1, 1, headerStyle)
err = xlsx.SetRowStyle(worksheetName, 1, 1, headerStyle) if err != nil {
if err != nil { fmt.Printf("Error setting header style : '%s'\n", err)
fmt.Printf("Error setting header style : '%s'\n", err) }
} }
} }