xmlTable.go 10 KB

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