xmlPivotTable.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX / XLSM / XLTM files. Supports reading and writing
  7. // spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
  8. // complex components by high compatibility, and provided streaming API for
  9. // generating or reading data from a worksheet with huge amounts of data. This
  10. // library needs Go version 1.15 or later.
  11. package excelize
  12. import "encoding/xml"
  13. // xlsxPivotTableDefinition represents the PivotTable root element for
  14. // non-null PivotTables. There exists one pivotTableDefinition for each
  15. // PivotTableDefinition part
  16. type xlsxPivotTableDefinition struct {
  17. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main pivotTableDefinition"`
  18. Name string `xml:"name,attr"`
  19. CacheID int `xml:"cacheId,attr"`
  20. ApplyNumberFormats bool `xml:"applyNumberFormats,attr,omitempty"`
  21. ApplyBorderFormats bool `xml:"applyBorderFormats,attr,omitempty"`
  22. ApplyFontFormats bool `xml:"applyFontFormats,attr,omitempty"`
  23. ApplyPatternFormats bool `xml:"applyPatternFormats,attr,omitempty"`
  24. ApplyAlignmentFormats bool `xml:"applyAlignmentFormats,attr,omitempty"`
  25. ApplyWidthHeightFormats bool `xml:"applyWidthHeightFormats,attr,omitempty"`
  26. DataOnRows bool `xml:"dataOnRows,attr,omitempty"`
  27. DataPosition int `xml:"dataPosition,attr,omitempty"`
  28. DataCaption string `xml:"dataCaption,attr"`
  29. GrandTotalCaption string `xml:"grandTotalCaption,attr,omitempty"`
  30. ErrorCaption string `xml:"errorCaption,attr,omitempty"`
  31. ShowError *bool `xml:"showError,attr"`
  32. MissingCaption string `xml:"missingCaption,attr,omitempty"`
  33. ShowMissing bool `xml:"showMissing,attr,omitempty"`
  34. PageStyle string `xml:"pageStyle,attr,omitempty"`
  35. PivotTableStyle string `xml:"pivotTableStyle,attr,omitempty"`
  36. VacatedStyle string `xml:"vacatedStyle,attr,omitempty"`
  37. Tag string `xml:"tag,attr,omitempty"`
  38. UpdatedVersion int `xml:"updatedVersion,attr,omitempty"`
  39. MinRefreshableVersion int `xml:"minRefreshableVersion,attr,omitempty"`
  40. AsteriskTotals bool `xml:"asteriskTotals,attr,omitempty"`
  41. ShowItems bool `xml:"showItems,attr,omitempty"`
  42. EditData bool `xml:"editData,attr,omitempty"`
  43. DisableFieldList bool `xml:"disableFieldList,attr,omitempty"`
  44. ShowCalcMbrs bool `xml:"showCalcMbrs,attr,omitempty"`
  45. VisualTotals bool `xml:"visualTotals,attr,omitempty"`
  46. ShowMultipleLabel bool `xml:"showMultipleLabel,attr,omitempty"`
  47. ShowDataDropDown bool `xml:"showDataDropDown,attr,omitempty"`
  48. ShowDrill *bool `xml:"showDrill,attr"`
  49. PrintDrill bool `xml:"printDrill,attr,omitempty"`
  50. ShowMemberPropertyTips bool `xml:"showMemberPropertyTips,attr,omitempty"`
  51. ShowDataTips bool `xml:"showDataTips,attr,omitempty"`
  52. EnableWizard bool `xml:"enableWizard,attr,omitempty"`
  53. EnableDrill bool `xml:"enableDrill,attr,omitempty"`
  54. EnableFieldProperties bool `xml:"enableFieldProperties,attr,omitempty"`
  55. PreserveFormatting bool `xml:"preserveFormatting,attr,omitempty"`
  56. UseAutoFormatting *bool `xml:"useAutoFormatting,attr,omitempty"`
  57. PageWrap int `xml:"pageWrap,attr,omitempty"`
  58. PageOverThenDown *bool `xml:"pageOverThenDown,attr,omitempty"`
  59. SubtotalHiddenItems bool `xml:"subtotalHiddenItems,attr,omitempty"`
  60. RowGrandTotals *bool `xml:"rowGrandTotals,attr,omitempty"`
  61. ColGrandTotals *bool `xml:"colGrandTotals,attr,omitempty"`
  62. FieldPrintTitles bool `xml:"fieldPrintTitles,attr,omitempty"`
  63. ItemPrintTitles bool `xml:"itemPrintTitles,attr,omitempty"`
  64. MergeItem *bool `xml:"mergeItem,attr,omitempty"`
  65. ShowDropZones bool `xml:"showDropZones,attr,omitempty"`
  66. CreatedVersion int `xml:"createdVersion,attr,omitempty"`
  67. Indent int `xml:"indent,attr,omitempty"`
  68. ShowEmptyRow bool `xml:"showEmptyRow,attr,omitempty"`
  69. ShowEmptyCol bool `xml:"showEmptyCol,attr,omitempty"`
  70. ShowHeaders bool `xml:"showHeaders,attr,omitempty"`
  71. Compact bool `xml:"compact,attr"`
  72. Outline bool `xml:"outline,attr"`
  73. OutlineData bool `xml:"outlineData,attr,omitempty"`
  74. CompactData *bool `xml:"compactData,attr,omitempty"`
  75. Published bool `xml:"published,attr,omitempty"`
  76. GridDropZones bool `xml:"gridDropZones,attr,omitempty"`
  77. Immersive bool `xml:"immersive,attr,omitempty"`
  78. MultipleFieldFilters bool `xml:"multipleFieldFilters,attr,omitempty"`
  79. ChartFormat int `xml:"chartFormat,attr,omitempty"`
  80. RowHeaderCaption string `xml:"rowHeaderCaption,attr,omitempty"`
  81. ColHeaderCaption string `xml:"colHeaderCaption,attr,omitempty"`
  82. FieldListSortAscending bool `xml:"fieldListSortAscending,attr,omitempty"`
  83. MdxSubqueries bool `xml:"mdxSubqueries,attr,omitempty"`
  84. CustomListSort bool `xml:"customListSort,attr,omitempty"`
  85. Location *xlsxLocation `xml:"location"`
  86. PivotFields *xlsxPivotFields `xml:"pivotFields"`
  87. RowFields *xlsxRowFields `xml:"rowFields"`
  88. RowItems *xlsxRowItems `xml:"rowItems"`
  89. ColFields *xlsxColFields `xml:"colFields"`
  90. ColItems *xlsxColItems `xml:"colItems"`
  91. PageFields *xlsxPageFields `xml:"pageFields"`
  92. DataFields *xlsxDataFields `xml:"dataFields"`
  93. ConditionalFormats *xlsxConditionalFormats `xml:"conditionalFormats"`
  94. PivotTableStyleInfo *xlsxPivotTableStyleInfo `xml:"pivotTableStyleInfo"`
  95. }
  96. // xlsxLocation represents location information for the PivotTable.
  97. type xlsxLocation struct {
  98. Ref string `xml:"ref,attr"`
  99. FirstHeaderRow int `xml:"firstHeaderRow,attr"`
  100. FirstDataRow int `xml:"firstDataRow,attr"`
  101. FirstDataCol int `xml:"firstDataCol,attr"`
  102. RowPageCount int `xml:"rowPageCount,attr,omitempty"`
  103. ColPageCount int `xml:"colPageCount,attr,omitempty"`
  104. }
  105. // xlsxPivotFields represents the collection of fields that appear on the
  106. // PivotTable.
  107. type xlsxPivotFields struct {
  108. Count int `xml:"count,attr"`
  109. PivotField []*xlsxPivotField `xml:"pivotField"`
  110. }
  111. // xlsxPivotField represents a single field in the PivotTable. This element
  112. // contains information about the field, including the collection of items in
  113. // the field.
  114. type xlsxPivotField struct {
  115. Name string `xml:"name,attr,omitempty"`
  116. Axis string `xml:"axis,attr,omitempty"`
  117. DataField bool `xml:"dataField,attr,omitempty"`
  118. SubtotalCaption string `xml:"subtotalCaption,attr,omitempty"`
  119. ShowDropDowns bool `xml:"showDropDowns,attr,omitempty"`
  120. HiddenLevel bool `xml:"hiddenLevel,attr,omitempty"`
  121. UniqueMemberProperty string `xml:"uniqueMemberProperty,attr,omitempty"`
  122. Compact bool `xml:"compact,attr"`
  123. AllDrilled bool `xml:"allDrilled,attr,omitempty"`
  124. NumFmtID string `xml:"numFmtId,attr,omitempty"`
  125. Outline bool `xml:"outline,attr"`
  126. SubtotalTop bool `xml:"subtotalTop,attr,omitempty"`
  127. DragToRow bool `xml:"dragToRow,attr,omitempty"`
  128. DragToCol bool `xml:"dragToCol,attr,omitempty"`
  129. MultipleItemSelectionAllowed bool `xml:"multipleItemSelectionAllowed,attr,omitempty"`
  130. DragToPage bool `xml:"dragToPage,attr,omitempty"`
  131. DragToData bool `xml:"dragToData,attr,omitempty"`
  132. DragOff bool `xml:"dragOff,attr,omitempty"`
  133. ShowAll bool `xml:"showAll,attr"`
  134. InsertBlankRow bool `xml:"insertBlankRow,attr,omitempty"`
  135. ServerField bool `xml:"serverField,attr,omitempty"`
  136. InsertPageBreak bool `xml:"insertPageBreak,attr,omitempty"`
  137. AutoShow bool `xml:"autoShow,attr,omitempty"`
  138. TopAutoShow bool `xml:"topAutoShow,attr,omitempty"`
  139. HideNewItems bool `xml:"hideNewItems,attr,omitempty"`
  140. MeasureFilter bool `xml:"measureFilter,attr,omitempty"`
  141. IncludeNewItemsInFilter bool `xml:"includeNewItemsInFilter,attr,omitempty"`
  142. ItemPageCount int `xml:"itemPageCount,attr,omitempty"`
  143. SortType string `xml:"sortType,attr,omitempty"`
  144. DataSourceSort bool `xml:"dataSourceSort,attr,omitempty"`
  145. NonAutoSortDefault bool `xml:"nonAutoSortDefault,attr,omitempty"`
  146. RankBy int `xml:"rankBy,attr,omitempty"`
  147. DefaultSubtotal *bool `xml:"defaultSubtotal,attr,omitempty"`
  148. SumSubtotal bool `xml:"sumSubtotal,attr,omitempty"`
  149. CountASubtotal bool `xml:"countASubtotal,attr,omitempty"`
  150. AvgSubtotal bool `xml:"avgSubtotal,attr,omitempty"`
  151. MaxSubtotal bool `xml:"maxSubtotal,attr,omitempty"`
  152. MinSubtotal bool `xml:"minSubtotal,attr,omitempty"`
  153. ProductSubtotal bool `xml:"productSubtotal,attr,omitempty"`
  154. CountSubtotal bool `xml:"countSubtotal,attr,omitempty"`
  155. StdDevSubtotal bool `xml:"stdDevSubtotal,attr,omitempty"`
  156. StdDevPSubtotal bool `xml:"stdDevPSubtotal,attr,omitempty"`
  157. VarSubtotal bool `xml:"varSubtotal,attr,omitempty"`
  158. VarPSubtotal bool `xml:"varPSubtotal,attr,omitempty"`
  159. ShowPropCell bool `xml:"showPropCell,attr,omitempty"`
  160. ShowPropTip bool `xml:"showPropTip,attr,omitempty"`
  161. ShowPropAsCaption bool `xml:"showPropAsCaption,attr,omitempty"`
  162. DefaultAttributeDrillState bool `xml:"defaultAttributeDrillState,attr,omitempty"`
  163. Items *xlsxItems `xml:"items"`
  164. AutoSortScope *xlsxAutoSortScope `xml:"autoSortScope"`
  165. ExtLst *xlsxExtLst `xml:"extLst"`
  166. }
  167. // xlsxItems represents the collection of items in a PivotTable field. The
  168. // items in the collection are ordered by index. Items represent the unique
  169. // entries from the field in the source data.
  170. type xlsxItems struct {
  171. Count int `xml:"count,attr"`
  172. Item []*xlsxItem `xml:"item"`
  173. }
  174. // xlsxItem represents a single item in PivotTable field.
  175. type xlsxItem struct {
  176. N string `xml:"n,attr,omitempty"`
  177. T string `xml:"t,attr,omitempty"`
  178. H bool `xml:"h,attr,omitempty"`
  179. S bool `xml:"s,attr,omitempty"`
  180. SD bool `xml:"sd,attr,omitempty"`
  181. F bool `xml:"f,attr,omitempty"`
  182. M bool `xml:"m,attr,omitempty"`
  183. C bool `xml:"c,attr,omitempty"`
  184. X *int `xml:"x,attr,omitempty"`
  185. D bool `xml:"d,attr,omitempty"`
  186. E bool `xml:"e,attr,omitempty"`
  187. }
  188. // xlsxAutoSortScope represents the sorting scope for the PivotTable.
  189. type xlsxAutoSortScope struct {
  190. }
  191. // xlsxRowFields represents the collection of row fields for the PivotTable.
  192. type xlsxRowFields struct {
  193. Count int `xml:"count,attr"`
  194. Field []*xlsxField `xml:"field"`
  195. }
  196. // xlsxField represents a generic field that can appear either on the column
  197. // or the row region of the PivotTable. There areas many <x> elements as there
  198. // are item values in any particular column or row.
  199. type xlsxField struct {
  200. X int `xml:"x,attr"`
  201. }
  202. // xlsxRowItems represents the collection of items in row axis of the
  203. // PivotTable.
  204. type xlsxRowItems struct {
  205. Count int `xml:"count,attr"`
  206. I []*xlsxI `xml:"i"`
  207. }
  208. // xlsxI represents the collection of items in the row region of the
  209. // PivotTable.
  210. type xlsxI struct {
  211. X []*xlsxX `xml:"x"`
  212. }
  213. // xlsxX represents an array of indexes to cached shared item values.
  214. type xlsxX struct {
  215. }
  216. // xlsxColFields represents the collection of fields that are on the column
  217. // axis of the PivotTable.
  218. type xlsxColFields struct {
  219. Count int `xml:"count,attr"`
  220. Field []*xlsxField `xml:"field"`
  221. }
  222. // xlsxColItems represents the collection of column items of the PivotTable.
  223. type xlsxColItems struct {
  224. Count int `xml:"count,attr"`
  225. I []*xlsxI `xml:"i"`
  226. }
  227. // xlsxPageFields represents the collection of items in the page or report
  228. // filter region of the PivotTable.
  229. type xlsxPageFields struct {
  230. Count int `xml:"count,attr"`
  231. PageField []*xlsxPageField `xml:"pageField"`
  232. }
  233. // xlsxPageField represents a field on the page or report filter of the
  234. // PivotTable.
  235. type xlsxPageField struct {
  236. Fld int `xml:"fld,attr"`
  237. Item int `xml:"item,attr,omitempty"`
  238. Hier int `xml:"hier,attr,omitempty"`
  239. Name string `xml:"name,attr,omitempty"`
  240. Cap string `xml:"cap,attr,omitempty"`
  241. ExtLst *xlsxExtLst `xml:"extLst"`
  242. }
  243. // xlsxDataFields represents the collection of items in the data region of the
  244. // PivotTable.
  245. type xlsxDataFields struct {
  246. Count int `xml:"count,attr"`
  247. DataField []*xlsxDataField `xml:"dataField"`
  248. }
  249. // xlsxDataField represents a field from a source list, table, or database
  250. // that contains data that is summarized in a PivotTable.
  251. type xlsxDataField struct {
  252. Name string `xml:"name,attr,omitempty"`
  253. Fld int `xml:"fld,attr"`
  254. Subtotal string `xml:"subtotal,attr,omitempty"`
  255. ShowDataAs string `xml:"showDataAs,attr,omitempty"`
  256. BaseField int `xml:"baseField,attr,omitempty"`
  257. BaseItem int64 `xml:"baseItem,attr,omitempty"`
  258. NumFmtID string `xml:"numFmtId,attr,omitempty"`
  259. ExtLst *xlsxExtLst `xml:"extLst"`
  260. }
  261. // xlsxConditionalFormats represents the collection of conditional formats
  262. // applied to a PivotTable.
  263. type xlsxConditionalFormats struct {
  264. }
  265. // xlsxPivotTableStyleInfo represent information on style applied to the
  266. // PivotTable.
  267. type xlsxPivotTableStyleInfo struct {
  268. Name string `xml:"name,attr"`
  269. ShowRowHeaders bool `xml:"showRowHeaders,attr"`
  270. ShowColHeaders bool `xml:"showColHeaders,attr"`
  271. ShowRowStripes bool `xml:"showRowStripes,attr,omitempty"`
  272. ShowColStripes bool `xml:"showColStripes,attr,omitempty"`
  273. ShowLastColumn bool `xml:"showLastColumn,attr,omitempty"`
  274. }