xmlStyles.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. Indexed *int `xml:"indexed,attr,omitempty"`
  47. Theme *int `xml:"theme,attr,omitempty"`
  48. Tint float64 `xml:"tint,attr,omitempty"`
  49. }
  50. // xlsxFonts directly maps the fonts element. This element contains all font
  51. // definitions for this workbook.
  52. type xlsxFonts struct {
  53. Count int `xml:"count,attr"`
  54. Font []*xlsxFont `xml:"font,omitempty"`
  55. }
  56. // xlsxFont directly maps the font element. This element defines the properties
  57. // for one of the fonts used in this workbook.
  58. type xlsxFont struct {
  59. Font string `xml:",innerxml"`
  60. }
  61. // xlsxFills directly maps the fills element. This element defines the cell
  62. // fills portion of the Styles part, consisting of a sequence of fill records. A
  63. // cell fill consists of a background color, foreground color, and pattern to be
  64. // applied across the cell.
  65. type xlsxFills struct {
  66. Count int `xml:"count,attr"`
  67. Fill []xlsxFill `xml:"fill,omitempty"`
  68. }
  69. // xlsxFill directly maps the fill element. This element specifies fill
  70. // formatting.
  71. type xlsxFill struct {
  72. PatternFill xlsxPatternFill `xml:"patternFill,omitempty"`
  73. }
  74. // xlsxPatternFill directly maps the patternFill element in the namespace
  75. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  76. // not checked it for completeness - it does as much as I need. This element is
  77. // used to specify cell fill information for pattern and solid color cell fills.
  78. // For solid cell fills (no pattern), fgColor is used. For cell fills with
  79. // patterns specified, then the cell fill color is specified by the bgColor
  80. // element.
  81. type xlsxPatternFill struct {
  82. PatternType string `xml:"patternType,attr,omitempty"`
  83. FgColor xlsxColor `xml:"fgColor,omitempty"`
  84. BgColor xlsxColor `xml:"bgColor,omitempty"`
  85. }
  86. // xlsxBorders directly maps the borders element. This element contains borders
  87. // formatting information, specifying all border definitions for all cells in
  88. // the workbook.
  89. type xlsxBorders struct {
  90. Count int `xml:"count,attr"`
  91. Border []*xlsxBorder `xml:"border,omitempty"`
  92. }
  93. // xlsxBorder directly maps the border element. Expresses a single set of cell
  94. // border formats (left, right, top, bottom, diagonal). Color is optional. When
  95. // missing, 'automatic' is implied.
  96. type xlsxBorder struct {
  97. DiagonalDown bool `xml:"diagonalDown,attr,omitempty"`
  98. DiagonalUp bool `xml:"diagonalUp,attr,omitempty"`
  99. Outline bool `xml:"outline,attr,omitempty"`
  100. Left xlsxLine `xml:"left,omitempty"`
  101. Right xlsxLine `xml:"right,omitempty"`
  102. Top xlsxLine `xml:"top,omitempty"`
  103. Bottom xlsxLine `xml:"bottom,omitempty"`
  104. Diagonal xlsxLine `xml:"diagonal,omitempty"`
  105. }
  106. // xlsxCellStyles directly maps the cellStyles element. This element contains
  107. // the named cell styles, consisting of a sequence of named style records. A
  108. // named cell style is a collection of direct or themed formatting (e.g., cell
  109. // border, cell fill, and font type/size/style) grouped together into a single
  110. // named style, and can be applied to a cell.
  111. type xlsxCellStyles struct {
  112. XMLName xml.Name `xml:"cellStyles"`
  113. Count int `xml:"count,attr"`
  114. CellStyle []*xlsxCellStyle `xml:"cellStyle,omitempty"`
  115. }
  116. // xlsxCellStyle directly maps the cellStyle element. This element represents
  117. // the name and related formatting records for a named cell style in this
  118. // workbook.
  119. type xlsxCellStyle struct {
  120. XMLName xml.Name `xml:"cellStyle"`
  121. BuiltInID *int `xml:"builtinId,attr,omitempty"`
  122. CustomBuiltIn *bool `xml:"customBuiltin,attr,omitempty"`
  123. Hidden *bool `xml:"hidden,attr,omitempty"`
  124. ILevel *bool `xml:"iLevel,attr,omitempty"`
  125. Name string `xml:"name,attr"`
  126. XfID int `xml:"xfId,attr"`
  127. }
  128. // xlsxCellStyleXfs directly maps the cellStyleXfs element. This element
  129. // contains the master formatting records (xf's) which define the formatting for
  130. // all named cell styles in this workbook. Master formatting records reference
  131. // individual elements of formatting (e.g., number format, font definitions,
  132. // cell fills, etc) by specifying a zero-based index into those collections.
  133. // Master formatting records also specify whether to apply or ignore particular
  134. // aspects of formatting.
  135. type xlsxCellStyleXfs struct {
  136. Count int `xml:"count,attr"`
  137. Xf []xlsxXf `xml:"xf,omitempty"`
  138. }
  139. // xlsxXf directly maps the xf element. A single xf element describes all of the
  140. // formatting for a cell.
  141. type xlsxXf struct {
  142. ApplyAlignment bool `xml:"applyAlignment,attr"`
  143. ApplyBorder bool `xml:"applyBorder,attr"`
  144. ApplyFill bool `xml:"applyFill,attr"`
  145. ApplyFont bool `xml:"applyFont,attr"`
  146. ApplyNumberFormat bool `xml:"applyNumberFormat,attr"`
  147. ApplyProtection bool `xml:"applyProtection,attr"`
  148. BorderID int `xml:"borderId,attr"`
  149. FillID int `xml:"fillId,attr"`
  150. FontID int `xml:"fontId,attr"`
  151. NumFmtID int `xml:"numFmtId,attr"`
  152. PivotButton bool `xml:"pivotButton,attr,omitempty"`
  153. QuotePrefix bool `xml:"quotePrefix,attr,omitempty"`
  154. XfID *int `xml:"xfId,attr,omitempty"`
  155. Alignment *xlsxAlignment `xml:"alignment"`
  156. }
  157. // xlsxCellXfs directly maps the cellXfs element. This element contains the
  158. // master formatting records (xf) which define the formatting applied to cells
  159. // in this workbook. These records are the starting point for determining the
  160. // formatting for a cell. Cells in the Sheet Part reference the xf records by
  161. // zero-based index.
  162. type xlsxCellXfs struct {
  163. Count int `xml:"count,attr"`
  164. Xf []xlsxXf `xml:"xf,omitempty"`
  165. }
  166. // xlsxDxfs directly maps the dxfs element. This element contains the master
  167. // differential formatting records (dxf's) which define formatting for all non-
  168. // cell formatting in this workbook. Whereas xf records fully specify a
  169. // particular aspect of formatting (e.g., cell borders) by referencing those
  170. // formatting definitions elsewhere in the Styles part, dxf records specify
  171. // incremental (or differential) aspects of formatting directly inline within
  172. // the dxf element. The dxf formatting is to be applied on top of or in addition
  173. // to any formatting already present on the object using the dxf record.
  174. type xlsxDxfs struct {
  175. Count int `xml:"count,attr"`
  176. Dxfs []*xlsxDxf `xml:"dxf,omitempty"`
  177. }
  178. // xlsxDxf directly maps the dxf element. A single dxf record, expressing
  179. // incremental formatting to be applied.
  180. type xlsxDxf struct {
  181. Dxf string `xml:",innerxml"`
  182. }
  183. // xlsxTableStyles directly maps the tableStyles element. This element
  184. // represents a collection of Table style definitions for Table styles and
  185. // PivotTable styles used in this workbook. It consists of a sequence of
  186. // tableStyle records, each defining a single Table style.
  187. type xlsxTableStyles struct {
  188. Count int `xml:"count,attr"`
  189. DefaultPivotStyle string `xml:"defaultPivotStyle,attr"`
  190. DefaultTableStyle string `xml:"defaultTableStyle,attr"`
  191. TableStyles []*xlsxTableStyle `xml:"tableStyle,omitempty"`
  192. }
  193. // xlsxTableStyle directly maps the tableStyle element. This element represents
  194. // a single table style definition that indicates how a spreadsheet application
  195. // should format and display a table.
  196. type xlsxTableStyle struct {
  197. Name string `xml:"name,attr,omitempty"`
  198. Pivot int `xml:"pivot,attr"`
  199. Count int `xml:"count,attr,omitempty"`
  200. Table bool `xml:"table,attr,omitempty"`
  201. TableStyleElement string `xml:",innerxml"`
  202. }
  203. // xlsxNumFmts directly maps the numFmts element. This element defines the
  204. // number formats in this workbook, consisting of a sequence of numFmt records,
  205. // where each numFmt record defines a particular number format, indicating how
  206. // to format and render the numeric value of a cell.
  207. type xlsxNumFmts struct {
  208. Count int `xml:"count,attr"`
  209. NumFmt []*xlsxNumFmt `xml:"numFmt,omitempty"`
  210. }
  211. // xlsxNumFmt directly maps the numFmt element. This element specifies number
  212. // format properties which indicate how to format and render the numeric value
  213. // of a cell.
  214. type xlsxNumFmt struct {
  215. NumFmtID int `xml:"numFmtId,attr,omitempty"`
  216. FormatCode string `xml:"formatCode,attr,omitempty"`
  217. }
  218. // xlsxStyleColors directly maps the colors element. Color information
  219. // associated with this stylesheet. This collection is written whenever the
  220. // legacy color palette has been modified (backwards compatibility settings) or
  221. // a custom color has been selected while using this workbook.
  222. type xlsxStyleColors struct {
  223. Color string `xml:",innerxml"`
  224. }
  225. // formatBorder directly maps the format settings of the borders.
  226. type formatBorder struct {
  227. Border []struct {
  228. Type string `json:"type"`
  229. Color string `json:"color"`
  230. Style int `json:"style"`
  231. } `json:"border"`
  232. }