This closes #804, fixes can't add timelines and slicers for a pivot table in generated spreadsheet

formula
xuri 4 years ago
parent 2350866d46
commit 9af00b9b98
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -70,7 +70,8 @@ type PivotTableField struct {
} }
// AddPivotTable provides the method to add pivot table by given pivot table // AddPivotTable provides the method to add pivot table by given pivot table
// options. // options. Note that the same fields can not in Columns, Rows and Filter
// fields at the same time.
// //
// For example, create a pivot table on the Sheet1!$G$2:$M$34 area with the // For example, create a pivot table on the Sheet1!$G$2:$M$34 area with the
// region Sheet1!$A$1:$E$31 as the data source, summarize by sum for sales: // region Sheet1!$A$1:$E$31 as the data source, summarize by sum for sales:
@ -243,8 +244,11 @@ func (f *File) addPivotCache(pivotCacheID int, pivotCacheXML string, opt *PivotT
hcell, _ := CoordinatesToCellName(coordinates[0], coordinates[1]) hcell, _ := CoordinatesToCellName(coordinates[0], coordinates[1])
vcell, _ := CoordinatesToCellName(coordinates[2], coordinates[3]) vcell, _ := CoordinatesToCellName(coordinates[2], coordinates[3])
pc := xlsxPivotCacheDefinition{ pc := xlsxPivotCacheDefinition{
SaveData: false, SaveData: false,
RefreshOnLoad: true, RefreshOnLoad: true,
CreatedVersion: pivotTableVersion,
RefreshedVersion: pivotTableVersion,
MinRefreshableVersion: pivotTableVersion,
CacheSource: &xlsxCacheSource{ CacheSource: &xlsxCacheSource{
Type: "worksheet", Type: "worksheet",
WorksheetSource: &xlsxWorksheetSource{ WorksheetSource: &xlsxWorksheetSource{
@ -300,17 +304,20 @@ func (f *File) addPivotTable(cacheID, pivotTableID int, pivotTableXML string, op
return opt.PivotTableStyleName return opt.PivotTableStyleName
} }
pt := xlsxPivotTableDefinition{ pt := xlsxPivotTableDefinition{
Name: fmt.Sprintf("Pivot Table%d", pivotTableID), Name: fmt.Sprintf("Pivot Table%d", pivotTableID),
CacheID: cacheID, CacheID: cacheID,
RowGrandTotals: &opt.RowGrandTotals, RowGrandTotals: &opt.RowGrandTotals,
ColGrandTotals: &opt.ColGrandTotals, ColGrandTotals: &opt.ColGrandTotals,
ShowDrill: &opt.ShowDrill, UpdatedVersion: pivotTableVersion,
UseAutoFormatting: &opt.UseAutoFormatting, MinRefreshableVersion: pivotTableVersion,
PageOverThenDown: &opt.PageOverThenDown, ShowDrill: &opt.ShowDrill,
MergeItem: &opt.MergeItem, UseAutoFormatting: &opt.UseAutoFormatting,
CompactData: &opt.CompactData, PageOverThenDown: &opt.PageOverThenDown,
ShowError: &opt.ShowError, MergeItem: &opt.MergeItem,
DataCaption: "Values", CreatedVersion: pivotTableVersion,
CompactData: &opt.CompactData,
ShowError: &opt.ShowError,
DataCaption: "Values",
Location: &xlsxLocation{ Location: &xlsxLocation{
Ref: hcell + ":" + vcell, Ref: hcell + ":" + vcell,
FirstDataCol: 1, FirstDataCol: 1,

@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of // Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
// this source code is governed by a BSD-style license that can be found in // this source code is governed by a BSD-style license that can be found in
// the LICENSE file. // the LICENSE file.
// //
@ -100,6 +100,11 @@ const (
TotalColumns = 16384 TotalColumns = 16384
TotalSheetHyperlinks = 65529 TotalSheetHyperlinks = 65529
TotalCellChars = 32767 TotalCellChars = 32767
// pivotTableVersion should be greater than 3. One or more of the
// PivotTables chosen are created in a version of Excel earlier than
// Excel 2007 or in compatibility mode. Slicer can only be used with
// PivotTables created in Excel 2007 or a newer version of Excel.
pivotTableVersion = 3
) )
var supportImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png", ".tif": ".tiff", ".tiff": ".tiff"} var supportImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png", ".tif": ".tiff", ".tiff": ".tiff"}

Loading…
Cancel
Save