Skip to content

Commit

Permalink
Fix: #254
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Sep 9, 2024
1 parent 5249642 commit 18e105d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
34 changes: 28 additions & 6 deletions internal/renderers/excel/excel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package excel
import (
"fmt"
_ "image/png"
"unicode/utf8"

"github.com/Azure/azqr/internal/embeded"
"github.com/Azure/azqr/internal/renderers"
Expand Down Expand Up @@ -46,11 +45,15 @@ func autofit(f *excelize.File, sheetName string) error {
for idx, col := range cols {
largestWidth := 0
for _, rowCell := range col {
cellWidth := utf8.RuneCountInString(rowCell) + 1
cellWidth := len(rowCell) + 3
if cellWidth > largestWidth {
largestWidth = cellWidth
}
}
if largestWidth > 255 {
largestWidth = 120
}

name, err := excelize.ColumnNumberToName(idx + 1)
if err != nil {
return err
Expand All @@ -60,6 +63,7 @@ func autofit(f *excelize.File, sheetName string) error {
return err
}
}

return nil
}

Expand Down Expand Up @@ -103,10 +107,10 @@ func createFirstRow(f *excelize.File, sheet string, headers []string) {
}

func setHyperLink(f *excelize.File, sheet string, col, currentRow int) {
display := "Learn"
tooltip := "Learn more..."
cell, _ := excelize.CoordinatesToCellName(col, currentRow)
link, _ := f.GetCellValue(sheet, cell)
display := link
tooltip := "Learn more..."
if link != "" {
_ = f.SetCellValue(sheet, cell, display)
_ = f.SetCellHyperLink(sheet, cell, link, "External", excelize.HyperlinkOpts{Display: &display, Tooltip: &tooltip})
Expand Down Expand Up @@ -146,12 +150,25 @@ func configureSheet(f *excelize.File, sheet string, headers []string, currentRow
}

func applyBlueStyle(f *excelize.File, sheet string, lastRow int, columns int) {
style, err := f.NewStyle(&excelize.Style{
blue, err := f.NewStyle(&excelize.Style{
Fill: excelize.Fill{
Type: "pattern",
Color: []string{"#CAEDFB"},
Pattern: 1,
},
Alignment: &excelize.Alignment{
Vertical: "top",
WrapText: true,
},
})
if err != nil {
log.Fatal().Err(err).Msg("Failed to create blue style")
}
white, err := f.NewStyle(&excelize.Style{
Alignment: &excelize.Alignment{
Vertical: "top",
WrapText: true,
},
})
if err != nil {
log.Fatal().Err(err).Msg("Failed to create blue style")
Expand All @@ -165,7 +182,12 @@ func applyBlueStyle(f *excelize.File, sheet string, lastRow int, columns int) {
}

if i%2 == 0 {
err = f.SetCellStyle(sheet, cell, cell, style)
err = f.SetCellStyle(sheet, cell, cell, blue)
if err != nil {
log.Fatal().Err(err).Msg("Failed to set style")
}
} else {
err = f.SetCellStyle(sheet, cell, cell, white)
if err != nil {
log.Fatal().Err(err).Msg("Failed to set style")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/renderers/excel/recommendations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func renderRecommendations(f *excelize.File, data *renderers.ReportData) int {
if err != nil {
log.Fatal().Err(err).Msg("Failed to set row")
}
// setHyperLink(f, sheetName, 12, currentRow)
setHyperLink(f, sheetName, 11, currentRow)
}

configureSheet(f, sheetName, headers, currentRow)
Expand Down

0 comments on commit 18e105d

Please sign in to comment.