do formatting to heading row of empty worksheet
This commit is contained in:
@@ -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
|
||||
if len(config.keyOrder) > 0 {
|
||||
|
||||
// Create a slice to hold the values
|
||||
var columnHeadings []string
|
||||
|
||||
// Iterate over the map and append each value to the slice
|
||||
for _, value := range config.keyOrder {
|
||||
columnHeadings = append(columnHeadings, value)
|
||||
}
|
||||
|
||||
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
|
||||
@@ -224,15 +243,15 @@ func main() {
|
||||
})
|
||||
if err2 != nil {
|
||||
fmt.Printf("Error generating header style : '%s'\n", err2)
|
||||
}
|
||||
|
||||
// Set the style
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Freeze top row if requested, see https://xuri.me/excelize/en/utils.html#SetPanes
|
||||
if freezeTopRow {
|
||||
|
Reference in New Issue
Block a user