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

Empty columns within the source data range of the pivot table, Excel cannot be opened after setting the pivot table #1945

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

Comments

@ShowerBandV
Copy link
Contributor

Description
There are empty columns within the source data range of the pivot table. After setting the pivot table, Excel cannot be opened. After decompressing the Excel file, it was found that the empty cacheField field in pivotCacheDefinition.xml was the cause. Reading the code reveals that it is empty because pc.CacheFields.CacheField.Name directly reads the cell value as empty. Should pc.CacheFields.CacheField.Name be given a default value when the cell value is empty, for example, in the source data of A1~E20, column C is a blank column, and pcCacheFieldsCacheFieldName defaults to column C instead of an empty string

func (f *File) getTableFieldsOrder(opts *PivotTableOptions) ([]string, error) {
	var order []string
	if err := f.getPivotTableDataRange(opts); err != nil {
		return order, err
	}
	dataSheet, coordinates, err := f.adjustRange(opts.pivotDataRange)
	if err != nil {
		return order, newPivotTableDataRangeError(err.Error())
	}
	for col := coordinates[0]; col <= coordinates[2]; col++ {
                //here
		coordinate, _ := CoordinatesToCellName(col, coordinates[1])
		name, err := f.GetCellValue(dataSheet, coordinate)
		if err != nil {
			return order, err
		}
		order = append(order, name)
	}
	return order, nil
}
@xuri xuri closed this as completed in 9c27836 Jul 13, 2024
@xuri
Copy link
Member

xuri commented Jul 13, 2024

Thanks for your issue. Excel does't allow column header cell is empty in pivot table data range. I added check in the AddPivotTable function, now it will be return an error for this. Please upgrade to the master branch, and this patch will be released in the next version.

zhangyimingdatiancai pushed a commit to zhangyimingdatiancai/excelize that referenced this issue Aug 6, 2024
…l is empty in pivot table data range

- Update unit tests
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: Features
Development

No branches or pull requests

2 participants