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

1820 Bug - Convert styleFillVariants from slice to func #1821

Merged
merged 1 commit into from
Feb 24, 2024

Conversation

edwardfward
Copy link
Contributor

PR Details

Fixes a bug with gradient fill styles that was causing different colored fills to return the same styleID making it impossible to use more than one gradient fill per workbook.

Description

Changed the styleFillVariants variable from []xlsxGradientFill to func() []xlsxGradientFill per @xuri's recommendation.

Related Issue

Motivation and Context

Customer required several gradient fills in the workbook we were generating for them. This PR allows use to generate those gradient fills.

How Has This Been Tested

  • Added unit test to verify gradients did not produce the same styleID
  • Executed go test ./...
ok      github.com/xuri/excelize/v2     23.656s
  • Executed the following test program to verify the fills we required returned unique styleID
package main

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

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

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

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

	s1Index, err := f.NewStyle(&s1)
	if err != nil {
		fmt.Println(err)
		return

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

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

Result:

s1Index: 1
s2Index: 2

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codecov bot commented Feb 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.20%. Comparing base (ee2ef15) to head (db46bc7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1821   +/-   ##
=======================================
  Coverage   99.20%   99.20%           
=======================================
  Files          32       32           
  Lines       23852    23871   +19     
=======================================
+ Hits        23663    23682   +19     
  Misses        101      101           
  Partials       88       88           
Flag Coverage Δ
unittests 99.20% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xuri xuri added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 24, 2024
Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution.

@xuri xuri merged commit 02b84a9 into qax-os:master Feb 24, 2024
29 checks passed
@edwardfward edwardfward deleted the 1820-gradient-fix branch February 24, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different gradient fill colors return the same style index
2 participants