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

Is there any way to change the style of pivot table by the mehod like SetColStyle? #1453

Open
Zncl2222 opened this issue Jan 18, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@Zncl2222
Copy link

Zncl2222 commented Jan 18, 2023

I'm trying to make a pivot table with custom style (not default style from excel). It seems SetColStyle("Sheet1", "H", style) can't style pivot table. Is there any way to fill color or change font color in any place of pivot table? Thanks for help !

ps. I tried to make custom style template from excel pivot table, but that function can only style some fixed place like 'title', 'sum row or col' etc. It's not enough for me. I prefer to adjust every cells by myself like SetColStyle("Sheet1", "H", style) feature.

@xuri
Copy link
Member

xuri commented Jan 18, 2023

Thanks for your issue. The library doesn't support set pivot table cell style currently. We need to implement pivot formats for this. Contributions are welcome. I'll certainly accept this feature patch if anybody did that.

@xuri xuri added the enhancement New feature or request label Jan 18, 2023
@eurosoll
Copy link

Hi

I am not sure if my issue is linked to this one.

I am trying to set conditional formatting on a column which has a pivot table in it.

The excel sheet creates the conditional formatting rule, but specifically excludes the cells in the pivot table. Is this normal behaviour?

I noticed that xlsxConditionalFormatting has a Pivot bool:

type xlsxConditionalFormatting struct {
XMLName xml.Name xml:"conditionalFormatting"
Pivot bool xml:"pivot,attr,omitempty"
SQRef string xml:"sqref,attr,omitempty"
CfRule []*xlsxCfRule xml:"cfRule"
}

If we cant use conditional formatting is there any other way to format these columns/cells?

TIA

@xuri
Copy link
Member

xuri commented Mar 22, 2023

That is exactly related to the same reason as this issue. Currently, the library doesn't support changing the cell style in the pivot table. We need to implement pivot formats for this.

@eurosoll
Copy link

Thanks for clarification.

I did a quick test and if the Pivot field is set to true then the conditional formatting does apply to the pivot table.

	ws.ConditionalFormatting = append(ws.ConditionalFormatting, &xlsxConditionalFormatting{
		Pivot:  true,
		SQRef:  area,
		CfRule: cfRule,
	})

Would it be possible to set that as standard as a quick fix?

@xuri
Copy link
Member

xuri commented Mar 22, 2023

Okay. Would you like to create a pull request to fix that?

@eurosoll
Copy link

Sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants