xmlTable.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. // xlsxTable directly maps the table element. A table helps organize and provide
  12. // structure to lists of information in a worksheet. Tables have clearly labeled
  13. // columns, rows, and data regions. Tables make it easier for users to sort,
  14. // analyze, format, manage, add, and delete information. This element is the
  15. // root element for a table that is not a single cell XML table.
  16. type xlsxTable struct {
  17. XMLName xml.Name `xml:"table"`
  18. XMLNS string `xml:"xmlns,attr"`
  19. DataCellStyle string `xml:"dataCellStyle,attr,omitempty"`
  20. DataDxfID int `xml:"dataDxfId,attr,omitempty"`
  21. DisplayName string `xml:"displayName,attr,omitempty"`
  22. HeaderRowBorderDxfID int `xml:"headerRowBorderDxfId,attr,omitempty"`
  23. HeaderRowCellStyle string `xml:"headerRowCellStyle,attr,omitempty"`
  24. HeaderRowCount int `xml:"headerRowCount,attr,omitempty"`
  25. HeaderRowDxfID int `xml:"headerRowDxfId,attr,omitempty"`
  26. ID int `xml:"id,attr"`
  27. InsertRow bool `xml:"insertRow,attr,omitempty"`
  28. InsertRowShift bool `xml:"insertRowShift,attr,omitempty"`
  29. Name string `xml:"name,attr"`
  30. Published bool `xml:"published,attr,omitempty"`
  31. Ref string `xml:"ref,attr"`
  32. TotalsRowCount int `xml:"totalsRowCount,attr,omitempty"`
  33. TotalsRowDxfID int `xml:"totalsRowDxfId,attr,omitempty"`
  34. TotalsRowShown bool `xml:"totalsRowShown,attr"`
  35. AutoFilter *xlsxAutoFilter `xml:"autoFilter"`
  36. TableColumns *xlsxTableColumns `xml:"tableColumns"`
  37. TableStyleInfo *xlsxTableStyleInfo `xml:"tableStyleInfo"`
  38. }
  39. // xlsxAutoFilter temporarily hides rows based on a filter criteria, which is
  40. // applied column by column to a table of data in the worksheet. This collection
  41. // expresses AutoFilter settings.
  42. type xlsxAutoFilter struct {
  43. XMLName xml.Name `xml:"autoFilter"`
  44. Ref string `xml:"ref,attr"`
  45. FilterColumn *xlsxFilterColumn `xml:"filterColumn"`
  46. }
  47. // xlsxFilterColumn directly maps the filterColumn element. The filterColumn
  48. // collection identifies a particular column in the AutoFilter range and
  49. // specifies filter information that has been applied to this column. If a
  50. // column in the AutoFilter range has no criteria specified, then there is no
  51. // corresponding filterColumn collection expressed for that column.
  52. type xlsxFilterColumn struct {
  53. ColID int `xml:"colId,attr"`
  54. HiddenButton bool `xml:"hiddenButton,attr,omitempty"`
  55. ShowButton bool `xml:"showButton,attr,omitempty"`
  56. CustomFilters *xlsxCustomFilters `xml:"customFilters"`
  57. Filters *xlsxFilters `xml:"filters"`
  58. ColorFilter *xlsxColorFilter `xml:"colorFilter"`
  59. DynamicFilter *xlsxDynamicFilter `xml:"dynamicFilter"`
  60. IconFilter *xlsxIconFilter `xml:"iconFilter"`
  61. Top10 *xlsxTop10 `xml:"top10"`
  62. }
  63. // xlsxCustomFilters directly maps the customFilters element. When there is more
  64. // than one custom filter criteria to apply (an 'and' or 'or' joining two
  65. // criteria), then this element groups the customFilter elements together.
  66. type xlsxCustomFilters struct {
  67. And bool `xml:"and,attr,omitempty"`
  68. CustomFilter []*xlsxCustomFilter `xml:"customFilter"`
  69. }
  70. // xlsxCustomFilter directly maps the customFilter element. A custom AutoFilter
  71. // specifies an operator and a value. There can be at most two customFilters
  72. // specified, and in that case the parent element specifies whether the two
  73. // conditions are joined by 'and' or 'or'. For any cells whose values do not
  74. // meet the specified criteria, the corresponding rows shall be hidden from view
  75. // when the filter is applied.
  76. type xlsxCustomFilter struct {
  77. Operator string `xml:"operator,attr,omitempty"`
  78. Val string `xml:"val,attr,omitempty"`
  79. }
  80. // xlsxFilters directly maps the filters (Filter Criteria) element. When
  81. // multiple values are chosen to filter by, or when a group of date values are
  82. // chosen to filter by, this element groups those criteria together.
  83. type xlsxFilters struct {
  84. Blank bool `xml:"blank,attr,omitempty"`
  85. CalendarType string `xml:"calendarType,attr,omitempty"`
  86. Filter []*xlsxFilter `xml:"filter"`
  87. DateGroupItem []*xlsxDateGroupItem `xml:"dateGroupItem"`
  88. }
  89. // xlsxFilter directly maps the filter element. This element expresses a filter
  90. // criteria value.
  91. type xlsxFilter struct {
  92. Val string `xml:"val,attr,omitempty"`
  93. }
  94. // xlsxColorFilter directly maps the colorFilter element. This element specifies
  95. // the color to filter by and whether to use the cell's fill or font color in
  96. // the filter criteria. If the cell's font or fill color does not match the
  97. // color specified in the criteria, the rows corresponding to those cells are
  98. // hidden from view.
  99. type xlsxColorFilter struct {
  100. CellColor bool `xml:"cellColor,attr"`
  101. DxfID int `xml:"dxfId,attr"`
  102. }
  103. // xlsxDynamicFilter directly maps the dynamicFilter element. This collection
  104. // specifies dynamic filter criteria. These criteria are considered dynamic
  105. // because they can change, either with the data itself (e.g., "above average")
  106. // or with the current system date (e.g., show values for "today"). For any
  107. // cells whose values do not meet the specified criteria, the corresponding rows
  108. // shall be hidden from view when the filter is applied.
  109. type xlsxDynamicFilter struct {
  110. MaxValISO string `xml:"maxValIso,attr,omitempty"`
  111. Type string `xml:"type,attr,omitempty"`
  112. Val float64 `xml:"val,attr,omitempty"`
  113. ValISO string `xml:"valIso,attr,omitempty"`
  114. }
  115. // xlsxIconFilter directly maps the iconFilter element. This element specifies
  116. // the icon set and particular icon within that set to filter by. For any cells
  117. // whose icon does not match the specified criteria, the corresponding rows
  118. // shall be hidden from view when the filter is applied.
  119. type xlsxIconFilter struct {
  120. IconID int `xml:"iconId,attr"`
  121. IconSet string `xml:"iconSet,attr,omitempty"`
  122. }
  123. // xlsxTop10 directly maps the top10 element. This element specifies the top N
  124. // (percent or number of items) to filter by.
  125. type xlsxTop10 struct {
  126. FilterVal float64 `xml:"filterVal,attr,omitempty"`
  127. Percent bool `xml:"percent,attr,omitempty"`
  128. Top bool `xml:"top,attr"`
  129. Val float64 `xml:"val,attr,omitempty"`
  130. }
  131. // xlsxDateGroupItem directly maps the dateGroupItem element. This collection is
  132. // used to express a group of dates or times which are used in an AutoFilter
  133. // criteria. [Note: See parent element for an example. end note] Values are
  134. // always written in the calendar type of the first date encountered in the
  135. // filter range, so that all subsequent dates, even when formatted or
  136. // represented by other calendar types, can be correctly compared for the
  137. // purposes of filtering.
  138. type xlsxDateGroupItem struct {
  139. DateTimeGrouping string `xml:"dateTimeGrouping,attr,omitempty"`
  140. Day int `xml:"day,attr,omitempty"`
  141. Hour int `xml:"hour,attr,omitempty"`
  142. Minute int `xml:"minute,attr,omitempty"`
  143. Month int `xml:"month,attr,omitempty"`
  144. Second int `xml:"second,attr,omitempty"`
  145. Year int `xml:"year,attr,omitempty"`
  146. }
  147. // xlsxTableColumns directly maps the element representing the collection of all
  148. // table columns for this table.
  149. type xlsxTableColumns struct {
  150. Count int `xml:"count,attr"`
  151. TableColumn []*xlsxTableColumn `xml:"tableColumn"`
  152. }
  153. // xlsxTableColumn directly maps the element representing a single column for
  154. // this table.
  155. type xlsxTableColumn struct {
  156. DataCellStyle string `xml:"dataCellStyle,attr,omitempty"`
  157. DataDxfID int `xml:"dataDxfId,attr,omitempty"`
  158. HeaderRowCellStyle string `xml:"headerRowCellStyle,attr,omitempty"`
  159. HeaderRowDxfID int `xml:"headerRowDxfId,attr,omitempty"`
  160. ID int `xml:"id,attr"`
  161. Name string `xml:"name,attr"`
  162. QueryTableFieldID int `xml:"queryTableFieldId,attr,omitempty"`
  163. TotalsRowCellStyle string `xml:"totalsRowCellStyle,attr,omitempty"`
  164. TotalsRowDxfID int `xml:"totalsRowDxfId,attr,omitempty"`
  165. TotalsRowFunction string `xml:"totalsRowFunction,attr,omitempty"`
  166. TotalsRowLabel string `xml:"totalsRowLabel,attr,omitempty"`
  167. UniqueName string `xml:"uniqueName,attr,omitempty"`
  168. }
  169. // xlsxTableStyleInfo directly maps the tableStyleInfo element. This element
  170. // describes which style is used to display this table, and specifies which
  171. // portions of the table have the style applied.
  172. type xlsxTableStyleInfo struct {
  173. Name string `xml:"name,attr,omitempty"`
  174. ShowFirstColumn bool `xml:"showFirstColumn,attr"`
  175. ShowLastColumn bool `xml:"showLastColumn,attr"`
  176. ShowRowStripes bool `xml:"showRowStripes,attr"`
  177. ShowColumnStripes bool `xml:"showColumnStripes,attr"`
  178. }
  179. // formatTable directly maps the format settings of the table.
  180. type formatTable struct {
  181. TableName string `json:"table_name"`
  182. TableStyle string `json:"table_style"`
  183. ShowFirstColumn bool `json:"show_first_column"`
  184. ShowLastColumn bool `json:"show_last_column"`
  185. ShowRowStripes bool `json:"show_row_stripes"`
  186. ShowColumnStripes bool `json:"show_column_stripes"`
  187. }
  188. // formatAutoFilter directly maps the auto filter settings.
  189. type formatAutoFilter struct {
  190. Column string `json:"column"`
  191. Expression string `json:"expression"`
  192. FilterList []struct {
  193. Column string `json:"column"`
  194. Value []int `json:"value"`
  195. } `json:"filter_list"`
  196. }