xmlStyle.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. // xslx is a package designed to help with reading data from
  2. // spreadsheets stored in the XLSX format used in recent versions of
  3. // Microsoft's Excel spreadsheet.
  4. //
  5. // For a concise example of how to use this library why not check out
  6. // the source for xlsx2csv here: https://github.com/tealeg/xlsx2csv
  7. package xlsx
  8. import (
  9. "encoding/xml"
  10. "fmt"
  11. "strconv"
  12. "strings"
  13. )
  14. var (
  15. NumFmtRefTable map[int]xlsxNumFmt
  16. )
  17. // xlsxStyle directly maps the styleSheet element in the namespace
  18. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  19. // currently I have not checked it for completeness - it does as much
  20. // as I need.
  21. type xlsxStyleSheet struct {
  22. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main styleSheet"`
  23. Fonts xlsxFonts `xml:"fonts,omitempty"`
  24. Fills xlsxFills `xml:"fills,omitempty"`
  25. Borders xlsxBorders `xml:"borders,omitempty"`
  26. CellStyleXfs xlsxCellStyleXfs `xml:"cellStyleXfs,omitempty"`
  27. CellXfs xlsxCellXfs `xml:"cellXfs,omitempty"`
  28. NumFmts xlsxNumFmts `xml:"numFmts,omitempty"`
  29. }
  30. func (styles *xlsxStyleSheet) buildNumFmtRefTable() (numFmtRefTable map[int]xlsxNumFmt) {
  31. numFmtRefTable = make(map[int]xlsxNumFmt)
  32. for _, numFmt := range styles.NumFmts.NumFmt {
  33. numFmtRefTable[numFmt.NumFmtId] = numFmt
  34. }
  35. return numFmtRefTable
  36. }
  37. func (styles *xlsxStyleSheet) getStyle(styleIndex int) (style Style) {
  38. var styleXf xlsxXf
  39. style = Style{}
  40. style.Border = Border{}
  41. style.Fill = Fill{}
  42. style.Font = Font{}
  43. xfCount := styles.CellXfs.Count
  44. if styleIndex > -1 && xfCount > 0 && styleIndex <= xfCount {
  45. xf := styles.CellXfs.Xf[styleIndex]
  46. // Google docs can produce output that has fewer
  47. // CellStyleXfs than CellXfs - this copes with that.
  48. if styleIndex < styles.CellStyleXfs.Count {
  49. styleXf = styles.CellStyleXfs.Xf[styleIndex]
  50. } else {
  51. styleXf = xlsxXf{}
  52. }
  53. style.ApplyBorder = xf.ApplyBorder || styleXf.ApplyBorder
  54. style.ApplyFill = xf.ApplyFill || styleXf.ApplyFill
  55. style.ApplyFont = xf.ApplyFont || styleXf.ApplyFont
  56. if xf.BorderId > -1 && xf.BorderId < styles.Borders.Count {
  57. style.Border.Left = styles.Borders.Border[xf.BorderId].Left.Style
  58. style.Border.Right = styles.Borders.Border[xf.BorderId].Right.Style
  59. style.Border.Top = styles.Borders.Border[xf.BorderId].Top.Style
  60. style.Border.Bottom = styles.Borders.Border[xf.BorderId].Bottom.Style
  61. }
  62. if xf.FillId > -1 && xf.FillId < styles.Fills.Count {
  63. xFill := styles.Fills.Fill[xf.FillId]
  64. style.Fill.PatternType = xFill.PatternFill.PatternType
  65. style.Fill.FgColor = xFill.PatternFill.FgColor.RGB
  66. style.Fill.BgColor = xFill.PatternFill.BgColor.RGB
  67. }
  68. if xf.FontId > -1 && xf.FontId < styles.Fonts.Count {
  69. xfont := styles.Fonts.Font[xf.FontId]
  70. style.Font.Size, _ = strconv.Atoi(xfont.Sz.Val)
  71. style.Font.Name = xfont.Name.Val
  72. style.Font.Family, _ = strconv.Atoi(xfont.Family.Val)
  73. style.Font.Charset, _ = strconv.Atoi(xfont.Charset.Val)
  74. }
  75. }
  76. return style
  77. }
  78. func (styles *xlsxStyleSheet) getNumberFormat(styleIndex int) string {
  79. if styles.CellXfs.Xf == nil {
  80. return ""
  81. }
  82. var numberFormat string = ""
  83. if styleIndex > -1 && styleIndex <= styles.CellXfs.Count {
  84. xf := styles.CellXfs.Xf[styleIndex]
  85. numFmt := NumFmtRefTable[xf.NumFmtId]
  86. numberFormat = numFmt.FormatCode
  87. }
  88. return strings.ToLower(numberFormat)
  89. }
  90. func (styles *xlsxStyleSheet) addFont(xFont xlsxFont) (index int) {
  91. var font xlsxFont
  92. for index, font = range styles.Fonts.Font {
  93. if font.Equals(xFont) {
  94. return index
  95. }
  96. }
  97. styles.Fonts.Font = append(styles.Fonts.Font, xFont)
  98. index = styles.Fonts.Count
  99. styles.Fonts.Count += 1
  100. return
  101. }
  102. func (styles *xlsxStyleSheet) addFill(xFill xlsxFill) (index int) {
  103. styles.Fills.Fill = append(styles.Fills.Fill, xFill)
  104. index = styles.Fills.Count
  105. styles.Fills.Count += 1
  106. return
  107. }
  108. func (styles *xlsxStyleSheet) addBorder(xBorder xlsxBorder) (index int) {
  109. styles.Borders.Border = append(styles.Borders.Border, xBorder)
  110. index = styles.Borders.Count
  111. styles.Borders.Count += 1
  112. return
  113. }
  114. func (styles *xlsxStyleSheet) addCellStyleXf(xCellStyleXf xlsxXf) (index int) {
  115. styles.CellStyleXfs.Xf = append(styles.CellStyleXfs.Xf, xCellStyleXf)
  116. index = styles.CellStyleXfs.Count
  117. styles.CellStyleXfs.Count += 1
  118. return
  119. }
  120. func (styles *xlsxStyleSheet) addCellXf(xCellXf xlsxXf) (index int) {
  121. styles.CellXfs.Xf = append(styles.CellXfs.Xf, xCellXf)
  122. index = styles.CellXfs.Count
  123. styles.CellXfs.Count += 1
  124. return
  125. }
  126. func (styles *xlsxStyleSheet) addNumFmt(xNumFmt xlsxNumFmt) (index int) {
  127. numFmt, ok := NumFmtRefTable[xNumFmt.NumFmtId]
  128. if !ok {
  129. if NumFmtRefTable == nil {
  130. NumFmtRefTable = make(map[int]xlsxNumFmt)
  131. }
  132. styles.NumFmts.NumFmt = append(styles.NumFmts.NumFmt, xNumFmt)
  133. NumFmtRefTable[xNumFmt.NumFmtId] = xNumFmt
  134. index = styles.NumFmts.Count
  135. styles.NumFmts.Count += 1
  136. return
  137. }
  138. numFmt.FormatCode = xNumFmt.FormatCode
  139. return
  140. }
  141. func (styles *xlsxStyleSheet) Marshal() (result string, err error) {
  142. var xNumFmts string
  143. var xfonts string
  144. var xfills string
  145. var xborders string
  146. var xcellStyleXfs string
  147. var xcellXfs string
  148. var outputFontMap map[int]int = make(map[int]int)
  149. var outputFillMap map[int]int = make(map[int]int)
  150. var outputBorderMap map[int]int = make(map[int]int)
  151. result = xml.Header
  152. result += `<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`
  153. xNumFmts, err = styles.NumFmts.Marshal()
  154. if err != nil {
  155. return
  156. }
  157. result += xNumFmts
  158. xfonts, err = styles.Fonts.Marshal(outputFontMap)
  159. if err != nil {
  160. return
  161. }
  162. result += xfonts
  163. xfills, err = styles.Fills.Marshal(outputFillMap)
  164. if err != nil {
  165. return
  166. }
  167. result += xfills
  168. xborders, err = styles.Borders.Marshal(outputBorderMap)
  169. if err != nil {
  170. return
  171. }
  172. result += xborders
  173. xcellStyleXfs, err = styles.CellStyleXfs.Marshal(outputBorderMap, outputFillMap, outputFontMap)
  174. if err != nil {
  175. return
  176. }
  177. result += xcellStyleXfs
  178. xcellXfs, err = styles.CellXfs.Marshal(outputBorderMap, outputFillMap, outputFontMap)
  179. if err != nil {
  180. return
  181. }
  182. result += xcellXfs
  183. result += `</styleSheet>`
  184. return
  185. }
  186. // xlsxNumFmts directly maps the numFmts element in the namespace
  187. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  188. // currently I have not checked it for completeness - it does as much
  189. // as I need.
  190. type xlsxNumFmts struct {
  191. Count int `xml:"count,attr"`
  192. NumFmt []xlsxNumFmt `xml:"numFmt,omitempty"`
  193. }
  194. func (numFmts *xlsxNumFmts) Marshal() (result string, err error) {
  195. if numFmts.Count > 0 {
  196. result = fmt.Sprintf(`<numFmts count="%d">`, numFmts.Count)
  197. for _, numFmt := range numFmts.NumFmt {
  198. var xNumFmt string
  199. xNumFmt, err = numFmt.Marshal()
  200. if err != nil {
  201. return
  202. }
  203. result += xNumFmt
  204. }
  205. result += `</numFmts>`
  206. }
  207. return
  208. }
  209. // xlsxNumFmt directly maps the numFmt element in the namespace
  210. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  211. // currently I have not checked it for completeness - it does as much
  212. // as I need.
  213. type xlsxNumFmt struct {
  214. NumFmtId int `xml:"numFmtId,omitempty"`
  215. FormatCode string `xml:"formatCode,omitempty"`
  216. }
  217. func (numFmt *xlsxNumFmt) Marshal() (result string, err error) {
  218. return fmt.Sprintf(`<numFmt numFmtId="%d" formatCode="%s"/>`, numFmt.NumFmtId, numFmt.FormatCode), nil
  219. }
  220. // xlsxFonts directly maps the fonts element in the namespace
  221. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  222. // currently I have not checked it for completeness - it does as much
  223. // as I need.
  224. type xlsxFonts struct {
  225. XMLName xml.Name `xml:"fonts"`
  226. Count int `xml:"count,attr"`
  227. Font []xlsxFont `xml:"font,omitempty"`
  228. }
  229. func (fonts *xlsxFonts) Marshal(outputFontMap map[int]int) (result string, err error) {
  230. emittedCount := 0
  231. subparts := ""
  232. for i, font := range fonts.Font {
  233. var xfont string
  234. xfont, err = font.Marshal()
  235. if err != nil {
  236. return
  237. }
  238. if xfont != "" {
  239. outputFontMap[i] = emittedCount
  240. emittedCount += 1
  241. subparts += xfont
  242. }
  243. }
  244. if emittedCount > 0 {
  245. result = fmt.Sprintf(`<fonts count="%d">`, fonts.Count)
  246. result += subparts
  247. result += `</fonts>`
  248. }
  249. return
  250. }
  251. // xlsxFont directly maps the font element in the namespace
  252. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  253. // currently I have not checked it for completeness - it does as much
  254. // as I need.
  255. type xlsxFont struct {
  256. Sz xlsxVal `xml:"sz,omitempty"`
  257. Name xlsxVal `xml:"name,omitempty"`
  258. Family xlsxVal `xml:"family,omitempty"`
  259. Charset xlsxVal `xml:"charset,omitempty"`
  260. Color xlsxColor `xml:"color,omitempty"`
  261. }
  262. func (font *xlsxFont) Equals(other xlsxFont) bool {
  263. return font.Sz.Val == other.Sz.Val && font.Name.Val == other.Name.Val && font.Family.Val == other.Family.Val && font.Charset.Val == other.Charset.Val && font.Color.RGB == other.Color.RGB
  264. }
  265. func (font *xlsxFont) Marshal() (result string, err error) {
  266. result = `<font>`
  267. if font.Sz.Val != "" {
  268. result += fmt.Sprintf(`<sz val="%s"/>`, font.Sz.Val)
  269. }
  270. if font.Name.Val != "" {
  271. result += fmt.Sprintf(`<name val="%s"/>`, font.Name.Val)
  272. }
  273. if font.Family.Val != "" {
  274. result += fmt.Sprintf(`<family val="%s"/>`, font.Family.Val)
  275. }
  276. if font.Charset.Val != "" {
  277. result += fmt.Sprintf(`<charset val="%s"/>`, font.Charset.Val)
  278. }
  279. if font.Color.RGB != "" {
  280. result += fmt.Sprintf(`<color rgb="%s"/>`, font.Color.RGB)
  281. }
  282. result += `</font>`
  283. return
  284. }
  285. // xlsxVal directly maps the val element in the namespace
  286. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  287. // currently I have not checked it for completeness - it does as much
  288. // as I need.
  289. type xlsxVal struct {
  290. Val string `xml:"val,attr,omitempty"`
  291. }
  292. // xlsxFills directly maps the fills element in the namespace
  293. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  294. // currently I have not checked it for completeness - it does as much
  295. // as I need.
  296. type xlsxFills struct {
  297. Count int `xml:"count,attr"`
  298. Fill []xlsxFill `xml:"fill,omitempty"`
  299. }
  300. func (fills *xlsxFills) Marshal(outputFillMap map[int]int) (result string, err error) {
  301. emittedCount := 0
  302. subparts := ""
  303. for i, fill := range fills.Fill {
  304. var xfill string
  305. xfill, err = fill.Marshal()
  306. if err != nil {
  307. return
  308. }
  309. if xfill != "" {
  310. outputFillMap[i] = emittedCount
  311. emittedCount += 1
  312. subparts += xfill
  313. }
  314. }
  315. if emittedCount > 0 {
  316. result = fmt.Sprintf(`<fills count="%d">`, emittedCount)
  317. result += subparts
  318. result += `</fills>`
  319. }
  320. return
  321. }
  322. // xlsxFill directly maps the fill element in the namespace
  323. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  324. // currently I have not checked it for completeness - it does as much
  325. // as I need.
  326. type xlsxFill struct {
  327. PatternFill xlsxPatternFill `xml:"patternFill,omitempty"`
  328. }
  329. func (fill *xlsxFill) Marshal() (result string, err error) {
  330. if fill.PatternFill.PatternType != "" {
  331. var xpatternFill string
  332. result = `<fill>`
  333. xpatternFill, err = fill.PatternFill.Marshal()
  334. if err != nil {
  335. return
  336. }
  337. result += xpatternFill
  338. result += `</fill>`
  339. }
  340. return
  341. }
  342. // xlsxPatternFill directly maps the patternFill element in the namespace
  343. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  344. // currently I have not checked it for completeness - it does as much
  345. // as I need.
  346. type xlsxPatternFill struct {
  347. PatternType string `xml:"patternType,attr,omitempty"`
  348. FgColor xlsxColor `xml:"fgColor,omitempty"`
  349. BgColor xlsxColor `xml:"bgColor,omitempty"`
  350. }
  351. func (patternFill *xlsxPatternFill) Marshal() (result string, err error) {
  352. result = fmt.Sprintf(`<patternFill patternType="%s"`, patternFill.PatternType)
  353. ending := `/>`
  354. subparts := ""
  355. if patternFill.FgColor.RGB != "" {
  356. ending = `>`
  357. subparts += fmt.Sprintf(`<fgColor rgb="%s"/>`, patternFill.FgColor.RGB)
  358. }
  359. if patternFill.BgColor.RGB != "" {
  360. ending = `>`
  361. subparts += fmt.Sprintf(`<bgColor rgb="%s"/>`, patternFill.BgColor.RGB)
  362. }
  363. result += ending
  364. result += subparts
  365. result += `</patternFill>`
  366. return
  367. }
  368. // xlsxColor is a common mapping used for both the fgColor and bgColor
  369. // elements in the namespace
  370. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  371. // currently I have not checked it for completeness - it does as much
  372. // as I need.
  373. type xlsxColor struct {
  374. RGB string `xml:"rgb,attr,omitempty"`
  375. }
  376. // xlsxBorders directly maps the borders element in the namespace
  377. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  378. // currently I have not checked it for completeness - it does as much
  379. // as I need.
  380. type xlsxBorders struct {
  381. Count int `xml:"count,attr"`
  382. Border []xlsxBorder `xml:"border,omitempty"`
  383. }
  384. func (borders *xlsxBorders) Marshal(outputBorderMap map[int]int) (result string, err error) {
  385. result = ""
  386. emittedCount := 0
  387. subparts := ""
  388. for i, border := range borders.Border {
  389. var xborder string
  390. xborder, err = border.Marshal()
  391. if err != nil {
  392. return
  393. }
  394. if xborder != "" {
  395. outputBorderMap[i] = emittedCount
  396. emittedCount += 1
  397. subparts += xborder
  398. }
  399. }
  400. if emittedCount > 0 {
  401. result += fmt.Sprintf(`<borders count="%d">`, emittedCount)
  402. result += subparts
  403. result += `</borders>`
  404. }
  405. return
  406. }
  407. // xlsxBorder directly maps the border element in the namespace
  408. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  409. // currently I have not checked it for completeness - it does as much
  410. // as I need.
  411. type xlsxBorder struct {
  412. Left xlsxLine `xml:"left,omitempty"`
  413. Right xlsxLine `xml:"right,omitempty"`
  414. Top xlsxLine `xml:"top,omitempty"`
  415. Bottom xlsxLine `xml:"bottom,omitempty"`
  416. }
  417. func (border *xlsxBorder) Marshal() (result string, err error) {
  418. emit := false
  419. subparts := ""
  420. if border.Left.Style != "" {
  421. emit = true
  422. subparts += fmt.Sprintf(`<left style="%s"/>`, border.Left.Style)
  423. }
  424. if border.Right.Style != "" {
  425. emit = true
  426. subparts += fmt.Sprintf(`<right style="%s"/>`, border.Right.Style)
  427. }
  428. if border.Top.Style != "" {
  429. emit = true
  430. subparts += fmt.Sprintf(`<top style="%s"/>`, border.Top.Style)
  431. }
  432. if border.Bottom.Style != "" {
  433. emit = true
  434. subparts += fmt.Sprintf(`<bottom style="%s"/>`, border.Bottom.Style)
  435. }
  436. if emit {
  437. result += `<border>`
  438. result += subparts
  439. result += `</border>`
  440. }
  441. return
  442. }
  443. // xlsxLine directly maps the line style element in the namespace
  444. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  445. // currently I have not checked it for completeness - it does as much
  446. // as I need.
  447. type xlsxLine struct {
  448. Style string `xml:"style,attr,omitempty"`
  449. }
  450. // xlsxCellStyleXfs directly maps the cellStyleXfs element in the
  451. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  452. // - currently I have not checked it for completeness - it does as
  453. // much as I need.
  454. type xlsxCellStyleXfs struct {
  455. Count int `xml:"count,attr"`
  456. Xf []xlsxXf `xml:"xf,omitempty"`
  457. }
  458. func (cellStyleXfs *xlsxCellStyleXfs) Marshal(outputBorderMap, outputFillMap, outputFontMap map[int]int) (result string, err error) {
  459. if cellStyleXfs.Count > 0 {
  460. result = fmt.Sprintf(`<cellStyleXfs count="%d">`, cellStyleXfs.Count)
  461. for _, xf := range cellStyleXfs.Xf {
  462. var xxf string
  463. xxf, err = xf.Marshal(outputBorderMap, outputFillMap, outputFontMap)
  464. if err != nil {
  465. return
  466. }
  467. result += xxf
  468. }
  469. result += `</cellStyleXfs>`
  470. }
  471. return
  472. }
  473. // xlsxCellXfs directly maps the cellXfs element in the namespace
  474. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  475. // currently I have not checked it for completeness - it does as much
  476. // as I need.
  477. type xlsxCellXfs struct {
  478. Count int `xml:"count,attr"`
  479. Xf []xlsxXf `xml:"xf,omitempty"`
  480. }
  481. func (cellXfs *xlsxCellXfs) Marshal(outputBorderMap, outputFillMap, outputFontMap map[int]int) (result string, err error) {
  482. if cellXfs.Count > 0 {
  483. result = fmt.Sprintf(`<cellXfs count="%d">`, cellXfs.Count)
  484. for _, xf := range cellXfs.Xf {
  485. var xxf string
  486. xxf, err = xf.Marshal(outputBorderMap, outputFillMap, outputFontMap)
  487. if err != nil {
  488. return
  489. }
  490. result += xxf
  491. }
  492. result += `</cellXfs>`
  493. }
  494. return
  495. }
  496. // xlsxXf directly maps the xf element in the namespace
  497. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  498. // currently I have not checked it for completeness - it does as much
  499. // as I need.
  500. type xlsxXf struct {
  501. ApplyAlignment bool `xml:"applyAlignment,attr"`
  502. ApplyBorder bool `xml:"applyBorder,attr"`
  503. ApplyFont bool `xml:"applyFont,attr"`
  504. ApplyFill bool `xml:"applyFill,attr"`
  505. ApplyProtection bool `xml:"applyProtection,attr"`
  506. BorderId int `xml:"borderId,attr"`
  507. FillId int `xml:"fillId,attr"`
  508. FontId int `xml:"fontId,attr"`
  509. NumFmtId int `xml:"numFmtId,attr"`
  510. alignment xlsxAlignment `xml:"alignment"`
  511. }
  512. func (xf *xlsxXf) Marshal(outputBorderMap, outputFillMap, outputFontMap map[int]int) (result string, err error) {
  513. var xalignment string
  514. result = fmt.Sprintf(`<xf applyAlignment="%t" applyBorder="%t" applyFont="%t" applyFill="%t" applyProtection="%t" borderId="%d" fillId="%d" fontId="%d" numFmtId="%d">`, xf.ApplyAlignment, xf.ApplyBorder, xf.ApplyFont, xf.ApplyFill, xf.ApplyProtection, outputBorderMap[xf.BorderId], outputFillMap[xf.FillId], outputFontMap[xf.FontId], xf.NumFmtId)
  515. xalignment, err = xf.alignment.Marshal()
  516. if err != nil {
  517. return
  518. }
  519. result += xalignment
  520. result += `</xf>`
  521. return
  522. }
  523. type xlsxAlignment struct {
  524. Horizontal string `xml:"horizontal,attr"`
  525. Indent int `xml:"indent,attr"`
  526. ShrinkToFit bool `xml:"shrinkToFit,attr"`
  527. TextRotation int `xml:"textRotation,attr"`
  528. Vertical string `xml:"vertical,attr"`
  529. WrapText bool `xml:"wrapText,attr"`
  530. }
  531. func (alignment *xlsxAlignment) Marshal() (result string, err error) {
  532. result = fmt.Sprintf(`<alignment horizontal="%s" indent="%d" shrinkToFit="%t" textRotation="%d" vertical="%s" wrapText="%t"/>`, alignment.Horizontal, alignment.Indent, alignment.ShrinkToFit, alignment.TextRotation, alignment.Vertical, alignment.WrapText)
  533. return
  534. }