From b30c642e2bf2a328cf087e03399b783e02e1e647 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 5 Sep 2019 23:42:40 +0800 Subject: Prepare pivot table support, add pivot table definition struct --- xmlPivotTable.go | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 xmlPivotTable.go (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go new file mode 100644 index 0000000..16c469f --- /dev/null +++ b/xmlPivotTable.go @@ -0,0 +1,289 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excelâ„¢ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.10 or later. + +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 { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main pivotTableDefinition"` + Name string `xml:"name,attr"` + CacheID int `xml:"cacheId,attr"` + DataOnRows bool `xml:"dataOnRows,attr"` + DataPosition int `xml:"dataPosition,attr"` + DataCaption string `xml:"dataCaption,attr"` + GrandTotalCaption string `xml:"grandTotalCaption,attr"` + ErrorCaption string `xml:"errorCaption,attr"` + ShowError bool `xml:"showError,attr"` + MissingCaption string `xml:"missingCaption,attr"` + ShowMissing bool `xml:"showMissing,attr"` + PageStyle string `xml:"pageStyle,attr"` + PivotTableStyle string `xml:"pivotTableStyle,attr"` + VacatedStyle string `xml:"vacatedStyle,attr"` + Tag string `xml:"tag,attr"` + UpdatedVersion int `xml:"updatedVersion,attr"` + MinRefreshableVersion int `xml:"minRefreshableVersion,attr"` + AsteriskTotals bool `xml:"asteriskTotals,attr"` + ShowItems bool `xml:"showItems,attr"` + EditData bool `xml:"editData,attr"` + DisableFieldList bool `xml:"disableFieldList,attr"` + ShowCalcMbrs bool `xml:"showCalcMbrs,attr"` + VisualTotals bool `xml:"visualTotals,attr"` + ShowMultipleLabel bool `xml:"showMultipleLabel,attr"` + ShowDataDropDown bool `xml:"showDataDropDown,attr"` + ShowDrill bool `xml:"showDrill,attr"` + PrintDrill bool `xml:"printDrill,attr"` + ShowMemberPropertyTips bool `xml:"showMemberPropertyTips,attr"` + ShowDataTips bool `xml:"showDataTips,attr"` + EnableWizard bool `xml:"enableWizard,attr"` + EnableDrill bool `xml:"enableDrill,attr"` + EnableFieldProperties bool `xml:"enableFieldProperties,attr"` + PreserveFormatting bool `xml:"preserveFormatting,attr"` + UseAutoFormatting bool `xml:"useAutoFormatting,attr"` + PageWrap int `xml:"pageWrap,attr"` + PageOverThenDown bool `xml:"pageOverThenDown,attr"` + SubtotalHiddenItems bool `xml:"subtotalHiddenItems,attr"` + RowGrandTotals bool `xml:"rowGrandTotals,attr"` + ColGrandTotals bool `xml:"colGrandTotals,attr"` + FieldPrintTitles bool `xml:"fieldPrintTitles,attr"` + ItemPrintTitles bool `xml:"itemPrintTitles,attr"` + MergeItem bool `xml:"mergeItem,attr"` + ShowDropZones bool `xml:"showDropZones,attr"` + CreatedVersion int `xml:"createdVersion,attr"` + Indent int `xml:"indent,attr"` + ShowEmptyRow bool `xml:"showEmptyRow,attr"` + ShowEmptyCol bool `xml:"showEmptyCol,attr"` + ShowHeaders bool `xml:"showHeaders,attr"` + Compact bool `xml:"compact,attr"` + Outline bool `xml:"outline,attr"` + OutlineData bool `xml:"outlineData,attr"` + CompactData bool `xml:"compactData,attr"` + Published bool `xml:"published,attr"` + GridDropZones bool `xml:"gridDropZones,attr"` + Immersive bool `xml:"immersive,attr"` + MultipleFieldFilters bool `xml:"multipleFieldFilters,attr"` + ChartFormat int `xml:"chartFormat,attr"` + RowHeaderCaption string `xml:"rowHeaderCaption,attr"` + ColHeaderCaption string `xml:"colHeaderCaption,attr"` + FieldListSortAscending bool `xml:"fieldListSortAscending,attr"` + MdxSubqueries bool `xml:"mdxSubqueries,attr"` + CustomListSort bool `xml:"customListSort,attr"` + 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"` +} + +// 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"` + RowPageCount int `xml:"rowPageCount,attr"` + ColPageCount int `xml:"colPageCount,attr"` +} + +// 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 { + Name string `xml:"name,attr"` + Axis string `xml:"axis,attr,omitempty"` + DataField bool `xml:"dataField,attr"` + SubtotalCaption string `xml:"subtotalCaption,attr"` + ShowDropDowns bool `xml:"showDropDowns,attr"` + HiddenLevel bool `xml:"hiddenLevel,attr"` + UniqueMemberProperty string `xml:"uniqueMemberProperty,attr"` + Compact bool `xml:"compact,attr"` + AllDrilled bool `xml:"allDrilled,attr"` + NumFmtId string `xml:"numFmtId,attr,omitempty"` + Outline bool `xml:"outline,attr"` + SubtotalTop bool `xml:"subtotalTop,attr"` + DragToRow bool `xml:"dragToRow,attr"` + DragToCol bool `xml:"dragToCol,attr"` + MultipleItemSelectionAllowed bool `xml:"multipleItemSelectionAllowed,attr"` + DragToPage bool `xml:"dragToPage,attr"` + DragToData bool `xml:"dragToData,attr"` + DragOff bool `xml:"dragOff,attr"` + ShowAll bool `xml:"showAll,attr"` + InsertBlankRow bool `xml:"insertBlankRow,attr"` + ServerField bool `xml:"serverField,attr"` + InsertPageBreak bool `xml:"insertPageBreak,attr"` + AutoShow bool `xml:"autoShow,attr"` + TopAutoShow bool `xml:"topAutoShow,attr"` + HideNewItems bool `xml:"hideNewItems,attr"` + MeasureFilter bool `xml:"measureFilter,attr"` + IncludeNewItemsInFilter bool `xml:"includeNewItemsInFilter,attr"` + ItemPageCount int `xml:"itemPageCount,attr"` + SortType string `xml:"sortType,attr"` + DataSourceSort bool `xml:"dataSourceSort,attr,omitempty"` + NonAutoSortDefault bool `xml:"nonAutoSortDefault,attr"` + RankBy int `xml:"rankBy,attr,omitempty"` + DefaultSubtotal bool `xml:"defaultSubtotal,attr"` + SumSubtotal bool `xml:"sumSubtotal,attr"` + CountASubtotal bool `xml:"countASubtotal,attr"` + AvgSubtotal bool `xml:"avgSubtotal,attr"` + MaxSubtotal bool `xml:"maxSubtotal,attr"` + MinSubtotal bool `xml:"minSubtotal,attr"` + ProductSubtotal bool `xml:"productSubtotal,attr"` + CountSubtotal bool `xml:"countSubtotal,attr"` + StdDevSubtotal bool `xml:"stdDevSubtotal,attr"` + StdDevPSubtotal bool `xml:"stdDevPSubtotal,attr"` + VarSubtotal bool `xml:"varSubtotal,attr"` + VarPSubtotal bool `xml:"varPSubtotal,attr"` + 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 { + N string `xml:"n,attr"` + T string `xml:"t,attr"` + H bool `xml:"h,attr"` + S bool `xml:"s,attr"` + SD bool `xml:"sd,attr"` + F bool `xml:"f,attr"` + M bool `xml:"m,attr"` + C bool `xml:"c,attr"` + X int `xml:"x,attr,omitempty"` + D bool `xml:"d,attr"` + E bool `xml:"e,attr"` +} + +// xlsxAutoSortScope represents the sorting scope for the PivotTable. +type xlsxAutoSortScope struct { +} + +// xlsxRowFields represents the collection of row fields for the PivotTable. +type xlsxRowFields struct { + Count int `xml:"count,attr"` + Fields []*xlsxField `xml:"fields"` +} + +// xlsxField represents a generic field that can appear either on the column +// or the row region of the PivotTable. There areas many 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. +type xlsxX struct { + XMLName xml.Name `xml:"x"` +} + +// xlsxColFields represents the collection of fields that are on the column +// axis of the PivotTable. +type xlsxColFields struct { + Count int `xml:"count,attr"` + Fields []*xlsxField `xml:"fields"` +} + +// 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"` + Hier int `xml:"hier,attr"` + Name string `xml:"name,attr"` + Cap string `xml:"cap,attr"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxDataFields represents the collection of items in the data region of the +// PivotTable. +type xlsxDataFields struct { + Count int `xml:"count,attr"` + DataField *xlsxDataField `xml:"dataField"` +} + +// 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"` + Subtotal string `xml:"subtotal,attr"` + ShowDataAs string `xml:"showDataAs,attr"` + BaseField int `xml:"baseField,attr"` + BaseItem int64 `xml:"baseItem,attr"` + NumFmtId string `xml:"numFmtId,attr,omitempty"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxConditionalFormats represents the collection of conditional formats +// applied to a PivotTable. +type xlsxConditionalFormats struct { +} + +// 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"` + ShowRowStripes bool `xml:"showRowStripes,attr"` + ShowColStripes bool `xml:"showColStripes,attr"` + ShowLastColumn bool `xml:"showLastColumn,attr,omitempty"` +} -- cgit v1.2.1 From 8922f659788187afa6d0a5d3248e999c2c1bb846 Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 16 Sep 2019 01:17:35 +0800 Subject: Combine functions: workBookRelsWriter, drawingRelsWriter into relsWriter; drawingRelsReader, workbookRelsReader, workSheetRelsReader into relsReader; addDrawingRelationships, addSheetRelationships into addRels --- xmlPivotTable.go | 150 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 78 insertions(+), 72 deletions(-) (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go index 16c469f..6f2a8e7 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -15,78 +15,84 @@ import "encoding/xml" // non-null PivotTables. There exists one pivotTableDefinition for each // PivotTableDefinition part type xlsxPivotTableDefinition struct { - XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main pivotTableDefinition"` - Name string `xml:"name,attr"` - CacheID int `xml:"cacheId,attr"` - DataOnRows bool `xml:"dataOnRows,attr"` - DataPosition int `xml:"dataPosition,attr"` - DataCaption string `xml:"dataCaption,attr"` - GrandTotalCaption string `xml:"grandTotalCaption,attr"` - ErrorCaption string `xml:"errorCaption,attr"` - ShowError bool `xml:"showError,attr"` - MissingCaption string `xml:"missingCaption,attr"` - ShowMissing bool `xml:"showMissing,attr"` - PageStyle string `xml:"pageStyle,attr"` - PivotTableStyle string `xml:"pivotTableStyle,attr"` - VacatedStyle string `xml:"vacatedStyle,attr"` - Tag string `xml:"tag,attr"` - UpdatedVersion int `xml:"updatedVersion,attr"` - MinRefreshableVersion int `xml:"minRefreshableVersion,attr"` - AsteriskTotals bool `xml:"asteriskTotals,attr"` - ShowItems bool `xml:"showItems,attr"` - EditData bool `xml:"editData,attr"` - DisableFieldList bool `xml:"disableFieldList,attr"` - ShowCalcMbrs bool `xml:"showCalcMbrs,attr"` - VisualTotals bool `xml:"visualTotals,attr"` - ShowMultipleLabel bool `xml:"showMultipleLabel,attr"` - ShowDataDropDown bool `xml:"showDataDropDown,attr"` - ShowDrill bool `xml:"showDrill,attr"` - PrintDrill bool `xml:"printDrill,attr"` - ShowMemberPropertyTips bool `xml:"showMemberPropertyTips,attr"` - ShowDataTips bool `xml:"showDataTips,attr"` - EnableWizard bool `xml:"enableWizard,attr"` - EnableDrill bool `xml:"enableDrill,attr"` - EnableFieldProperties bool `xml:"enableFieldProperties,attr"` - PreserveFormatting bool `xml:"preserveFormatting,attr"` - UseAutoFormatting bool `xml:"useAutoFormatting,attr"` - PageWrap int `xml:"pageWrap,attr"` - PageOverThenDown bool `xml:"pageOverThenDown,attr"` - SubtotalHiddenItems bool `xml:"subtotalHiddenItems,attr"` - RowGrandTotals bool `xml:"rowGrandTotals,attr"` - ColGrandTotals bool `xml:"colGrandTotals,attr"` - FieldPrintTitles bool `xml:"fieldPrintTitles,attr"` - ItemPrintTitles bool `xml:"itemPrintTitles,attr"` - MergeItem bool `xml:"mergeItem,attr"` - ShowDropZones bool `xml:"showDropZones,attr"` - CreatedVersion int `xml:"createdVersion,attr"` - Indent int `xml:"indent,attr"` - ShowEmptyRow bool `xml:"showEmptyRow,attr"` - ShowEmptyCol bool `xml:"showEmptyCol,attr"` - ShowHeaders bool `xml:"showHeaders,attr"` - Compact bool `xml:"compact,attr"` - Outline bool `xml:"outline,attr"` - OutlineData bool `xml:"outlineData,attr"` - CompactData bool `xml:"compactData,attr"` - Published bool `xml:"published,attr"` - GridDropZones bool `xml:"gridDropZones,attr"` - Immersive bool `xml:"immersive,attr"` - MultipleFieldFilters bool `xml:"multipleFieldFilters,attr"` - ChartFormat int `xml:"chartFormat,attr"` - RowHeaderCaption string `xml:"rowHeaderCaption,attr"` - ColHeaderCaption string `xml:"colHeaderCaption,attr"` - FieldListSortAscending bool `xml:"fieldListSortAscending,attr"` - MdxSubqueries bool `xml:"mdxSubqueries,attr"` - CustomListSort bool `xml:"customListSort,attr"` - 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"` + 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"` + ShowError bool `xml:"showError,attr,omitempty"` + 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"` + UpdatedVersion int `xml:"updatedVersion,attr"` + MinRefreshableVersion int `xml:"minRefreshableVersion,attr"` + 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"` + ShowDrill bool `xml:"showDrill,attr,omitempty"` + 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"` + UseAutoFormatting bool `xml:"useAutoFormatting,attr"` + PageWrap int `xml:"pageWrap,attr,omitempty"` + PageOverThenDown bool `xml:"pageOverThenDown,attr,omitempty"` + SubtotalHiddenItems bool `xml:"subtotalHiddenItems,attr,omitempty"` + RowGrandTotals bool `xml:"rowGrandTotals,attr,omitempty"` + ColGrandTotals bool `xml:"colGrandTotals,attr,omitempty"` + FieldPrintTitles bool `xml:"fieldPrintTitles,attr,omitempty"` + ItemPrintTitles bool `xml:"itemPrintTitles,attr"` + MergeItem bool `xml:"mergeItem,attr,omitempty"` + ShowDropZones bool `xml:"showDropZones,attr,omitempty"` + CreatedVersion int `xml:"createdVersion,attr"` + Indent int `xml:"indent,attr,omitempty"` + ShowEmptyRow bool `xml:"showEmptyRow,attr,omitempty"` + ShowEmptyCol bool `xml:"showEmptyCol,attr,omitempty"` + ShowHeaders bool `xml:"showHeaders,attr,omitempty"` + Compact bool `xml:"compact,attr,omitempty"` + Outline bool `xml:"outline,attr,omitempty"` + OutlineData bool `xml:"outlineData,attr,omitempty"` + CompactData bool `xml:"compactData,attr,omitempty"` + Published bool `xml:"published,attr,omitempty"` + GridDropZones bool `xml:"gridDropZones,attr"` + 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"` } // xlsxLocation represents location information for the PivotTable. -- cgit v1.2.1 From 3c636da46029b1c578871dfab3e1692e989af9f7 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 20 Sep 2019 00:20:30 +0800 Subject: Resolve #40, init pivot table support --- xmlPivotTable.go | 141 +++++++++++++++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 71 deletions(-) (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go index 6f2a8e7..3738ed8 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -36,8 +36,8 @@ type xlsxPivotTableDefinition struct { PivotTableStyle string `xml:"pivotTableStyle,attr,omitempty"` VacatedStyle string `xml:"vacatedStyle,attr,omitempty"` Tag string `xml:"tag,attr,omitempty"` - UpdatedVersion int `xml:"updatedVersion,attr"` - MinRefreshableVersion int `xml:"minRefreshableVersion,attr"` + UpdatedVersion int `xml:"updatedVersion,attr,omitempty"` + MinRefreshableVersion int `xml:"minRefreshableVersion,attr,omitempty"` AsteriskTotals bool `xml:"asteriskTotals,attr,omitempty"` ShowItems bool `xml:"showItems,attr,omitempty"` EditData bool `xml:"editData,attr,omitempty"` @@ -54,27 +54,27 @@ type xlsxPivotTableDefinition struct { EnableDrill bool `xml:"enableDrill,attr,omitempty"` EnableFieldProperties bool `xml:"enableFieldProperties,attr,omitempty"` PreserveFormatting bool `xml:"preserveFormatting,attr,omitempty"` - UseAutoFormatting bool `xml:"useAutoFormatting,attr"` + UseAutoFormatting bool `xml:"useAutoFormatting,attr,omitempty"` PageWrap int `xml:"pageWrap,attr,omitempty"` PageOverThenDown bool `xml:"pageOverThenDown,attr,omitempty"` SubtotalHiddenItems bool `xml:"subtotalHiddenItems,attr,omitempty"` RowGrandTotals bool `xml:"rowGrandTotals,attr,omitempty"` ColGrandTotals bool `xml:"colGrandTotals,attr,omitempty"` FieldPrintTitles bool `xml:"fieldPrintTitles,attr,omitempty"` - ItemPrintTitles bool `xml:"itemPrintTitles,attr"` + ItemPrintTitles bool `xml:"itemPrintTitles,attr,omitempty"` MergeItem bool `xml:"mergeItem,attr,omitempty"` ShowDropZones bool `xml:"showDropZones,attr,omitempty"` - CreatedVersion int `xml:"createdVersion,attr"` + CreatedVersion int `xml:"createdVersion,attr,omitempty"` Indent int `xml:"indent,attr,omitempty"` ShowEmptyRow bool `xml:"showEmptyRow,attr,omitempty"` ShowEmptyCol bool `xml:"showEmptyCol,attr,omitempty"` ShowHeaders bool `xml:"showHeaders,attr,omitempty"` - Compact bool `xml:"compact,attr,omitempty"` - Outline bool `xml:"outline,attr,omitempty"` + Compact bool `xml:"compact,attr"` + Outline bool `xml:"outline,attr"` OutlineData bool `xml:"outlineData,attr,omitempty"` CompactData bool `xml:"compactData,attr,omitempty"` Published bool `xml:"published,attr,omitempty"` - GridDropZones bool `xml:"gridDropZones,attr"` + GridDropZones bool `xml:"gridDropZones,attr,omitempty"` Immersive bool `xml:"immersive,attr,omitempty"` MultipleFieldFilters bool `xml:"multipleFieldFilters,attr,omitempty"` ChartFormat int `xml:"chartFormat,attr,omitempty"` @@ -101,8 +101,8 @@ type xlsxLocation struct { FirstHeaderRow int `xml:"firstHeaderRow,attr"` FirstDataRow int `xml:"firstDataRow,attr"` FirstDataCol int `xml:"firstDataCol,attr"` - RowPageCount int `xml:"rowPageCount,attr"` - ColPageCount int `xml:"colPageCount,attr"` + RowPageCount int `xml:"rowPageCount,attr,omitempty"` + ColPageCount int `xml:"colPageCount,attr,omitempty"` } // xlsxPivotFields represents the collection of fields that appear on the @@ -116,50 +116,50 @@ type xlsxPivotFields struct { // contains information about the field, including the collection of items in // the field. type xlsxPivotField struct { - Name string `xml:"name,attr"` + Name string `xml:"name,attr,omitempty"` Axis string `xml:"axis,attr,omitempty"` - DataField bool `xml:"dataField,attr"` - SubtotalCaption string `xml:"subtotalCaption,attr"` - ShowDropDowns bool `xml:"showDropDowns,attr"` - HiddenLevel bool `xml:"hiddenLevel,attr"` - UniqueMemberProperty string `xml:"uniqueMemberProperty,attr"` + 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"` Compact bool `xml:"compact,attr"` - AllDrilled bool `xml:"allDrilled,attr"` + AllDrilled bool `xml:"allDrilled,attr,omitempty"` NumFmtId string `xml:"numFmtId,attr,omitempty"` Outline bool `xml:"outline,attr"` - SubtotalTop bool `xml:"subtotalTop,attr"` - DragToRow bool `xml:"dragToRow,attr"` - DragToCol bool `xml:"dragToCol,attr"` - MultipleItemSelectionAllowed bool `xml:"multipleItemSelectionAllowed,attr"` - DragToPage bool `xml:"dragToPage,attr"` - DragToData bool `xml:"dragToData,attr"` - DragOff bool `xml:"dragOff,attr"` + 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"` ShowAll bool `xml:"showAll,attr"` - InsertBlankRow bool `xml:"insertBlankRow,attr"` - ServerField bool `xml:"serverField,attr"` - InsertPageBreak bool `xml:"insertPageBreak,attr"` - AutoShow bool `xml:"autoShow,attr"` - TopAutoShow bool `xml:"topAutoShow,attr"` - HideNewItems bool `xml:"hideNewItems,attr"` - MeasureFilter bool `xml:"measureFilter,attr"` - IncludeNewItemsInFilter bool `xml:"includeNewItemsInFilter,attr"` - ItemPageCount int `xml:"itemPageCount,attr"` - SortType string `xml:"sortType,attr"` + 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"` DataSourceSort bool `xml:"dataSourceSort,attr,omitempty"` - NonAutoSortDefault bool `xml:"nonAutoSortDefault,attr"` + NonAutoSortDefault bool `xml:"nonAutoSortDefault,attr,omitempty"` RankBy int `xml:"rankBy,attr,omitempty"` - DefaultSubtotal bool `xml:"defaultSubtotal,attr"` - SumSubtotal bool `xml:"sumSubtotal,attr"` - CountASubtotal bool `xml:"countASubtotal,attr"` - AvgSubtotal bool `xml:"avgSubtotal,attr"` - MaxSubtotal bool `xml:"maxSubtotal,attr"` - MinSubtotal bool `xml:"minSubtotal,attr"` - ProductSubtotal bool `xml:"productSubtotal,attr"` - CountSubtotal bool `xml:"countSubtotal,attr"` - StdDevSubtotal bool `xml:"stdDevSubtotal,attr"` - StdDevPSubtotal bool `xml:"stdDevPSubtotal,attr"` - VarSubtotal bool `xml:"varSubtotal,attr"` - VarPSubtotal bool `xml:"varPSubtotal,attr"` + DefaultSubtotal bool `xml:"defaultSubtotal,attr,omitempty"` + 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"` ShowPropCell bool `xml:"showPropCell,attr,omitempty"` ShowPropTip bool `xml:"showPropTip,attr,omitempty"` ShowPropAsCaption bool `xml:"showPropAsCaption,attr,omitempty"` @@ -179,17 +179,17 @@ type xlsxItems struct { // xlsxItem represents a single item in PivotTable field. type xlsxItem struct { - N string `xml:"n,attr"` - T string `xml:"t,attr"` - H bool `xml:"h,attr"` - S bool `xml:"s,attr"` - SD bool `xml:"sd,attr"` - F bool `xml:"f,attr"` - M bool `xml:"m,attr"` - C bool `xml:"c,attr"` - X int `xml:"x,attr,omitempty"` - D bool `xml:"d,attr"` - E bool `xml:"e,attr"` + 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"` + X int `xml:"x,attr,omitempty,omitempty"` + D bool `xml:"d,attr,omitempty"` + E bool `xml:"e,attr,omitempty"` } // xlsxAutoSortScope represents the sorting scope for the PivotTable. @@ -198,8 +198,8 @@ type xlsxAutoSortScope struct { // xlsxRowFields represents the collection of row fields for the PivotTable. type xlsxRowFields struct { - Count int `xml:"count,attr"` - Fields []*xlsxField `xml:"fields"` + Count int `xml:"count,attr"` + Field []*xlsxField `xml:"field"` } // xlsxField represents a generic field that can appear either on the column @@ -224,14 +224,13 @@ type xlsxI struct { // xlsxX represents an array of indexes to cached shared item values. type xlsxX struct { - XMLName xml.Name `xml:"x"` } // xlsxColFields represents the collection of fields that are on the column // axis of the PivotTable. type xlsxColFields struct { - Count int `xml:"count,attr"` - Fields []*xlsxField `xml:"fields"` + Count int `xml:"count,attr"` + Field []*xlsxField `xml:"field"` } // xlsxColItems represents the collection of column items of the PivotTable. @@ -261,8 +260,8 @@ type xlsxPageField struct { // xlsxDataFields represents the collection of items in the data region of the // PivotTable. type xlsxDataFields struct { - Count int `xml:"count,attr"` - DataField *xlsxDataField `xml:"dataField"` + Count int `xml:"count,attr"` + DataField []*xlsxDataField `xml:"dataField"` } // xlsxDataField represents a field from a source list, table, or database @@ -270,10 +269,10 @@ type xlsxDataFields struct { type xlsxDataField struct { Name string `xml:"name,attr,omitempty"` Fld int `xml:"fld,attr"` - Subtotal string `xml:"subtotal,attr"` - ShowDataAs string `xml:"showDataAs,attr"` - BaseField int `xml:"baseField,attr"` - BaseItem int64 `xml:"baseItem,attr"` + Subtotal string `xml:"subtotal,attr,omitempty"` + ShowDataAs string `xml:"showDataAs,attr,omitempty"` + BaseField int `xml:"baseField,attr,omitempty"` + BaseItem int64 `xml:"baseItem,attr,omitempty"` NumFmtId string `xml:"numFmtId,attr,omitempty"` ExtLst *xlsxExtLst `xml:"extLst"` } @@ -289,7 +288,7 @@ type xlsxPivotTableStyleInfo struct { Name string `xml:"name,attr"` ShowRowHeaders bool `xml:"showRowHeaders,attr"` ShowColHeaders bool `xml:"showColHeaders,attr"` - ShowRowStripes bool `xml:"showRowStripes,attr"` - ShowColStripes bool `xml:"showColStripes,attr"` + ShowRowStripes bool `xml:"showRowStripes,attr,omitempty"` + ShowColStripes bool `xml:"showColStripes,attr,omitempty"` ShowLastColumn bool `xml:"showLastColumn,attr,omitempty"` } -- cgit v1.2.1 From 2e791fa433def282ee2e7a5049a46fc4a76796cf Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 16 Oct 2019 01:03:29 +0800 Subject: Optimize code of Getting/Setting Page Margins --- xmlPivotTable.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go index 3738ed8..0549c5e 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -125,7 +125,7 @@ type xlsxPivotField struct { UniqueMemberProperty string `xml:"uniqueMemberProperty,attr,omitempty"` Compact bool `xml:"compact,attr"` AllDrilled bool `xml:"allDrilled,attr,omitempty"` - NumFmtId string `xml:"numFmtId,attr,omitempty"` + NumFmtID string `xml:"numFmtId,attr,omitempty"` Outline bool `xml:"outline,attr"` SubtotalTop bool `xml:"subtotalTop,attr,omitempty"` DragToRow bool `xml:"dragToRow,attr,omitempty"` @@ -273,7 +273,7 @@ type xlsxDataField struct { ShowDataAs string `xml:"showDataAs,attr,omitempty"` BaseField int `xml:"baseField,attr,omitempty"` BaseItem int64 `xml:"baseItem,attr,omitempty"` - NumFmtId string `xml:"numFmtId,attr,omitempty"` + NumFmtID string `xml:"numFmtId,attr,omitempty"` ExtLst *xlsxExtLst `xml:"extLst"` } -- cgit v1.2.1 From 4e4a5b9b3e052d1694442515492792fb1aa74c5a Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 23 Dec 2019 00:07:40 +0800 Subject: Improve compatibility, fix workbook's rels ID calc error --- xmlPivotTable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go index 0549c5e..6e1dfb8 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -187,7 +187,7 @@ type xlsxItem struct { F bool `xml:"f,attr,omitempty"` M bool `xml:"m,attr,omitempty"` C bool `xml:"c,attr,omitempty"` - X int `xml:"x,attr,omitempty,omitempty"` + X int `xml:"x,attr,omitempty"` D bool `xml:"d,attr,omitempty"` E bool `xml:"e,attr,omitempty"` } -- cgit v1.2.1 From 09485b3f9f0aefc58d51462aed65c2416205c591 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 29 Dec 2019 16:02:31 +0800 Subject: Improve code coverage unit tests --- xmlPivotTable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go index 6e1dfb8..82bbf27 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -1,4 +1,4 @@ -// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of // this source code is governed by a BSD-style license that can be found in // the LICENSE file. // -- cgit v1.2.1 From e36650f4ffd3e305d2c3834620f97ec382cf6faf Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 9 Apr 2020 01:00:14 +0800 Subject: Resolve #598, filter support for AddPivotTable --- xmlPivotTable.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'xmlPivotTable.go') diff --git a/xmlPivotTable.go b/xmlPivotTable.go index 82bbf27..2eff026 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -251,9 +251,9 @@ type xlsxPageFields struct { type xlsxPageField struct { Fld int `xml:"fld,attr"` Item int `xml:"item,attr,omitempty"` - Hier int `xml:"hier,attr"` - Name string `xml:"name,attr"` - Cap string `xml:"cap,attr"` + Hier int `xml:"hier,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` + Cap string `xml:"cap,attr,omitempty"` ExtLst *xlsxExtLst `xml:"extLst"` } -- cgit v1.2.1