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

When copying styles, they sometimes become bottom-aligned. #1708

Closed
yuki2006 opened this issue Nov 1, 2023 · 1 comment
Closed

When copying styles, they sometimes become bottom-aligned. #1708

yuki2006 opened this issue Nov 1, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@yuki2006
Copy link
Contributor

yuki2006 commented Nov 1, 2023

Description

Steps to reproduce the issue:

  1. use Book1.xlsx
  2. execute the code below.
  3. Open the outputted file.
    Book2.xlsx

image
image

func copyStyle(f *excelize.File, src, dst string) error {
	styleID, err := f.GetCellStyle("Sheet1", src)
	if err != nil {
		return err
	}
	style, err := f.GetStyle(styleID)
	if err != nil {
		return err
	}
	if style.Font == nil {
		style.Font = &excelize.Font{}
	}
	style.Font.Strike = true
	newStyleID, err := f.NewStyle(style)
	if err != nil {
		return err
	}
	err = f.SetCellValue("Sheet1", dst, "Hello world.")
	if err != nil {
		return err
	}
	err = f.SetCellStyle("Sheet1", dst, dst, newStyleID)
	if err != nil {
		return err
	}
	return nil
}

func main() {

	f, err := excelize.OpenFile("Book1.xlsx")
	if err != nil {
		panic(err)
	}

	err = copyStyle(f, "A1", "B1")
	if err != nil {
		panic(err)
	}
	err = copyStyle(f, "A2", "B2")
	if err != nil {
		panic(err)
	}

	err = f.SaveAs("Book2.xlsx")
	if err != nil {
		panic(err)
	}
}

Describe the results you received:

image

Describe the results you expected:

I want both to remain in their original style without becoming bottom-aligned.

Output of go version:

go version go1.21.3 darwin/arm64

Excelize version or commit ID:

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

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

image

@xuri xuri added bug Something isn't working in progress Working in progress labels Nov 2, 2023
@xuri xuri closed this as completed in 4e936da Nov 2, 2023
@xuri
Copy link
Member

xuri commented Nov 2, 2023

Thanks for your issue. This issue has been fixed, please try to upgrade the master branch code, and this patch will be released in the next version.

@xuri xuri removed the in progress Working in progress label Nov 2, 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
None yet
Development

No branches or pull requests

2 participants