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

setRowStyle function not working #1129

Closed
eduardo-mior opened this issue Jan 24, 2022 · 10 comments
Closed

setRowStyle function not working #1129

eduardo-mior opened this issue Jan 24, 2022 · 10 comments

Comments

@eduardo-mior
Copy link

eduardo-mior commented Jan 24, 2022

Description
setRowStyle function not working.

I need to define the style of a line but this is not working in Excel and GoogleSheets, interestingly in LibreOffice Calcs it works.

Code example:

xlsx.SetSheetName("Sheet1", "Report")

titleStyle, err := xlsx.NewStyle(&excelize.Style{
	Font: &excelize.Font{
		Bold: true,
		Size: 20,
	},
	Alignment: &excelize.Alignment{
		Vertical: "center",
	},
})
if err != nil {
	return "", nil, err
}

if err := xlsx.SetCellValue("Report", "A1", "Customers Report"); err != nil {
	return "", nil, err
}

if err := xlsx.SetRowStyle("Report", 1, 1, titleStyle); err != nil {
	return "", nil, err
}

if err := xlsx.SetRowHeight("Report", 1, 30); err != nil {
	return "", nil, err
}

if err := xlsx.MergeCell("Report", "A1", "Z1"); err != nil {
	return "", nil, err
}

xlsx.SaveAs("teste.xlsx")

Describe the results you received:
GoogleSheets and Excel:
image

Describe the results you expected:
LibreOffice:
image

Output of go version:

go version go1.17.3

Excelize version or commit ID: 2.5.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):
MacOS Catalina AND Linux Zorion OS
GoogleSheets (online), Libre Office (linux), Excel 2021 (macos from app store)

@xuri
Copy link
Member

xuri commented Jan 25, 2022

Thanks for your issue. Please set the style for the cells in the merged range like this:

err := xlsx.SetCellStyle("Report", "A1", "Z1", titleStyle)

@eduardo-mior
Copy link
Author

Many thanks for the reply.

@xuri xuri closed this as completed Jan 27, 2022
@eduardo-mior
Copy link
Author

Do you plan to resolve this issue in a future release? I noticed that you closed the issue but didn't leave any other comments.

xuri added a commit that referenced this issue Jan 27, 2022
Correct cells style in merge range
Fix incorrect style ID returned on getting cell style in some cases
Unit test updated and simplified code
@xuri
Copy link
Member

xuri commented Jan 27, 2022

I have fixed it, please upgrade to the master branch code, and this patch will be released in the next version.

@kukaki
Copy link

kukaki commented Feb 24, 2022

@xuri

SetRowStyle is not replacing the style of a cell (part of the row) which was previously set using SetCellStyle.

For eg. Let's say I have set style to column A using SetColStyle. Now if I set style to row 1 using SetRowStyle, the row style is applied to entire row 1 except cell A1 (col style prevailing here).

i.e. SetRowStyle is setting style to only the cells which do not have a previous style.

It is not intended, right?

xuri added a commit that referenced this issue May 1, 2022
Ref #1129, make `SetRowStyle` overwrite style of the cells
@xuri
Copy link
Member

xuri commented May 1, 2022

Hi @kukaki, sorry for my late reply, I have made the SetRowStyle overwrite style of the cells on commit 773d4af, please upgrade to the master branch code, and this patch will be released in the next version.

@xuri
Copy link
Member

xuri commented May 1, 2022

Hi @eduardo-mior, I also notice that according to the benchmark report of v2.6.0, this fix (commit: 156bf6d) slows down set sheet row and the merging cell about 400 times.

xuri added a commit that referenced this issue May 2, 2022
…ce, and 1904 date system support

- Fix incorrect cell data types casting results when number formatting
- Support set cell value on 1904 date system enabled, ref #1212
- Improve performance for set sheet row and the merging cells, fix performance impact when resolving #1129
@xuri
Copy link
Member

xuri commented May 2, 2022

Hi @eduardo-mior, I have improved performance for the set sheet row and the merging cells on commit eed431e, fixed performance impact when resolving this issue, and this patch will be released in the next version.

@michaelperel
Copy link

@xuri I am not sure if this is the same issue (I recently started using the library), however:

In the latest v2 release, when I set a row style for 1 row, and then write data into row 2, 3, 4 and so on, the style from row 1 is applied to all rows. I would expect the style to only apply to row 1, not subsequent rows.

In master (commit: eed431e), the behavior is as I would have expected - If I set the style for row 1 and then write row 2, the style from row 1 does not apply to row 2.

So that is to say, master is working great for me!

@xuri
Copy link
Member

xuri commented May 5, 2022

@michaelperel, yep, this issue was caused by an incorrect row compare condition on cell style inheritance in commit 156bf6d.

xuri added a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
…tyle

Correct cells style in merge range
Fix incorrect style ID returned on getting cell style in some cases
Unit test updated and simplified code
xuri added a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
Ref qax-os#1129, make `SetRowStyle` overwrite style of the cells
xuri added a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
…formance, and 1904 date system support

- Fix incorrect cell data types casting results when number formatting
- Support set cell value on 1904 date system enabled, ref qax-os#1212
- Improve performance for set sheet row and the merging cells, fix performance impact when resolving qax-os#1129
xuri added a commit to JDavidVR/excelize that referenced this issue Jul 11, 2023
Ref qax-os#1129, make `SetRowStyle` overwrite style of the cells
xuri added a commit to JDavidVR/excelize that referenced this issue Jul 11, 2023
…formance, and 1904 date system support

- Fix incorrect cell data types casting results when number formatting
- Support set cell value on 1904 date system enabled, ref qax-os#1212
- Improve performance for set sheet row and the merging cells, fix performance impact when resolving qax-os#1129
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
…tyle

Correct cells style in merge range
Fix incorrect style ID returned on getting cell style in some cases
Unit test updated and simplified code
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
Ref qax-os#1129, make `SetRowStyle` overwrite style of the cells
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
…formance, and 1904 date system support

- Fix incorrect cell data types casting results when number formatting
- Support set cell value on 1904 date system enabled, ref qax-os#1212
- Improve performance for set sheet row and the merging cells, fix performance impact when resolving qax-os#1129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Bugfix
Development

No branches or pull requests

4 participants