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

StreamWriter couldn't set row style by RowOpt #1354

Closed
invzhi opened this issue Sep 20, 2022 · 3 comments · Fixed by #1355
Closed

StreamWriter couldn't set row style by RowOpt #1354

invzhi opened this issue Sep 20, 2022 · 3 comments · Fixed by #1355
Labels
confirmed This issue can be reproduced
Projects

Comments

@invzhi
Copy link
Contributor

invzhi commented Sep 20, 2022

Description

Stream Writer couldn't set row style by RowOpt.

Steps to reproduce the issue:

f := excelize.NewFile()
w, _ := f.NewStreamWriter("Sheet1")

styleID, _ := f.NewStyle(&excelize.Style{
	Fill: excelize.Fill{Type: "pattern", Color: []string{"#FBBC04"}, Pattern: 1},
})

_ = w.SetRow("A1", []interface{}{"value1", "value2"}, excelize.RowOpts{StyleID: styleID})
_ = w.Flush()

_ = f.SaveAs("demo.xlsx")

Describe the results you received:

image

Describe the results you expected:

image

Output of go version:

go version go1.18.4 darwin/arm64

Excelize version or commit ID:

v2.6.1
@xuri xuri added the confirmed This issue can be reproduced label Sep 20, 2022
@xuri
Copy link
Member

xuri commented Sep 20, 2022

Thanks for your issue. The stream writer won't apply or overwrite the style of each cell when you specify the row style, please specify the style for each cell as you need like this:

w.SetRow("A1", []interface{}{
    excelize.Cell{StyleID: styleID, Value: "value1"},
    excelize.Cell{StyleID: styleID, Value: "value2"},
})

@invzhi
Copy link
Contributor Author

invzhi commented Sep 20, 2022

Thanks for your quick response. I would like to open a pull request to fix this issue.

I have a question about the expected behavior.

When I specify the style like this:

w.SetRow("A1", []interface{}{excelize.Cell{StyleID: 0, Value: "value1"}}, excelize.RowOpts{StyleID: styleID})

The style id of A1 should be:

  1. overridden by 0
  2. still use styleID in excelize.RowOpts?

My understanding is that the first is the expected behavior, which the developers could unset the cell style.

@xuri
Copy link
Member

xuri commented Sep 20, 2022

Yep, the cell style should be overridden by 0 in this case, the cell style priority is hight than the rows.

@xuri xuri linked a pull request Sep 20, 2022 that will close this issue
10 tasks
@xuri xuri added this to Bugfix in v2.7.0 Sep 20, 2022
xuri pushed a commit that referenced this issue Sep 20, 2022
…ch cell (#1355)

Co-authored-by: Tianzhi Jin <tianzhi.jin@iglooinsure.com>
xuri pushed a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
…for each cell (qax-os#1355)

Co-authored-by: Tianzhi Jin <tianzhi.jin@iglooinsure.com>
xuri pushed a commit to JDavidVR/excelize that referenced this issue Jul 11, 2023
…for each cell (qax-os#1355)

Co-authored-by: Tianzhi Jin <tianzhi.jin@iglooinsure.com>
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
…for each cell (qax-os#1355)

Co-authored-by: Tianzhi Jin <tianzhi.jin@iglooinsure.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
No open projects
v2.7.0
Bugfix
Development

Successfully merging a pull request may close this issue.

2 participants