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

Different gradient fill colors return the same style index #1820

Closed
edwardfward opened this issue Feb 22, 2024 · 2 comments · Fixed by #1821
Closed

Different gradient fill colors return the same style index #1820

edwardfward opened this issue Feb 22, 2024 · 2 comments · Fixed by #1821
Labels
bug Something isn't working

Comments

@edwardfward
Copy link
Contributor

Different gradient fills produce the same style index making it impossible to use more than one gradient fill in a workbook.

package main

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

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

	s1 := excelize.Style{
		Fill: excelize.Fill{
			Type:    "gradient",
			Pattern: 1,
			Shading: 1,
			Color:   []string{"#000000", "#FFFFFF"},
		},
	}

	s2 := excelize.Style{
		Fill: excelize.Fill{
			Type:    "gradient",
			Pattern: 1,
			Shading: 1,
			Color:   []string{"#FFFF00", "#000000"},
		},
	}

	s1Index, _ := f.NewStyle(&s1)
	s2Index, _ := f.NewStyle(&s2)

	fmt.Println("s1Index:", s1Index)
	fmt.Println("s2Index:", s2Index)
}

Describe the results you received:

s1Index: 1
s2Index: 1

Describe the results you expected:

s1Index: 1
s2Index: (Something other than 1)

Output of go version:

go version go1.22.0 darwin/arm64

Excelize version or commit ID:

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

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

Apple M2 Max (Mac OS 14.2.1)
@xuri
Copy link
Member

xuri commented Feb 23, 2024

Thanks for your issue. I have tested with the v2.8.0, and it works well. This bug was introduced by commit 9c079e5. We need to change the array variable styleFillVariants to a function to fix this:

styleFillVariants = func() []xlsxGradientFill {
    return []xlsxGradientFill{
        // ...
    }
}

Would you like to create a pull request to help us fix this problem?

@xuri xuri added the confirmed This issue can be reproduced label Feb 23, 2024
@edwardfward
Copy link
Contributor Author

I will give it a go.

@xuri xuri added bug Something isn't working and removed confirmed This issue can be reproduced labels Feb 24, 2024
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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants