@@ -6,7 +6,6 @@ package excel
66import (
77 "fmt"
88 _ "image/png"
9- "unicode/utf8"
109
1110 "github.com/Azure/azqr/internal/embeded"
1211 "github.com/Azure/azqr/internal/renderers"
@@ -46,11 +45,15 @@ func autofit(f *excelize.File, sheetName string) error {
4645 for idx , col := range cols {
4746 largestWidth := 0
4847 for _ , rowCell := range col {
49- cellWidth := utf8 . RuneCountInString (rowCell ) + 1
48+ cellWidth := len (rowCell ) + 3
5049 if cellWidth > largestWidth {
5150 largestWidth = cellWidth
5251 }
5352 }
53+ if largestWidth > 255 {
54+ largestWidth = 120
55+ }
56+
5457 name , err := excelize .ColumnNumberToName (idx + 1 )
5558 if err != nil {
5659 return err
@@ -60,6 +63,7 @@ func autofit(f *excelize.File, sheetName string) error {
6063 return err
6164 }
6265 }
66+
6367 return nil
6468}
6569
@@ -103,10 +107,10 @@ func createFirstRow(f *excelize.File, sheet string, headers []string) {
103107}
104108
105109func setHyperLink (f * excelize.File , sheet string , col , currentRow int ) {
106- display := "Learn"
107- tooltip := "Learn more..."
108110 cell , _ := excelize .CoordinatesToCellName (col , currentRow )
109111 link , _ := f .GetCellValue (sheet , cell )
112+ display := link
113+ tooltip := "Learn more..."
110114 if link != "" {
111115 _ = f .SetCellValue (sheet , cell , display )
112116 _ = f .SetCellHyperLink (sheet , cell , link , "External" , excelize.HyperlinkOpts {Display : & display , Tooltip : & tooltip })
@@ -146,12 +150,25 @@ func configureSheet(f *excelize.File, sheet string, headers []string, currentRow
146150}
147151
148152func applyBlueStyle (f * excelize.File , sheet string , lastRow int , columns int ) {
149- style , err := f .NewStyle (& excelize.Style {
153+ blue , err := f .NewStyle (& excelize.Style {
150154 Fill : excelize.Fill {
151155 Type : "pattern" ,
152156 Color : []string {"#CAEDFB" },
153157 Pattern : 1 ,
154158 },
159+ Alignment : & excelize.Alignment {
160+ Vertical : "top" ,
161+ WrapText : true ,
162+ },
163+ })
164+ if err != nil {
165+ log .Fatal ().Err (err ).Msg ("Failed to create blue style" )
166+ }
167+ white , err := f .NewStyle (& excelize.Style {
168+ Alignment : & excelize.Alignment {
169+ Vertical : "top" ,
170+ WrapText : true ,
171+ },
155172 })
156173 if err != nil {
157174 log .Fatal ().Err (err ).Msg ("Failed to create blue style" )
@@ -165,7 +182,12 @@ func applyBlueStyle(f *excelize.File, sheet string, lastRow int, columns int) {
165182 }
166183
167184 if i % 2 == 0 {
168- err = f .SetCellStyle (sheet , cell , cell , style )
185+ err = f .SetCellStyle (sheet , cell , cell , blue )
186+ if err != nil {
187+ log .Fatal ().Err (err ).Msg ("Failed to set style" )
188+ }
189+ } else {
190+ err = f .SetCellStyle (sheet , cell , cell , white )
169191 if err != nil {
170192 log .Fatal ().Err (err ).Msg ("Failed to set style" )
171193 }
0 commit comments