xmlPivotTable.go 16 KB

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