Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
fix corrupt Excel report when value is NaN (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
harp-intel committed Jun 27, 2024
1 parent 08b06d0 commit 525bc5f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/reporter/report_generator_xlsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"fmt"
"math"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -67,11 +68,10 @@ func renderExcelTable(tableHeaders []string, tableValues [][]string, f *excelize
for _, header := range tableHeaders {
// if possible, convert strings to floats before inserting into the sheet
floatValue, err := strconv.ParseFloat(header, 64)
if err == nil {
if err == nil && !math.IsNaN(floatValue) { // if it's a number, right align it
f.SetCellFloat(reportSheetName, cellName(col, row), floatValue, 1, 64)
f.SetCellStyle(reportSheetName, cellName(col, row), cellName(col, row), boldAlignLeft)
} else {

f.SetCellStr(reportSheetName, cellName(col, row), header)
f.SetCellStyle(reportSheetName, cellName(col, row), cellName(col, row), bold)
}
Expand All @@ -85,7 +85,7 @@ func renderExcelTable(tableHeaders []string, tableValues [][]string, f *excelize
for rowIdx, value := range rowValues {
// if possible, convert strings to floats before inserting into the sheet
floatValue, err := strconv.ParseFloat(value, 64)
if err == nil {
if err == nil && !math.IsNaN(floatValue) { // if it's a number, right align it
f.SetCellFloat(reportSheetName, cellName(col, row), floatValue, 1, 64)
f.SetCellStyle(reportSheetName, cellName(col, row), cellName(col, row), alignLeft)
} else {
Expand Down

0 comments on commit 525bc5f

Please sign in to comment.