xmlTable.go 9.6 KB

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