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

GetConditionalFormats reads a conditional format that is higher than the average and reports a null pointer error #1745

Closed
ShowerBandV opened this issue Dec 7, 2023 · 3 comments
Labels
bug Something isn't working
Projects

Comments

@ShowerBandV
Copy link

Description
I have an Excel file that sets a conditional format higher than the average, and calling GetConditionalFormats reports an error with a null pointer

here is my code

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/xuri/excelize/v2"
)

func main() {
	file, err := excelize.OpenFile("ddd.xlsx")
	if err != nil {
		fmt.Printf("open file failed:%s", err.Error())
		return
	}
	formats, err := file.GetConditionalFormats("Sheet1")
	if err != nil {
		fmt.Printf("get conditionformats failed:%s", err.Error())
		return
	}
	fmt.Println(formats)
}

and the error is

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x5407b0]

goroutine 1 [running]:
github.com/xuri/excelize/v2.extractCondFmtAboveAverage(_, _)
        D:/Users/yl5713/go/pkg/mod/github.com/xuri/excelize/v2@v2.8.0/styles.go:2701 +0x90 
github.com/xuri/excelize/v2.(*File).GetConditionalFormats(0xc00016e160, {0x5ef156, 0x6})   
        D:/Users/yl5713/go/pkg/mod/github.com/xuri/excelize/v2@v2.8.0/styles.go:2857 +0x6be
main.main()
        E:/projects/excelizeDemo/main.go:17 +0x1c5

After changing the conditional format to below average, GetConditionalFormats can be used normally. The conditional format is above average, and there is no AboveAverage in the XML. I hope excelize can handle it。

<conditionalFormatting sqref="A1:C8">
<cfRule type="aboveAverage" dxfId="2" priority="2"/>
</conditionalFormatting>
<conditionalFormatting sqref="F1:H8">
<cfRule type="aboveAverage" dxfId="0" priority="1" aboveAverage="0"/>
</conditionalFormatting>
@xuri
Copy link
Member

xuri commented Dec 7, 2023

Thanks for your issue. Which version of the Excelize library are you using? If you open an existing workbook, could you provide the file attachment without confidential info?

@xuri xuri added the needs more info This issue can't reproduce, need more info label Dec 7, 2023
@ShowerBandV
Copy link
Author

ShowerBandV commented Dec 7, 2023

ddd.xlsx
github.com/xuri/excelize/v2 v2.8.0

@xuri xuri added bug Something isn't working and removed needs more info This issue can't reproduce, need more info labels Dec 7, 2023
@xuri xuri added this to Bugfix in v2.8.1 Dec 7, 2023
@xuri xuri added the in progress Working in progress label Dec 7, 2023
@xuri xuri closed this as completed in 866f308 Dec 7, 2023
@xuri
Copy link
Member

xuri commented Dec 7, 2023

Thanks for your feedback. I have fixed this. Please upgrade to the master branch code, and this patch will be released in the next version.

@xuri xuri removed the in progress Working in progress label Dec 7, 2023
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
v2.8.1
Bugfix
Development

No branches or pull requests

2 participants