xmlTable.go 10 KB

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