styles.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. package excelize
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "strconv"
  6. "strings"
  7. )
  8. // Excel styles can reference number formats that are built-in, all of which
  9. // have an id less than 164. This is a possibly incomplete list comprised of as
  10. // many of them as I could find.
  11. var builtInNumFmt = map[int]string{
  12. 0: "general",
  13. 1: "0",
  14. 2: "0.00",
  15. 3: "#,##0",
  16. 4: "#,##0.00",
  17. 9: "0%",
  18. 10: "0.00%",
  19. 11: "0.00e+00",
  20. 12: "# ?/?",
  21. 13: "# ??/??",
  22. 14: "mm-dd-yy",
  23. 15: "d-mmm-yy",
  24. 16: "d-mmm",
  25. 17: "mmm-yy",
  26. 18: "h:mm am/pm",
  27. 19: "h:mm:ss am/pm",
  28. 20: "h:mm",
  29. 21: "h:mm:ss",
  30. 22: "m/d/yy h:mm",
  31. 37: "#,##0 ;(#,##0)",
  32. 38: "#,##0 ;[red](#,##0)",
  33. 39: "#,##0.00;(#,##0.00)",
  34. 40: "#,##0.00;[red](#,##0.00)",
  35. 41: `_(* #,##0_);_(* \(#,##0\);_(* "-"_);_(@_)`,
  36. 42: `_("$"* #,##0_);_("$* \(#,##0\);_("$"* "-"_);_(@_)`,
  37. 43: `_(* #,##0.00_);_(* \(#,##0.00\);_(* "-"??_);_(@_)`,
  38. 44: `_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)`,
  39. 45: "mm:ss",
  40. 46: "[h]:mm:ss",
  41. 47: "mmss.0",
  42. 48: "##0.0e+0",
  43. 49: "@",
  44. }
  45. // parseFormatStyleSet provides function to parse the format settings of the
  46. // borders.
  47. func parseFormatStyleSet(style string) (*formatCellStyle, error) {
  48. var format formatCellStyle
  49. err := json.Unmarshal([]byte(style), &format)
  50. return &format, err
  51. }
  52. // SetCellStyle provides function to set style for cells by given sheet index
  53. // and coordinate area in XLSX file. Note that the color field uses RGB color
  54. // code and diagonalDown and diagonalUp type border should be use same color in
  55. // the same coordinate area.
  56. //
  57. // For example create a borders of cell H9 on Sheet1:
  58. //
  59. // err := xlsx.SetCellStyle("Sheet1", "H9", "H9", `{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`)
  60. // if err != nil {
  61. // fmt.Println(err)
  62. // }
  63. //
  64. // Set gradient fill with vertical variants shading styles for cell H9 on
  65. // Sheet1:
  66. //
  67. // err := xlsx.SetCellStyle("Sheet1", "H9", "H9", `{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
  68. // if err != nil {
  69. // fmt.Println(err)
  70. // }
  71. //
  72. // Set solid style pattern fill for cell H9 on Sheet1:
  73. //
  74. // err := xlsx.SetCellStyle("Sheet1", "H9", "H9", `{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
  75. // if err != nil {
  76. // fmt.Println(err)
  77. // }
  78. //
  79. // Set alignment style for cell H9 on Sheet1:
  80. //
  81. // err = xlsx.SetCellStyle("Sheet1", "H9", "H9", `{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`)
  82. // if err != nil {
  83. // fmt.Println(err)
  84. // }
  85. //
  86. // Dates and times in Excel are represented by real numbers, for example "Apr 7
  87. // 2017 12:00 PM" is represented by the number 42920.5. Set date and time format
  88. // for cell H9 on Sheet1:
  89. //
  90. // xlsx.SetCellValue("Sheet2", "H9", 42920.5)
  91. // err = xlsx.SetCellStyle("Sheet1", "H9", "H9", `{"number_format": 22}`)
  92. // if err != nil {
  93. // fmt.Println(err)
  94. // }
  95. //
  96. // The following shows the border styles sorted by excelize index number:
  97. //
  98. // +-------+---------------+--------+-----------------+
  99. // | Index | Name | Weight | Style |
  100. // +=======+===============+========+=================+
  101. // | 0 | None | 0 | |
  102. // +-------+---------------+--------+-----------------+
  103. // | 1 | Continuous | 1 | ``-----------`` |
  104. // +-------+---------------+--------+-----------------+
  105. // | 2 | Continuous | 2 | ``-----------`` |
  106. // +-------+---------------+--------+-----------------+
  107. // | 3 | Dash | 1 | ``- - - - - -`` |
  108. // +-------+---------------+--------+-----------------+
  109. // | 4 | Dot | 1 | ``. . . . . .`` |
  110. // +-------+---------------+--------+-----------------+
  111. // | 5 | Continuous | 3 | ``-----------`` |
  112. // +-------+---------------+--------+-----------------+
  113. // | 6 | Double | 3 | ``===========`` |
  114. // +-------+---------------+--------+-----------------+
  115. // | 7 | Continuous | 0 | ``-----------`` |
  116. // +-------+---------------+--------+-----------------+
  117. // | 8 | Dash | 2 | ``- - - - - -`` |
  118. // +-------+---------------+--------+-----------------+
  119. // | 9 | Dash Dot | 1 | ``- . - . - .`` |
  120. // +-------+---------------+--------+-----------------+
  121. // | 10 | Dash Dot | 2 | ``- . - . - .`` |
  122. // +-------+---------------+--------+-----------------+
  123. // | 11 | Dash Dot Dot | 1 | ``- . . - . .`` |
  124. // +-------+---------------+--------+-----------------+
  125. // | 12 | Dash Dot Dot | 2 | ``- . . - . .`` |
  126. // +-------+---------------+--------+-----------------+
  127. // | 13 | SlantDash Dot | 2 | ``/ - . / - .`` |
  128. // +-------+---------------+--------+-----------------+
  129. //
  130. // The following shows the borders in the order shown in the Excel dialog:
  131. //
  132. // +-------+-----------------+-------+-----------------+
  133. // | Index | Style | Index | Style |
  134. // +=======+=================+=======+=================+
  135. // | 0 | None | 12 | ``- . . - . .`` |
  136. // +-------+-----------------+-------+-----------------+
  137. // | 7 | ``-----------`` | 13 | ``/ - . / - .`` |
  138. // +-------+-----------------+-------+-----------------+
  139. // | 4 | ``. . . . . .`` | 10 | ``- . - . - .`` |
  140. // +-------+-----------------+-------+-----------------+
  141. // | 11 | ``- . . - . .`` | 8 | ``- - - - - -`` |
  142. // +-------+-----------------+-------+-----------------+
  143. // | 9 | ``- . - . - .`` | 2 | ``-----------`` |
  144. // +-------+-----------------+-------+-----------------+
  145. // | 3 | ``- - - - - -`` | 5 | ``-----------`` |
  146. // +-------+-----------------+-------+-----------------+
  147. // | 1 | ``-----------`` | 6 | ``===========`` |
  148. // +-------+-----------------+-------+-----------------+
  149. //
  150. // The following shows the shading styles sorted by excelize index number:
  151. //
  152. // +-------+-----------------+-------+-----------------+
  153. // | Index | Style | Index | Style |
  154. // +=======+=================+=======+=================+
  155. // | 0 | Horizontal | 3 | Diagonal down |
  156. // +-------+-----------------+-------+-----------------+
  157. // | 1 | Vertical | 4 | From corner |
  158. // +-------+-----------------+-------+-----------------+
  159. // | 2 | Diagonal Up | 5 | From center |
  160. // +-------+-----------------+-------+-----------------+
  161. //
  162. // The following shows the patterns styles sorted by excelize index number:
  163. //
  164. // +-------+-----------------+-------+-----------------+
  165. // | Index | Style | Index | Style |
  166. // +=======+=================+=======+=================+
  167. // | 0 | None | 10 | darkTrellis |
  168. // +-------+-----------------+-------+-----------------+
  169. // | 1 | solid | 11 | lightHorizontal |
  170. // +-------+-----------------+-------+-----------------+
  171. // | 2 | mediumGray | 12 | lightVertical |
  172. // +-------+-----------------+-------+-----------------+
  173. // | 3 | darkGray | 13 | lightDown |
  174. // +-------+-----------------+-------+-----------------+
  175. // | 4 | lightGray | 14 | lightUp |
  176. // +-------+-----------------+-------+-----------------+
  177. // | 5 | darkHorizontal | 15 | lightGrid |
  178. // +-------+-----------------+-------+-----------------+
  179. // | 6 | darkVertical | 16 | lightTrellis |
  180. // +-------+-----------------+-------+-----------------+
  181. // | 7 | darkDown | 17 | gray125 |
  182. // +-------+-----------------+-------+-----------------+
  183. // | 8 | darkUp | 18 | gray0625 |
  184. // +-------+-----------------+-------+-----------------+
  185. // | 9 | darkGrid | | |
  186. // +-------+-----------------+-------+-----------------+
  187. //
  188. // The following the type of horizontal alignment in cells:
  189. //
  190. // +------------------+
  191. // | Style |
  192. // +==================+
  193. // | left |
  194. // +------------------+
  195. // | center |
  196. // +------------------+
  197. // | right |
  198. // +------------------+
  199. // | fill |
  200. // +------------------+
  201. // | justify |
  202. // +------------------+
  203. // | centerContinuous |
  204. // +------------------+
  205. // | distributed |
  206. // +------------------+
  207. //
  208. // The following the type of vertical alignment in cells:
  209. //
  210. // +------------------+
  211. // | Style |
  212. // +==================+
  213. // | top |
  214. // +------------------+
  215. // | center |
  216. // +------------------+
  217. // | justify |
  218. // +------------------+
  219. // | distributed |
  220. // +------------------+
  221. //
  222. // Excel's built-in formats are shown in the following table:
  223. //
  224. // +-------+----------------------------------------------------+
  225. // | Index | Format String |
  226. // +=======+====================================================+
  227. // | 0 | General |
  228. // +-------+----------------------------------------------------+
  229. // | 1 | 0 |
  230. // +-------+----------------------------------------------------+
  231. // | 2 | 0.00 |
  232. // +-------+----------------------------------------------------+
  233. // | 3 | #,##0 |
  234. // +-------+----------------------------------------------------+
  235. // | 4 | #,##0.00 |
  236. // +-------+----------------------------------------------------+
  237. // | 5 | ($#,##0_);($#,##0) |
  238. // +-------+----------------------------------------------------+
  239. // | 6 | ($#,##0_);[Red]($#,##0) |
  240. // +-------+----------------------------------------------------+
  241. // | 7 | ($#,##0.00_);($#,##0.00) |
  242. // +-------+----------------------------------------------------+
  243. // | 8 | ($#,##0.00_);[Red]($#,##0.00) |
  244. // +-------+----------------------------------------------------+
  245. // | 9 | 0% |
  246. // +-------+----------------------------------------------------+
  247. // | 10 | 0.00% |
  248. // +-------+----------------------------------------------------+
  249. // | 11 | 0.00E+00 |
  250. // +-------+----------------------------------------------------+
  251. // | 12 | # ?/? |
  252. // +-------+----------------------------------------------------+
  253. // | 13 | # ??/?? |
  254. // +-------+----------------------------------------------------+
  255. // | 14 | m/d/yy |
  256. // +-------+----------------------------------------------------+
  257. // | 15 | d-mmm-yy |
  258. // +-------+----------------------------------------------------+
  259. // | 16 | d-mmm |
  260. // +-------+----------------------------------------------------+
  261. // | 17 | mmm-yy |
  262. // +-------+----------------------------------------------------+
  263. // | 18 | h:mm AM/PM |
  264. // +-------+----------------------------------------------------+
  265. // | 19 | h:mm:ss AM/PM |
  266. // +-------+----------------------------------------------------+
  267. // | 20 | h:mm |
  268. // +-------+----------------------------------------------------+
  269. // | 21 | h:mm:ss |
  270. // +-------+----------------------------------------------------+
  271. // | 22 | m/d/yy h:mm |
  272. // +-------+----------------------------------------------------+
  273. // | ... | ... |
  274. // +-------+----------------------------------------------------+
  275. // | 37 | (#,##0_);(#,##0) |
  276. // +-------+----------------------------------------------------+
  277. // | 38 | (#,##0_);[Red](#,##0) |
  278. // +-------+----------------------------------------------------+
  279. // | 39 | (#,##0.00_);(#,##0.00) |
  280. // +-------+----------------------------------------------------+
  281. // | 40 | (#,##0.00_);[Red](#,##0.00) |
  282. // +-------+----------------------------------------------------+
  283. // | 41 | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
  284. // +-------+----------------------------------------------------+
  285. // | 42 | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) |
  286. // +-------+----------------------------------------------------+
  287. // | 43 | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
  288. // +-------+----------------------------------------------------+
  289. // | 44 | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) |
  290. // +-------+----------------------------------------------------+
  291. // | 45 | mm:ss |
  292. // +-------+----------------------------------------------------+
  293. // | 46 | [h]:mm:ss |
  294. // +-------+----------------------------------------------------+
  295. // | 47 | mm:ss.0 |
  296. // +-------+----------------------------------------------------+
  297. // | 48 | ##0.0E+0 |
  298. // +-------+----------------------------------------------------+
  299. // | 49 | @ |
  300. // +-------+----------------------------------------------------+
  301. //
  302. func (f *File) SetCellStyle(sheet, hcell, vcell, style string) error {
  303. var styleSheet xlsxStyleSheet
  304. xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
  305. formatCellStyle, err := parseFormatStyleSet(style)
  306. if err != nil {
  307. return err
  308. }
  309. numFmtID := setNumFmt(&styleSheet, formatCellStyle)
  310. borderID := setBorders(&styleSheet, formatCellStyle)
  311. fillID := setFills(&styleSheet, formatCellStyle)
  312. applyAlignment, alignment := setAlignment(&styleSheet, formatCellStyle)
  313. cellXfsID := setCellXfs(&styleSheet, numFmtID, fillID, borderID, applyAlignment, alignment)
  314. output, err := xml.Marshal(styleSheet)
  315. if err != nil {
  316. return err
  317. }
  318. f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpace(string(output)))
  319. f.setCellStyle(sheet, hcell, vcell, cellXfsID)
  320. return err
  321. }
  322. // setNumFmt provides function to check if number format code in the range of
  323. // built-in values.
  324. func setNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  325. _, ok := builtInNumFmt[formatCellStyle.NumFmt]
  326. if !ok {
  327. return 0
  328. }
  329. return formatCellStyle.NumFmt
  330. }
  331. // setFills provides function to add fill elements in the styles.xml by given
  332. // cell format settings.
  333. func setFills(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  334. var patterns = []string{
  335. "none",
  336. "solid",
  337. "mediumGray",
  338. "darkGray",
  339. "lightGray",
  340. "darkHorizontal",
  341. "darkVertical",
  342. "darkDown",
  343. "darkUp",
  344. "darkGrid",
  345. "darkTrellis",
  346. "lightHorizontal",
  347. "lightVertical",
  348. "lightDown",
  349. "lightUp",
  350. "lightGrid",
  351. "lightTrellis",
  352. "gray125",
  353. "gray0625",
  354. }
  355. var variants = []float64{
  356. 90,
  357. 0,
  358. 45,
  359. 135,
  360. }
  361. var fill xlsxFill
  362. switch formatCellStyle.Fill.Type {
  363. case "gradient":
  364. if len(formatCellStyle.Fill.Color) != 2 {
  365. break
  366. }
  367. var gradient xlsxGradientFill
  368. switch formatCellStyle.Fill.Shading {
  369. case 0, 1, 2, 3:
  370. gradient.Degree = variants[formatCellStyle.Fill.Shading]
  371. case 4:
  372. gradient.Type = "path"
  373. case 5:
  374. gradient.Type = "path"
  375. gradient.Bottom = 0.5
  376. gradient.Left = 0.5
  377. gradient.Right = 0.5
  378. gradient.Top = 0.5
  379. default:
  380. break
  381. }
  382. var stops []*xlsxGradientFillStop
  383. for index, color := range formatCellStyle.Fill.Color {
  384. var stop xlsxGradientFillStop
  385. stop.Position = float64(index)
  386. stop.Color.RGB = getPaletteColor(color)
  387. stops = append(stops, &stop)
  388. }
  389. gradient.Stop = stops
  390. fill.GradientFill = &gradient
  391. case "pattern":
  392. if formatCellStyle.Fill.Pattern > 18 || formatCellStyle.Fill.Pattern < 0 {
  393. break
  394. }
  395. if len(formatCellStyle.Fill.Color) < 1 {
  396. break
  397. }
  398. var pattern xlsxPatternFill
  399. pattern.PatternType = patterns[formatCellStyle.Fill.Pattern]
  400. pattern.FgColor.RGB = getPaletteColor(formatCellStyle.Fill.Color[0])
  401. fill.PatternFill = &pattern
  402. }
  403. style.Fills.Count++
  404. style.Fills.Fill = append(style.Fills.Fill, &fill)
  405. return style.Fills.Count - 1
  406. }
  407. // setAlignment provides function to formatting information pertaining to text
  408. // alignment in cells. There are a variety of choices for how text is aligned
  409. // both horizontally and vertically, as well as indentation settings, and so on.
  410. func setAlignment(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) (bool, *xlsxAlignment) {
  411. if formatCellStyle.Alignment == nil {
  412. return false, &xlsxAlignment{}
  413. }
  414. var alignment = xlsxAlignment{
  415. Horizontal: formatCellStyle.Alignment.Horizontal,
  416. Indent: formatCellStyle.Alignment.Indent,
  417. JustifyLastLine: formatCellStyle.Alignment.JustifyLastLine,
  418. ReadingOrder: formatCellStyle.Alignment.ReadingOrder,
  419. RelativeIndent: formatCellStyle.Alignment.RelativeIndent,
  420. ShrinkToFit: formatCellStyle.Alignment.ShrinkToFit,
  421. TextRotation: formatCellStyle.Alignment.TextRotation,
  422. Vertical: formatCellStyle.Alignment.Vertical,
  423. WrapText: formatCellStyle.Alignment.WrapText,
  424. }
  425. return true, &alignment
  426. }
  427. // setBorders provides function to add border elements in the styles.xml by
  428. // given borders format settings.
  429. func setBorders(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  430. var styles = []string{
  431. "none",
  432. "thin",
  433. "medium",
  434. "dashed",
  435. "dotted",
  436. "thick",
  437. "double",
  438. "hair",
  439. "mediumDashed",
  440. "dashDot",
  441. "mediumDashDot",
  442. "dashDotDot",
  443. "mediumDashDotDot",
  444. "slantDashDot",
  445. }
  446. var border xlsxBorder
  447. for _, v := range formatCellStyle.Border {
  448. if v.Style > 13 || v.Style < 0 {
  449. continue
  450. }
  451. var color xlsxColor
  452. color.RGB = getPaletteColor(v.Color)
  453. switch v.Type {
  454. case "left":
  455. border.Left.Style = styles[v.Style]
  456. border.Left.Color = &color
  457. case "right":
  458. border.Right.Style = styles[v.Style]
  459. border.Right.Color = &color
  460. case "top":
  461. border.Top.Style = styles[v.Style]
  462. border.Top.Color = &color
  463. case "bottom":
  464. border.Bottom.Style = styles[v.Style]
  465. border.Bottom.Color = &color
  466. case "diagonalUp":
  467. border.Diagonal.Style = styles[v.Style]
  468. border.Diagonal.Color = &color
  469. border.DiagonalUp = true
  470. case "diagonalDown":
  471. border.Diagonal.Style = styles[v.Style]
  472. border.Diagonal.Color = &color
  473. border.DiagonalDown = true
  474. }
  475. }
  476. style.Borders.Count++
  477. style.Borders.Border = append(style.Borders.Border, &border)
  478. return style.Borders.Count - 1
  479. }
  480. // setCellXfs provides function to set describes all of the formatting for a
  481. // cell.
  482. func setCellXfs(style *xlsxStyleSheet, numFmtID, fillID, borderID int, applyAlignment bool, alignment *xlsxAlignment) int {
  483. var xf xlsxXf
  484. xf.NumFmtID = numFmtID
  485. if numFmtID != 0 {
  486. xf.ApplyNumberFormat = true
  487. }
  488. xf.FillID = fillID
  489. xf.BorderID = borderID
  490. style.CellXfs.Count++
  491. xf.Alignment = alignment
  492. xf.ApplyAlignment = applyAlignment
  493. style.CellXfs.Xf = append(style.CellXfs.Xf, xf)
  494. return style.CellXfs.Count - 1
  495. }
  496. // setCellStyle provides function to add style attribute for cells by given
  497. // sheet index, coordinate area and style ID.
  498. func (f *File) setCellStyle(sheet, hcell, vcell string, styleID int) {
  499. hcell = strings.ToUpper(hcell)
  500. vcell = strings.ToUpper(vcell)
  501. // Coordinate conversion, convert C1:B3 to 2,0,1,2.
  502. hcol := string(strings.Map(letterOnlyMapF, hcell))
  503. hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell))
  504. hyAxis := hrow - 1
  505. hxAxis := titleToNumber(hcol)
  506. vcol := string(strings.Map(letterOnlyMapF, vcell))
  507. vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell))
  508. vyAxis := vrow - 1
  509. vxAxis := titleToNumber(vcol)
  510. if vxAxis < hxAxis {
  511. hcell, vcell = vcell, hcell
  512. vxAxis, hxAxis = hxAxis, vxAxis
  513. }
  514. if vyAxis < hyAxis {
  515. hcell, vcell = vcell, hcell
  516. vyAxis, hyAxis = hyAxis, vyAxis
  517. }
  518. // Correct the coordinate area, such correct C1:B3 to B1:C3.
  519. hcell = toAlphaString(hxAxis+1) + strconv.Itoa(hyAxis+1)
  520. vcell = toAlphaString(vxAxis+1) + strconv.Itoa(vyAxis+1)
  521. xlsx := f.workSheetReader(sheet)
  522. completeRow(xlsx, vxAxis+1, vyAxis+1)
  523. completeCol(xlsx, vxAxis+1, vyAxis+1)
  524. for r, row := range xlsx.SheetData.Row {
  525. for k, c := range row.C {
  526. if checkCellInArea(c.R, hcell+":"+vcell) {
  527. xlsx.SheetData.Row[r].C[k].S = styleID
  528. }
  529. }
  530. }
  531. }
  532. // getPaletteColor provides function to convert the RBG color by given string.
  533. func getPaletteColor(color string) string {
  534. return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
  535. }