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
}