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

fix pivot fails in case of multi columns and multi data #710

Conversation

lbraconnier2
Copy link
Contributor

PR Details

The pivot generation fails when pivot has many colums and many data.
Please se details below.

Description

i'll try to generate this pivot :
image

The database is this one :

Month Year Type Sales Region
Jun 2017 Produce 4059 West
Jul 2018 Meat 456 East
Mar 2018 Beverages 89 East
Mar 2017 Dairy 3237 North
Dec 2017 Meat 1258 South
Aug 2018 Meat 2790 South
Feb 2017 Produce 1831 West
Sep 2017 Produce 1485 North
Feb 2018 Beverages 563 West
Apr 2018 Meat 1159 West
Oct 2018 Dairy 2199 East
Feb 2019 Beverages 4703 South
Dec 2017 Dairy 156 North
Sep 2019 Beverages 4783 North
Aug 2017 Beverages 4718 South
Jul 2018 Produce 2996 East
Apr 2017 Dairy 3133 West
Aug 2019 Produce 3891 North
Mar 2018 Beverages 4107 East
Aug 2017 Produce 2205 North
Oct 2018 Produce 4757 South
Mar 2018 Dairy 3590 East
Jul 2018 Produce 3582 East
Feb 2019 Dairy 4271 North
Mar 2018 Dairy 2079 North
Jul 2019 Beverages 4819 West
Jan 2017 Dairy 710 South
Feb 2019 Beverages 4384 South
Jan 2019 Meat 1532 East
Dec 2019 Beverages 2051 East

The code for this pivot is :

if err := f.AddPivotTable(&PivotTableOption{
		DataRange:       "Sheet1!$A$1:$E$31",
		PivotTableRange: "Sheet2!$A$56:$AG$90",
		Rows:            []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
		Columns:         []PivotTableField{{Data: "Region", DefaultSubtotal: true}, {Data: "Type"}},
		Data:            []PivotTableField{{Data: "Sales", Subtotal: "Sum", Name: "Sum of Sales"}, {Data: "Sales", Subtotal: "Average", Name: "Average of Sales"}},
		RowGrandTotals:  true,
		ColGrandTotals:  true,
		ShowDrill:       true,
		ShowRowHeaders:  true,
		ShowColHeaders:  true,
		ShowLastColumn:  true,
	}); err != nil {
		fmt.Println(err)
	}

but this won't generate proper pivot table and end up with pivot table removed in the generated excel.

After doing comparison of "\xl\pivotTables\pivotTable1.xml",
the one that is working(generated manually) got colFields generated like,

<colFields count="4">
		<field x="5"/>
		<field x="6"/>
		<field x="7"/>
		<field x="-2"/>		 
</colFields>

The one by exelize is :

<colFields count="3">
		<field x="5"/>
		<field x="6"/>
		<field x="7"/>	 
</colFields>

Related Issue

Motivation and Context

How Has This Been Tested

go test TestAddPivotTable

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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2020

Codecov Report

Merging #710 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #710   +/-   ##
=======================================
  Coverage   95.52%   95.53%           
=======================================
  Files          31       31           
  Lines        8386     8390    +4     
=======================================
+ Hits         8011     8015    +4     
  Misses        226      226           
  Partials      149      149           
Impacted Files Coverage Δ
pivotTable.go 98.77% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c492220...2bd359b. Read the comment docs.

@xuri xuri added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 1, 2020
@xuri xuri merged commit 9055a83 into qax-os:master Oct 1, 2020
@xuri
Copy link
Member

xuri commented Oct 1, 2020

LGTM, thanks @lbraconnier2.

jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this pull request Oct 22, 2023
…of-multi-columns-and-multi-data

fix pivot fails in case of multi columns and multi data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants