2023-01-02 11:47:31 +08:00
|
|
|
// Copyright 2016 - 2023 The excelize Authors. All rights reserved. Use of
|
2019-09-05 23:42:40 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
2022-02-17 00:09:11 +08:00
|
|
|
// Package excelize providing a set of functions that allow you to write to and
|
|
|
|
// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
|
|
|
|
// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
|
|
|
|
// Supports complex components by high compatibility, and provided streaming
|
|
|
|
// API for generating or reading data from a worksheet with huge amounts of
|
2023-01-02 11:47:31 +08:00
|
|
|
// data. This library needs Go version 1.16 or later.
|
2019-09-05 23:42:40 +08:00
|
|
|
|
|
|
|
package excelize
|
|
|
|
|
|
|
|
import "encoding/xml"
|
|
|
|
|
|
|
|
// xlsxPivotTableDefinition represents the PivotTable root element for
|
|
|
|
// non-null PivotTables. There exists one pivotTableDefinition for each
|
|
|
|
// PivotTableDefinition part
|
|
|
|
type xlsxPivotTableDefinition struct {
|
2019-09-16 01:17:35 +08:00
|
|
|
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main pivotTableDefinition"`
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
CacheID int `xml:"cacheId,attr"`
|
|
|
|
ApplyNumberFormats bool `xml:"applyNumberFormats,attr,omitempty"`
|
|
|
|
ApplyBorderFormats bool `xml:"applyBorderFormats,attr,omitempty"`
|
|
|
|
ApplyFontFormats bool `xml:"applyFontFormats,attr,omitempty"`
|
|
|
|
ApplyPatternFormats bool `xml:"applyPatternFormats,attr,omitempty"`
|
|
|
|
ApplyAlignmentFormats bool `xml:"applyAlignmentFormats,attr,omitempty"`
|
|
|
|
ApplyWidthHeightFormats bool `xml:"applyWidthHeightFormats,attr,omitempty"`
|
|
|
|
DataOnRows bool `xml:"dataOnRows,attr,omitempty"`
|
|
|
|
DataPosition int `xml:"dataPosition,attr,omitempty"`
|
|
|
|
DataCaption string `xml:"dataCaption,attr"`
|
|
|
|
GrandTotalCaption string `xml:"grandTotalCaption,attr,omitempty"`
|
|
|
|
ErrorCaption string `xml:"errorCaption,attr,omitempty"`
|
2021-03-13 13:22:28 +08:00
|
|
|
ShowError *bool `xml:"showError,attr"`
|
2019-09-16 01:17:35 +08:00
|
|
|
MissingCaption string `xml:"missingCaption,attr,omitempty"`
|
|
|
|
ShowMissing bool `xml:"showMissing,attr,omitempty"`
|
|
|
|
PageStyle string `xml:"pageStyle,attr,omitempty"`
|
|
|
|
PivotTableStyle string `xml:"pivotTableStyle,attr,omitempty"`
|
|
|
|
VacatedStyle string `xml:"vacatedStyle,attr,omitempty"`
|
|
|
|
Tag string `xml:"tag,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
UpdatedVersion int `xml:"updatedVersion,attr,omitempty"`
|
|
|
|
MinRefreshableVersion int `xml:"minRefreshableVersion,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
AsteriskTotals bool `xml:"asteriskTotals,attr,omitempty"`
|
|
|
|
ShowItems bool `xml:"showItems,attr,omitempty"`
|
|
|
|
EditData bool `xml:"editData,attr,omitempty"`
|
|
|
|
DisableFieldList bool `xml:"disableFieldList,attr,omitempty"`
|
|
|
|
ShowCalcMbrs bool `xml:"showCalcMbrs,attr,omitempty"`
|
|
|
|
VisualTotals bool `xml:"visualTotals,attr,omitempty"`
|
|
|
|
ShowMultipleLabel bool `xml:"showMultipleLabel,attr,omitempty"`
|
|
|
|
ShowDataDropDown bool `xml:"showDataDropDown,attr,omitempty"`
|
2021-03-13 13:22:28 +08:00
|
|
|
ShowDrill *bool `xml:"showDrill,attr"`
|
2019-09-16 01:17:35 +08:00
|
|
|
PrintDrill bool `xml:"printDrill,attr,omitempty"`
|
|
|
|
ShowMemberPropertyTips bool `xml:"showMemberPropertyTips,attr,omitempty"`
|
|
|
|
ShowDataTips bool `xml:"showDataTips,attr,omitempty"`
|
|
|
|
EnableWizard bool `xml:"enableWizard,attr,omitempty"`
|
|
|
|
EnableDrill bool `xml:"enableDrill,attr,omitempty"`
|
|
|
|
EnableFieldProperties bool `xml:"enableFieldProperties,attr,omitempty"`
|
|
|
|
PreserveFormatting bool `xml:"preserveFormatting,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
UseAutoFormatting *bool `xml:"useAutoFormatting,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
PageWrap int `xml:"pageWrap,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
PageOverThenDown *bool `xml:"pageOverThenDown,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
SubtotalHiddenItems bool `xml:"subtotalHiddenItems,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
RowGrandTotals *bool `xml:"rowGrandTotals,attr,omitempty"`
|
|
|
|
ColGrandTotals *bool `xml:"colGrandTotals,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
FieldPrintTitles bool `xml:"fieldPrintTitles,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
ItemPrintTitles bool `xml:"itemPrintTitles,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
MergeItem *bool `xml:"mergeItem,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
ShowDropZones bool `xml:"showDropZones,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
CreatedVersion int `xml:"createdVersion,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
Indent int `xml:"indent,attr,omitempty"`
|
|
|
|
ShowEmptyRow bool `xml:"showEmptyRow,attr,omitempty"`
|
|
|
|
ShowEmptyCol bool `xml:"showEmptyCol,attr,omitempty"`
|
|
|
|
ShowHeaders bool `xml:"showHeaders,attr,omitempty"`
|
2021-10-11 00:08:45 +08:00
|
|
|
Compact *bool `xml:"compact,attr"`
|
|
|
|
Outline *bool `xml:"outline,attr"`
|
2019-09-16 01:17:35 +08:00
|
|
|
OutlineData bool `xml:"outlineData,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
CompactData *bool `xml:"compactData,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
Published bool `xml:"published,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
GridDropZones bool `xml:"gridDropZones,attr,omitempty"`
|
2019-09-16 01:17:35 +08:00
|
|
|
Immersive bool `xml:"immersive,attr,omitempty"`
|
|
|
|
MultipleFieldFilters bool `xml:"multipleFieldFilters,attr,omitempty"`
|
|
|
|
ChartFormat int `xml:"chartFormat,attr,omitempty"`
|
|
|
|
RowHeaderCaption string `xml:"rowHeaderCaption,attr,omitempty"`
|
|
|
|
ColHeaderCaption string `xml:"colHeaderCaption,attr,omitempty"`
|
|
|
|
FieldListSortAscending bool `xml:"fieldListSortAscending,attr,omitempty"`
|
|
|
|
MdxSubqueries bool `xml:"mdxSubqueries,attr,omitempty"`
|
|
|
|
CustomListSort bool `xml:"customListSort,attr,omitempty"`
|
|
|
|
Location *xlsxLocation `xml:"location"`
|
|
|
|
PivotFields *xlsxPivotFields `xml:"pivotFields"`
|
|
|
|
RowFields *xlsxRowFields `xml:"rowFields"`
|
|
|
|
RowItems *xlsxRowItems `xml:"rowItems"`
|
|
|
|
ColFields *xlsxColFields `xml:"colFields"`
|
|
|
|
ColItems *xlsxColItems `xml:"colItems"`
|
|
|
|
PageFields *xlsxPageFields `xml:"pageFields"`
|
|
|
|
DataFields *xlsxDataFields `xml:"dataFields"`
|
|
|
|
ConditionalFormats *xlsxConditionalFormats `xml:"conditionalFormats"`
|
|
|
|
PivotTableStyleInfo *xlsxPivotTableStyleInfo `xml:"pivotTableStyleInfo"`
|
2019-09-05 23:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxLocation represents location information for the PivotTable.
|
|
|
|
type xlsxLocation struct {
|
|
|
|
Ref string `xml:"ref,attr"`
|
|
|
|
FirstHeaderRow int `xml:"firstHeaderRow,attr"`
|
|
|
|
FirstDataRow int `xml:"firstDataRow,attr"`
|
|
|
|
FirstDataCol int `xml:"firstDataCol,attr"`
|
2019-09-20 00:20:30 +08:00
|
|
|
RowPageCount int `xml:"rowPageCount,attr,omitempty"`
|
|
|
|
ColPageCount int `xml:"colPageCount,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxPivotFields represents the collection of fields that appear on the
|
|
|
|
// PivotTable.
|
|
|
|
type xlsxPivotFields struct {
|
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
PivotField []*xlsxPivotField `xml:"pivotField"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxPivotField represents a single field in the PivotTable. This element
|
|
|
|
// contains information about the field, including the collection of items in
|
|
|
|
// the field.
|
|
|
|
type xlsxPivotField struct {
|
2019-09-20 00:20:30 +08:00
|
|
|
Name string `xml:"name,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
Axis string `xml:"axis,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
DataField bool `xml:"dataField,attr,omitempty"`
|
|
|
|
SubtotalCaption string `xml:"subtotalCaption,attr,omitempty"`
|
|
|
|
ShowDropDowns bool `xml:"showDropDowns,attr,omitempty"`
|
|
|
|
HiddenLevel bool `xml:"hiddenLevel,attr,omitempty"`
|
|
|
|
UniqueMemberProperty string `xml:"uniqueMemberProperty,attr,omitempty"`
|
2021-10-11 00:08:45 +08:00
|
|
|
Compact *bool `xml:"compact,attr"`
|
2019-09-20 00:20:30 +08:00
|
|
|
AllDrilled bool `xml:"allDrilled,attr,omitempty"`
|
2019-10-16 01:03:29 +08:00
|
|
|
NumFmtID string `xml:"numFmtId,attr,omitempty"`
|
2021-10-11 00:08:45 +08:00
|
|
|
Outline *bool `xml:"outline,attr"`
|
2019-09-20 00:20:30 +08:00
|
|
|
SubtotalTop bool `xml:"subtotalTop,attr,omitempty"`
|
|
|
|
DragToRow bool `xml:"dragToRow,attr,omitempty"`
|
|
|
|
DragToCol bool `xml:"dragToCol,attr,omitempty"`
|
|
|
|
MultipleItemSelectionAllowed bool `xml:"multipleItemSelectionAllowed,attr,omitempty"`
|
|
|
|
DragToPage bool `xml:"dragToPage,attr,omitempty"`
|
|
|
|
DragToData bool `xml:"dragToData,attr,omitempty"`
|
|
|
|
DragOff bool `xml:"dragOff,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
ShowAll bool `xml:"showAll,attr"`
|
2019-09-20 00:20:30 +08:00
|
|
|
InsertBlankRow bool `xml:"insertBlankRow,attr,omitempty"`
|
|
|
|
ServerField bool `xml:"serverField,attr,omitempty"`
|
|
|
|
InsertPageBreak bool `xml:"insertPageBreak,attr,omitempty"`
|
|
|
|
AutoShow bool `xml:"autoShow,attr,omitempty"`
|
|
|
|
TopAutoShow bool `xml:"topAutoShow,attr,omitempty"`
|
|
|
|
HideNewItems bool `xml:"hideNewItems,attr,omitempty"`
|
|
|
|
MeasureFilter bool `xml:"measureFilter,attr,omitempty"`
|
|
|
|
IncludeNewItemsInFilter bool `xml:"includeNewItemsInFilter,attr,omitempty"`
|
|
|
|
ItemPageCount int `xml:"itemPageCount,attr,omitempty"`
|
|
|
|
SortType string `xml:"sortType,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
DataSourceSort bool `xml:"dataSourceSort,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
NonAutoSortDefault bool `xml:"nonAutoSortDefault,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
RankBy int `xml:"rankBy,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
DefaultSubtotal *bool `xml:"defaultSubtotal,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
SumSubtotal bool `xml:"sumSubtotal,attr,omitempty"`
|
|
|
|
CountASubtotal bool `xml:"countASubtotal,attr,omitempty"`
|
|
|
|
AvgSubtotal bool `xml:"avgSubtotal,attr,omitempty"`
|
|
|
|
MaxSubtotal bool `xml:"maxSubtotal,attr,omitempty"`
|
|
|
|
MinSubtotal bool `xml:"minSubtotal,attr,omitempty"`
|
|
|
|
ProductSubtotal bool `xml:"productSubtotal,attr,omitempty"`
|
|
|
|
CountSubtotal bool `xml:"countSubtotal,attr,omitempty"`
|
|
|
|
StdDevSubtotal bool `xml:"stdDevSubtotal,attr,omitempty"`
|
|
|
|
StdDevPSubtotal bool `xml:"stdDevPSubtotal,attr,omitempty"`
|
|
|
|
VarSubtotal bool `xml:"varSubtotal,attr,omitempty"`
|
|
|
|
VarPSubtotal bool `xml:"varPSubtotal,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
ShowPropCell bool `xml:"showPropCell,attr,omitempty"`
|
|
|
|
ShowPropTip bool `xml:"showPropTip,attr,omitempty"`
|
|
|
|
ShowPropAsCaption bool `xml:"showPropAsCaption,attr,omitempty"`
|
|
|
|
DefaultAttributeDrillState bool `xml:"defaultAttributeDrillState,attr,omitempty"`
|
|
|
|
Items *xlsxItems `xml:"items"`
|
|
|
|
AutoSortScope *xlsxAutoSortScope `xml:"autoSortScope"`
|
|
|
|
ExtLst *xlsxExtLst `xml:"extLst"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxItems represents the collection of items in a PivotTable field. The
|
|
|
|
// items in the collection are ordered by index. Items represent the unique
|
|
|
|
// entries from the field in the source data.
|
|
|
|
type xlsxItems struct {
|
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
Item []*xlsxItem `xml:"item"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxItem represents a single item in PivotTable field.
|
|
|
|
type xlsxItem struct {
|
2019-09-20 00:20:30 +08:00
|
|
|
N string `xml:"n,attr,omitempty"`
|
|
|
|
T string `xml:"t,attr,omitempty"`
|
|
|
|
H bool `xml:"h,attr,omitempty"`
|
|
|
|
S bool `xml:"s,attr,omitempty"`
|
|
|
|
SD bool `xml:"sd,attr,omitempty"`
|
|
|
|
F bool `xml:"f,attr,omitempty"`
|
|
|
|
M bool `xml:"m,attr,omitempty"`
|
|
|
|
C bool `xml:"c,attr,omitempty"`
|
2020-09-11 00:45:52 +08:00
|
|
|
X *int `xml:"x,attr,omitempty"`
|
2019-09-20 00:20:30 +08:00
|
|
|
D bool `xml:"d,attr,omitempty"`
|
|
|
|
E bool `xml:"e,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxAutoSortScope represents the sorting scope for the PivotTable.
|
2022-01-23 00:32:34 +08:00
|
|
|
type xlsxAutoSortScope struct{}
|
2019-09-05 23:42:40 +08:00
|
|
|
|
|
|
|
// xlsxRowFields represents the collection of row fields for the PivotTable.
|
|
|
|
type xlsxRowFields struct {
|
2019-09-20 00:20:30 +08:00
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
Field []*xlsxField `xml:"field"`
|
2019-09-05 23:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxField represents a generic field that can appear either on the column
|
|
|
|
// or the row region of the PivotTable. There areas many <x> elements as there
|
|
|
|
// are item values in any particular column or row.
|
|
|
|
type xlsxField struct {
|
|
|
|
X int `xml:"x,attr"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxRowItems represents the collection of items in row axis of the
|
|
|
|
// PivotTable.
|
|
|
|
type xlsxRowItems struct {
|
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
I []*xlsxI `xml:"i"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxI represents the collection of items in the row region of the
|
|
|
|
// PivotTable.
|
|
|
|
type xlsxI struct {
|
|
|
|
X []*xlsxX `xml:"x"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxX represents an array of indexes to cached shared item values.
|
2022-01-23 00:32:34 +08:00
|
|
|
type xlsxX struct{}
|
2019-09-05 23:42:40 +08:00
|
|
|
|
|
|
|
// xlsxColFields represents the collection of fields that are on the column
|
|
|
|
// axis of the PivotTable.
|
|
|
|
type xlsxColFields struct {
|
2019-09-20 00:20:30 +08:00
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
Field []*xlsxField `xml:"field"`
|
2019-09-05 23:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxColItems represents the collection of column items of the PivotTable.
|
|
|
|
type xlsxColItems struct {
|
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
I []*xlsxI `xml:"i"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxPageFields represents the collection of items in the page or report
|
|
|
|
// filter region of the PivotTable.
|
|
|
|
type xlsxPageFields struct {
|
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
PageField []*xlsxPageField `xml:"pageField"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxPageField represents a field on the page or report filter of the
|
|
|
|
// PivotTable.
|
|
|
|
type xlsxPageField struct {
|
|
|
|
Fld int `xml:"fld,attr"`
|
|
|
|
Item int `xml:"item,attr,omitempty"`
|
2020-04-09 01:00:14 +08:00
|
|
|
Hier int `xml:"hier,attr,omitempty"`
|
|
|
|
Name string `xml:"name,attr,omitempty"`
|
|
|
|
Cap string `xml:"cap,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
ExtLst *xlsxExtLst `xml:"extLst"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxDataFields represents the collection of items in the data region of the
|
|
|
|
// PivotTable.
|
|
|
|
type xlsxDataFields struct {
|
2019-09-20 00:20:30 +08:00
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
DataField []*xlsxDataField `xml:"dataField"`
|
2019-09-05 23:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxDataField represents a field from a source list, table, or database
|
|
|
|
// that contains data that is summarized in a PivotTable.
|
|
|
|
type xlsxDataField struct {
|
|
|
|
Name string `xml:"name,attr,omitempty"`
|
|
|
|
Fld int `xml:"fld,attr"`
|
2019-09-20 00:20:30 +08:00
|
|
|
Subtotal string `xml:"subtotal,attr,omitempty"`
|
|
|
|
ShowDataAs string `xml:"showDataAs,attr,omitempty"`
|
|
|
|
BaseField int `xml:"baseField,attr,omitempty"`
|
|
|
|
BaseItem int64 `xml:"baseItem,attr,omitempty"`
|
2019-10-16 01:03:29 +08:00
|
|
|
NumFmtID string `xml:"numFmtId,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
ExtLst *xlsxExtLst `xml:"extLst"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxConditionalFormats represents the collection of conditional formats
|
|
|
|
// applied to a PivotTable.
|
2022-01-23 00:32:34 +08:00
|
|
|
type xlsxConditionalFormats struct{}
|
2019-09-05 23:42:40 +08:00
|
|
|
|
|
|
|
// xlsxPivotTableStyleInfo represent information on style applied to the
|
|
|
|
// PivotTable.
|
|
|
|
type xlsxPivotTableStyleInfo struct {
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
ShowRowHeaders bool `xml:"showRowHeaders,attr"`
|
|
|
|
ShowColHeaders bool `xml:"showColHeaders,attr"`
|
2019-09-20 00:20:30 +08:00
|
|
|
ShowRowStripes bool `xml:"showRowStripes,attr,omitempty"`
|
|
|
|
ShowColStripes bool `xml:"showColStripes,attr,omitempty"`
|
2019-09-05 23:42:40 +08:00
|
|
|
ShowLastColumn bool `xml:"showLastColumn,attr,omitempty"`
|
|
|
|
}
|