xmlStyles.go 15 KB

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