xmlStyles.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package excelize
  2. import "encoding/xml"
  3. // xlsxStyleSheet directly maps the stylesheet element in the namespace
  4. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  5. // not checked it for completeness - it does as much as I need.
  6. type xlsxStyleSheet struct {
  7. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main styleSheet"`
  8. NumFmts *xlsxNumFmts `xml:"numFmts,omitempty"`
  9. Fonts *xlsxFonts `xml:"fonts,omitempty"`
  10. Fills *xlsxFills `xml:"fills,omitempty"`
  11. Borders *xlsxBorders `xml:"borders,omitempty"`
  12. CellStyleXfs *xlsxCellStyleXfs `xml:"cellStyleXfs,omitempty"`
  13. CellXfs *xlsxCellXfs `xml:"cellXfs,omitempty"`
  14. CellStyles *xlsxCellStyles `xml:"cellStyles,omitempty"`
  15. Dxfs *xlsxDxfs `xml:"dxfs,omitempty"`
  16. TableStyles *xlsxTableStyles `xml:"tableStyles,omitempty"`
  17. Colors *xlsxStyleColors `xml:"colors,omitempty"`
  18. ExtLst *xlsxExtLst `xml:"extLst"`
  19. }
  20. // xlsxAlignment formatting information pertaining to text alignment in cells.
  21. // There are a variety of choices for how text is aligned both horizontally and
  22. // vertically, as well as indentation settings, and so on.
  23. type xlsxAlignment struct {
  24. Horizontal string `xml:"horizontal,attr,omitempty"`
  25. Indent int `xml:"indent,attr,omitempty"`
  26. JustifyLastLine bool `xml:"justifyLastLine,attr,omitempty"`
  27. ReadingOrder uint64 `xml:"readingOrder,attr,omitempty"`
  28. RelativeIndent int `xml:"relativeIndent,attr,omitempty"`
  29. ShrinkToFit bool `xml:"shrinkToFit,attr,omitempty"`
  30. TextRotation int `xml:"textRotation,attr,omitempty"`
  31. Vertical string `xml:"vertical,attr,omitempty"`
  32. WrapText bool `xml:"wrapText,attr,omitempty"`
  33. }
  34. // xlsxLine directly maps the line style element in the namespace
  35. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  36. // not checked it for completeness - it does as much as I need.
  37. type xlsxLine struct {
  38. Style string `xml:"style,attr,omitempty"`
  39. Color *xlsxColor `xml:"color,omitempty"`
  40. }
  41. // xlsxColor is a common mapping used for both the fgColor and bgColor elements
  42. // in the namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  43. // currently I have not checked it for completeness - it does as much as I need.
  44. type xlsxColor struct {
  45. RGB string `xml:"rgb,attr,omitempty"`
  46. Theme *int `xml:"theme,attr,omitempty"`
  47. Tint float64 `xml:"tint,attr,omitempty"`
  48. }
  49. // xlsxFonts directly maps the fonts element. This element contains all font
  50. // definitions for this workbook.
  51. type xlsxFonts struct {
  52. Count int `xml:"count,attr"`
  53. Font []*xlsxFont `xml:"font,omitempty"`
  54. }
  55. // xlsxFont directly maps the font element. This element defines the properties
  56. // for one of the fonts used in this workbook.
  57. type xlsxFont struct {
  58. Font string `xml:",innerxml"`
  59. }
  60. // xlsxFills directly maps the fills element. This element defines the cell
  61. // fills portion of the Styles part, consisting of a sequence of fill records. A
  62. // cell fill consists of a background color, foreground color, and pattern to be
  63. // applied across the cell.
  64. type xlsxFills struct {
  65. Count int `xml:"count,attr"`
  66. Fill []xlsxFill `xml:"fill,omitempty"`
  67. }
  68. // xlsxFill directly maps the fill element. This element specifies fill
  69. // formatting.
  70. type xlsxFill struct {
  71. Fill string `xml:",innerxml"`
  72. }
  73. // xlsxBorders directly maps the borders element. This element contains borders
  74. // formatting information, specifying all border definitions for all cells in
  75. // the workbook.
  76. type xlsxBorders struct {
  77. Count int `xml:"count,attr"`
  78. Border []*xlsxBorder `xml:"border,omitempty"`
  79. }
  80. // xlsxBorder directly maps the border element. Expresses a single set of cell
  81. // border formats (left, right, top, bottom, diagonal). Color is optional. When
  82. // missing, 'automatic' is implied.
  83. type xlsxBorder struct {
  84. DiagonalDown bool `xml:"diagonalDown,attr,omitempty"`
  85. DiagonalUp bool `xml:"diagonalUp,attr,omitempty"`
  86. Outline bool `xml:"outline,attr,omitempty"`
  87. Left xlsxLine `xml:"left,omitempty"`
  88. Right xlsxLine `xml:"right,omitempty"`
  89. Top xlsxLine `xml:"top,omitempty"`
  90. Bottom xlsxLine `xml:"bottom,omitempty"`
  91. Diagonal xlsxLine `xml:"diagonal,omitempty"`
  92. }
  93. // xlsxCellStyles directly maps the cellStyles element. This element contains
  94. // the named cell styles, consisting of a sequence of named style records. A
  95. // named cell style is a collection of direct or themed formatting (e.g., cell
  96. // border, cell fill, and font type/size/style) grouped together into a single
  97. // named style, and can be applied to a cell.
  98. type xlsxCellStyles struct {
  99. XMLName xml.Name `xml:"cellStyles"`
  100. Count int `xml:"count,attr"`
  101. CellStyle []*xlsxCellStyle `xml:"cellStyle,omitempty"`
  102. }
  103. // xlsxCellStyle directly maps the cellStyle element. This element represents
  104. // the name and related formatting records for a named cell style in this
  105. // workbook.
  106. type xlsxCellStyle struct {
  107. XMLName xml.Name `xml:"cellStyle"`
  108. BuiltInID *int `xml:"builtInId,attr,omitempty"`
  109. CustomBuiltIn *bool `xml:"customBuiltIn,attr,omitempty"`
  110. Hidden *bool `xml:"hidden,attr,omitempty"`
  111. ILevel *bool `xml:"iLevel,attr,omitempty"`
  112. Name string `xml:"name,attr"`
  113. XfID int `xml:"xfId,attr"`
  114. }
  115. // xlsxCellStyleXfs directly maps the cellStyleXfs element. This element
  116. // contains the master formatting records (xf's) which define the formatting for
  117. // all named cell styles in this workbook. Master formatting records reference
  118. // individual elements of formatting (e.g., number format, font definitions,
  119. // cell fills, etc) by specifying a zero-based index into those collections.
  120. // Master formatting records also specify whether to apply or ignore particular
  121. // aspects of formatting.
  122. type xlsxCellStyleXfs struct {
  123. Count int `xml:"count,attr"`
  124. Xf []xlsxXf `xml:"xf,omitempty"`
  125. }
  126. // xlsxXf directly maps the xf element. A single xf element describes all of the
  127. // formatting for a cell.
  128. type xlsxXf struct {
  129. ApplyAlignment bool `xml:"applyAlignment,attr"`
  130. ApplyBorder bool `xml:"applyBorder,attr"`
  131. ApplyFill bool `xml:"applyFill,attr"`
  132. ApplyFont bool `xml:"applyFont,attr"`
  133. ApplyNumberFormat bool `xml:"applyNumberFormat,attr"`
  134. ApplyProtection bool `xml:"applyProtection,attr"`
  135. BorderID int `xml:"borderId,attr"`
  136. FillID int `xml:"fillId,attr"`
  137. FontID int `xml:"fontId,attr"`
  138. NumFmtID int `xml:"numFmtId,attr"`
  139. PivotButton bool `xml:"pivotButton,attr,omitempty"`
  140. QuotePrefix bool `xml:"quotePrefix,attr,omitempty"`
  141. XfID *int `xml:"xfId,attr,omitempty"`
  142. Alignment *xlsxAlignment `xml:"alignment"`
  143. }
  144. // xlsxCellXfs directly maps the cellXfs element. This element contains the
  145. // master formatting records (xf) which define the formatting applied to cells
  146. // in this workbook. These records are the starting point for determining the
  147. // formatting for a cell. Cells in the Sheet Part reference the xf records by
  148. // zero-based index.
  149. type xlsxCellXfs struct {
  150. Count int `xml:"count,attr"`
  151. Xf []xlsxXf `xml:"xf,omitempty"`
  152. }
  153. // xlsxDxfs directly maps the dxfs element. This element contains the master
  154. // differential formatting records (dxf's) which define formatting for all non-
  155. // cell formatting in this workbook. Whereas xf records fully specify a
  156. // particular aspect of formatting (e.g., cell borders) by referencing those
  157. // formatting definitions elsewhere in the Styles part, dxf records specify
  158. // incremental (or differential) aspects of formatting directly inline within
  159. // the dxf element. The dxf formatting is to be applied on top of or in addition
  160. // to any formatting already present on the object using the dxf record.
  161. type xlsxDxfs struct {
  162. Count int `xml:"count,attr"`
  163. Dxfs []*xlsxDxf `xml:"dxf,omitempty"`
  164. }
  165. // xlsxDxf directly maps the dxf element. A single dxf record, expressing
  166. // incremental formatting to be applied.
  167. type xlsxDxf struct {
  168. Dxf string `xml:",innerxml"`
  169. }
  170. // xlsxTableStyles directly maps the tableStyles element. This element
  171. // represents a collection of Table style definitions for Table styles and
  172. // PivotTable styles used in this workbook. It consists of a sequence of
  173. // tableStyle records, each defining a single Table style.
  174. type xlsxTableStyles struct {
  175. Count int `xml:"count,attr"`
  176. DefaultPivotStyle string `xml:"defaultPivotStyle,attr"`
  177. DefaultTableStyle string `xml:"defaultTableStyle,attr"`
  178. TableStyles []*xlsxTableStyle `xml:"tableStyle,omitempty"`
  179. }
  180. // xlsxTableStyle directly maps the tableStyle element. This element represents
  181. // a single table style definition that indicates how a spreadsheet application
  182. // should format and display a table.
  183. type xlsxTableStyle struct {
  184. Name string `xml:"name,attr,omitempty"`
  185. Pivot int `xml:"pivot,attr,omitempty"`
  186. Count int `xml:"count,attr,omitempty"`
  187. Table bool `xml:"table,attr,omitempty"`
  188. TableStyleElement string `xml:",innerxml"`
  189. }
  190. // xlsxNumFmts directly maps the numFmts element. This element defines the
  191. // number formats in this workbook, consisting of a sequence of numFmt records,
  192. // where each numFmt record defines a particular number format, indicating how
  193. // to format and render the numeric value of a cell.
  194. type xlsxNumFmts struct {
  195. Count int `xml:"count,attr"`
  196. NumFmt []*xlsxNumFmt `xml:"numFmt,omitempty"`
  197. }
  198. // xlsxNumFmt directly maps the numFmt element. This element specifies number
  199. // format properties which indicate how to format and render the numeric value
  200. // of a cell.
  201. type xlsxNumFmt struct {
  202. NumFmtID int `xml:"numFmtId,attr,omitempty"`
  203. FormatCode string `xml:"formatCode,attr,omitempty"`
  204. }
  205. // xlsxStyleColors directly maps the colors element. Color information
  206. // associated with this stylesheet. This collection is written whenever the
  207. // legacy color palette has been modified (backwards compatibility settings) or
  208. // a custom color has been selected while using this workbook.
  209. type xlsxStyleColors struct {
  210. Color string `xml:",innerxml"`
  211. }
  212. // formatBorder directly maps the format settings of the borders.
  213. type formatBorder struct {
  214. Border []struct {
  215. Type string `json:"type"`
  216. Color string `json:"color"`
  217. Style int `json:"style"`
  218. } `json:"border"`
  219. }