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

getPivotTable use wrong sheetName #1937

Closed
ShowerBandV opened this issue Jul 3, 2024 · 1 comment
Closed

getPivotTable use wrong sheetName #1937

ShowerBandV opened this issue Jul 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ShowerBandV
Copy link
Contributor

Description
Reading a cross sheet pivot table, it was found that the pivot table data source was obtained but not used, using the current sheetName

func (f *File) getPivotTable(sheet, pivotTableXML, pivotCacheRels string) (PivotTableOptions, error) {
	...
	opts = PivotTableOptions{
		pivotTableXML:   pivotTableXML,
		pivotCacheXML:   pivotCacheXML,
		pivotSheetName:  sheet,
                //sheet is currentsheet,but dataRange need pc.CacheSource.WorksheetSource.Sheet
		DataRange:       fmt.Sprintf("%s!%s", sheet, pc.CacheSource.WorksheetSource.Ref),
		PivotTableRange: fmt.Sprintf("%s!%s", sheet, pt.Location.Ref),
		Name:            pt.Name,
	}
	...
}

here is demo code and a xlsx file:

func TestGetPivotTable(t *testing.T) {
	file, err := excelize.OpenFile("Book1.xlsx")
	if err != nil {
		panic(err)
	}
	tables, err := file.GetPivotTables("Sheet2")
	if err != nil {
		panic(err)
	}
	fmt.Println(tables)
}

Book1.xlsx

@xuri
Copy link
Member

xuri commented Jul 5, 2024

Hi @ShowerBandV, thanks for your issue. Would you like to create a pull request to help us fix that?

@xuri xuri added the bug Something isn't working label Jul 5, 2024
ShowerBandV added a commit to ShowerBandV/excelize that referenced this issue Jul 5, 2024
@xuri xuri closed this as completed in 7999a49 Jul 6, 2024
zhangyimingdatiancai pushed a commit to zhangyimingdatiancai/excelize that referenced this issue Aug 6, 2024
…nge (qax-os#1941)

- Add unit test for get pivot table with across worksheet data range, update dependencies package and updated comments of the GetMergeCells function
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
Status: Bugfix
Development

No branches or pull requests

2 participants