xmlStyles.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. // Foreground color of the cell fill pattern. Cell fill patterns operate with
  43. // two colors: a background color and a foreground color. These combine together
  44. // to make a patterned cell fill. Background color of the cell fill pattern.
  45. // Cell fill patterns operate with two colors: a background color and a
  46. // foreground color. These combine together to make a patterned cell fill.
  47. type xlsxColor struct {
  48. Auto bool `xml:"auto,attr,omitempty"`
  49. RGB string `xml:"rgb,attr,omitempty"`
  50. Indexed *int `xml:"indexed,attr,omitempty"`
  51. Theme *int `xml:"theme,attr,omitempty"`
  52. Tint float64 `xml:"tint,attr,omitempty"`
  53. }
  54. // xlsxFonts directly maps the font element. This element contains all font
  55. // definitions for this workbook.
  56. type xlsxFonts struct {
  57. Count int `xml:"count,attr"`
  58. Font []*xlsxFont `xml:"font"`
  59. }
  60. // font directly maps the font element.
  61. type font struct {
  62. B bool `xml:"b,omitempty"`
  63. I bool `xml:"i,omitempty"`
  64. U *attrValString `xml:"u"`
  65. Sz *attrValInt `xml:"sz"`
  66. Color *xlsxColor `xml:"color"`
  67. Name *attrValString `xml:"name"`
  68. Family *attrValInt `xml:"family"`
  69. Scheme *attrValString `xml:"scheme"`
  70. }
  71. // xlsxFont directly maps the font element. This element defines the properties
  72. // for one of the fonts used in this workbook.
  73. type xlsxFont struct {
  74. Font string `xml:",innerxml"`
  75. }
  76. // xlsxFills directly maps the fills element. This element defines the cell
  77. // fills portion of the Styles part, consisting of a sequence of fill records. A
  78. // cell fill consists of a background color, foreground color, and pattern to be
  79. // applied across the cell.
  80. type xlsxFills struct {
  81. Count int `xml:"count,attr"`
  82. Fill []*xlsxFill `xml:"fill,omitempty"`
  83. }
  84. // xlsxFill directly maps the fill element. This element specifies fill
  85. // formatting.
  86. type xlsxFill struct {
  87. PatternFill *xlsxPatternFill `xml:"patternFill,omitempty"`
  88. GradientFill *xlsxGradientFill `xml:"gradientFill,omitempty"`
  89. }
  90. // xlsxPatternFill directly maps the patternFill element in the namespace
  91. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  92. // not checked it for completeness - it does as much as I need. This element is
  93. // used to specify cell fill information for pattern and solid color cell fills.
  94. // For solid cell fills (no pattern), fgColor is used. For cell fills with
  95. // patterns specified, then the cell fill color is specified by the bgColor
  96. // element.
  97. type xlsxPatternFill struct {
  98. PatternType string `xml:"patternType,attr,omitempty"`
  99. FgColor xlsxColor `xml:"fgColor,omitempty"`
  100. BgColor xlsxColor `xml:"bgColor,omitempty"`
  101. }
  102. // xlsxGradientFill defines a gradient-style cell fill. Gradient cell fills can
  103. // use one or two colors as the end points of color interpolation.
  104. type xlsxGradientFill struct {
  105. Bottom float64 `xml:"bottom,attr,omitempty"`
  106. Degree float64 `xml:"degree,attr,omitempty"`
  107. Left float64 `xml:"left,attr,omitempty"`
  108. Right float64 `xml:"right,attr,omitempty"`
  109. Top float64 `xml:"top,attr,omitempty"`
  110. Type string `xml:"type,attr,omitempty"`
  111. Stop []*xlsxGradientFillStop `xml:"stop,omitempty"`
  112. }
  113. // xlsxGradientFillStop directly maps the stop element.
  114. type xlsxGradientFillStop struct {
  115. Position float64 `xml:"position,attr"`
  116. Color xlsxColor `xml:"color,omitempty"`
  117. }
  118. // xlsxBorders directly maps the borders element. This element contains borders
  119. // formatting information, specifying all border definitions for all cells in
  120. // the workbook.
  121. type xlsxBorders struct {
  122. Count int `xml:"count,attr"`
  123. Border []*xlsxBorder `xml:"border,omitempty"`
  124. }
  125. // xlsxBorder directly maps the border element. Expresses a single set of cell
  126. // border formats (left, right, top, bottom, diagonal). Color is optional. When
  127. // missing, 'automatic' is implied.
  128. type xlsxBorder struct {
  129. DiagonalDown bool `xml:"diagonalDown,attr,omitempty"`
  130. DiagonalUp bool `xml:"diagonalUp,attr,omitempty"`
  131. Outline bool `xml:"outline,attr,omitempty"`
  132. Left xlsxLine `xml:"left,omitempty"`
  133. Right xlsxLine `xml:"right,omitempty"`
  134. Top xlsxLine `xml:"top,omitempty"`
  135. Bottom xlsxLine `xml:"bottom,omitempty"`
  136. Diagonal xlsxLine `xml:"diagonal,omitempty"`
  137. }
  138. // xlsxCellStyles directly maps the cellStyles element. This element contains
  139. // the named cell styles, consisting of a sequence of named style records. A
  140. // named cell style is a collection of direct or themed formatting (e.g., cell
  141. // border, cell fill, and font type/size/style) grouped together into a single
  142. // named style, and can be applied to a cell.
  143. type xlsxCellStyles struct {
  144. XMLName xml.Name `xml:"cellStyles"`
  145. Count int `xml:"count,attr"`
  146. CellStyle []*xlsxCellStyle `xml:"cellStyle,omitempty"`
  147. }
  148. // xlsxCellStyle directly maps the cellStyle element. This element represents
  149. // the name and related formatting records for a named cell style in this
  150. // workbook.
  151. type xlsxCellStyle struct {
  152. XMLName xml.Name `xml:"cellStyle"`
  153. BuiltInID *int `xml:"builtinId,attr,omitempty"`
  154. CustomBuiltIn *bool `xml:"customBuiltin,attr,omitempty"`
  155. Hidden *bool `xml:"hidden,attr,omitempty"`
  156. ILevel *bool `xml:"iLevel,attr,omitempty"`
  157. Name string `xml:"name,attr"`
  158. XfID int `xml:"xfId,attr"`
  159. }
  160. // xlsxCellStyleXfs directly maps the cellStyleXfs element. This element
  161. // contains the master formatting records (xf's) which define the formatting for
  162. // all named cell styles in this workbook. Master formatting records reference
  163. // individual elements of formatting (e.g., number format, font definitions,
  164. // cell fills, etc) by specifying a zero-based index into those collections.
  165. // Master formatting records also specify whether to apply or ignore particular
  166. // aspects of formatting.
  167. type xlsxCellStyleXfs struct {
  168. Count int `xml:"count,attr"`
  169. Xf []xlsxXf `xml:"xf,omitempty"`
  170. }
  171. // xlsxXf directly maps the xf element. A single xf element describes all of the
  172. // formatting for a cell.
  173. type xlsxXf struct {
  174. ApplyAlignment bool `xml:"applyAlignment,attr"`
  175. ApplyBorder bool `xml:"applyBorder,attr"`
  176. ApplyFill bool `xml:"applyFill,attr"`
  177. ApplyFont bool `xml:"applyFont,attr"`
  178. ApplyNumberFormat bool `xml:"applyNumberFormat,attr"`
  179. ApplyProtection bool `xml:"applyProtection,attr"`
  180. BorderID int `xml:"borderId,attr"`
  181. FillID int `xml:"fillId,attr"`
  182. FontID int `xml:"fontId,attr"`
  183. NumFmtID int `xml:"numFmtId,attr"`
  184. PivotButton bool `xml:"pivotButton,attr,omitempty"`
  185. QuotePrefix bool `xml:"quotePrefix,attr,omitempty"`
  186. XfID *int `xml:"xfId,attr,omitempty"`
  187. Alignment *xlsxAlignment `xml:"alignment"`
  188. }
  189. // xlsxCellXfs directly maps the cellXfs element. This element contains the
  190. // master formatting records (xf) which define the formatting applied to cells
  191. // in this workbook. These records are the starting point for determining the
  192. // formatting for a cell. Cells in the Sheet Part reference the xf records by
  193. // zero-based index.
  194. type xlsxCellXfs struct {
  195. Count int `xml:"count,attr"`
  196. Xf []xlsxXf `xml:"xf,omitempty"`
  197. }
  198. // xlsxDxfs directly maps the dxfs element. This element contains the master
  199. // differential formatting records (dxf's) which define formatting for all non-
  200. // cell formatting in this workbook. Whereas xf records fully specify a
  201. // particular aspect of formatting (e.g., cell borders) by referencing those
  202. // formatting definitions elsewhere in the Styles part, dxf records specify
  203. // incremental (or differential) aspects of formatting directly inline within
  204. // the dxf element. The dxf formatting is to be applied on top of or in addition
  205. // to any formatting already present on the object using the dxf record.
  206. type xlsxDxfs struct {
  207. Count int `xml:"count,attr"`
  208. Dxfs []*xlsxDxf `xml:"dxf,omitempty"`
  209. }
  210. // xlsxDxf directly maps the dxf element. A single dxf record, expressing
  211. // incremental formatting to be applied.
  212. type xlsxDxf struct {
  213. Dxf string `xml:",innerxml"`
  214. }
  215. // xlsxTableStyles directly maps the tableStyles element. This element
  216. // represents a collection of Table style definitions for Table styles and
  217. // PivotTable styles used in this workbook. It consists of a sequence of
  218. // tableStyle records, each defining a single Table style.
  219. type xlsxTableStyles struct {
  220. Count int `xml:"count,attr"`
  221. DefaultPivotStyle string `xml:"defaultPivotStyle,attr"`
  222. DefaultTableStyle string `xml:"defaultTableStyle,attr"`
  223. TableStyles []*xlsxTableStyle `xml:"tableStyle,omitempty"`
  224. }
  225. // xlsxTableStyle directly maps the tableStyle element. This element represents
  226. // a single table style definition that indicates how a spreadsheet application
  227. // should format and display a table.
  228. type xlsxTableStyle struct {
  229. Name string `xml:"name,attr,omitempty"`
  230. Pivot int `xml:"pivot,attr"`
  231. Count int `xml:"count,attr,omitempty"`
  232. Table bool `xml:"table,attr,omitempty"`
  233. TableStyleElement string `xml:",innerxml"`
  234. }
  235. // xlsxNumFmts directly maps the numFmts element. This element defines the
  236. // number formats in this workbook, consisting of a sequence of numFmt records,
  237. // where each numFmt record defines a particular number format, indicating how
  238. // to format and render the numeric value of a cell.
  239. type xlsxNumFmts struct {
  240. Count int `xml:"count,attr"`
  241. NumFmt []*xlsxNumFmt `xml:"numFmt,omitempty"`
  242. }
  243. // xlsxNumFmt directly maps the numFmt element. This element specifies number
  244. // format properties which indicate how to format and render the numeric value
  245. // of a cell.
  246. type xlsxNumFmt struct {
  247. NumFmtID int `xml:"numFmtId,attr,omitempty"`
  248. FormatCode string `xml:"formatCode,attr,omitempty"`
  249. }
  250. // xlsxStyleColors directly maps the colors element. Color information
  251. // associated with this stylesheet. This collection is written whenever the
  252. // legacy color palette has been modified (backwards compatibility settings) or
  253. // a custom color has been selected while using this workbook.
  254. type xlsxStyleColors struct {
  255. Color string `xml:",innerxml"`
  256. }
  257. // formatCellStyle directly maps the styles settings of the borders.
  258. type formatCellStyle struct {
  259. Border []struct {
  260. Type string `json:"type"`
  261. Color string `json:"color"`
  262. Style int `json:"style"`
  263. } `json:"border"`
  264. Fill struct {
  265. Type string `json:"type"`
  266. Pattern int `json:"pattern"`
  267. Color []string `json:"color"`
  268. Shading int `json:"shading"`
  269. } `json:"fill"`
  270. Font *struct {
  271. Bold bool `json:"bold"`
  272. Italic bool `json:"italic"`
  273. Underline string `json:"underline"`
  274. Family string `json:"family"`
  275. Size int `json:"size"`
  276. Color string `json:"color"`
  277. } `json:"font"`
  278. Alignment *struct {
  279. Horizontal string `json:"horizontal"`
  280. Indent int `json:"indent"`
  281. JustifyLastLine bool `json:"justify_last_line"`
  282. ReadingOrder uint64 `json:"reading_order"`
  283. RelativeIndent int `json:"relative_indent"`
  284. ShrinkToFit bool `json:"shrink_to_fit"`
  285. TextRotation int `json:"text_rotation"`
  286. Vertical string `json:"vertical"`
  287. WrapText bool `json:"wrap_text"`
  288. } `json:"alignment"`
  289. NumFmt int `json:"number_format"`
  290. }