xmlPivotTable.go 14 KB

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