Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #254 #255

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading