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

Setting Cell to NaN leads to "problem with some content" dialog in Excel #1955

Closed
MattBrittan opened this issue Jul 18, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@MattBrittan
Copy link

Description

Setting a cell value to NaN (i.e. math.NaN()) leads to an error when the resulting file is opened in Excel.

Note: Old issue #119 looks pretty much identical, xuri mentioned the library handled this OK in xlsx files but that does not appear to be the case (or an issue has been introduced in the interim). Excel does not really support NaN values so the solution to this is not obvious.

Steps to reproduce the issue:

Run code below:

package main

import (
	"fmt"
	excelize "github.com/xuri/excelize/v2"
	"math"
)

func main() {
	f := excelize.NewFile()

	if err := f.SetCellValue("Sheet1", "A1", math.NaN()); err != nil {
		panic(err)
	}

	if err := f.SaveAs("Book1.xlsx"); err != nil {
		fmt.Println(err)
	}
}

Describe the results you received:.

Error when opening resulting file in Excel.

Excel: We found a problem dialog

Excel : removed unreadable content

Describe the results you expected:

Either:

  1. An error from SetCellValue
  2. Excel file that opens and the cell contains either (not a perfect option here as Excel does not really support NaN)
    • The text NaN
    • #N/A error (perhaps =NA() formula).

I wonder if the first option is better as that leaves it up to the developer to resolve this.

Output of go version:

go version go1.22.4 windows/amd64

Excelize version or commit ID:

v2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):

Windows 11, Excel for Microsoft 365 (Version 2406 build 16.0.17726.20078) 64-Bit

@MattBrittan MattBrittan changed the title 119 Setting Cell to NaN leads to "problem with some content" dialog in Excel Jul 18, 2024
@xuri xuri added the bug Something isn't working label Jul 18, 2024
@xuri xuri closed this as completed in 4dd3447 Jul 18, 2024
@xuri
Copy link
Member

xuri commented Jul 18, 2024

Thanks for your feedback. This issue has been fixed, now cell value will be represent in string or inline string for any IEEE 754 "not-a-number" value or infinity numeric. Please upgrade to the master branch code by go get -u github.com/xuri/excelize/v2@master, and this patch will be released in the next version.

zhangyimingdatiancai pushed a commit to zhangyimingdatiancai/excelize that referenced this issue Aug 6, 2024
…ith an IEEE 754 "not-a-number" value or infinity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Bugfix
Development

No branches or pull requests

2 participants