styles.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. package excelize
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "fmt"
  6. "math"
  7. "strconv"
  8. "strings"
  9. )
  10. // Excel styles can reference number formats that are built-in, all of which
  11. // have an id less than 164. This is a possibly incomplete list comprised of as
  12. // many of them as I could find.
  13. var builtInNumFmt = map[int]string{
  14. 0: "general",
  15. 1: "0",
  16. 2: "0.00",
  17. 3: "#,##0",
  18. 4: "#,##0.00",
  19. 9: "0%",
  20. 10: "0.00%",
  21. 11: "0.00e+00",
  22. 12: "# ?/?",
  23. 13: "# ??/??",
  24. 14: "mm-dd-yy",
  25. 15: "d-mmm-yy",
  26. 16: "d-mmm",
  27. 17: "mmm-yy",
  28. 18: "h:mm am/pm",
  29. 19: "h:mm:ss am/pm",
  30. 20: "h:mm",
  31. 21: "h:mm:ss",
  32. 22: "m/d/yy h:mm",
  33. 37: "#,##0 ;(#,##0)",
  34. 38: "#,##0 ;[red](#,##0)",
  35. 39: "#,##0.00;(#,##0.00)",
  36. 40: "#,##0.00;[red](#,##0.00)",
  37. 41: `_(* #,##0_);_(* \(#,##0\);_(* "-"_);_(@_)`,
  38. 42: `_("$"* #,##0_);_("$* \(#,##0\);_("$"* "-"_);_(@_)`,
  39. 43: `_(* #,##0.00_);_(* \(#,##0.00\);_(* "-"??_);_(@_)`,
  40. 44: `_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)`,
  41. 45: "mm:ss",
  42. 46: "[h]:mm:ss",
  43. 47: "mmss.0",
  44. 48: "##0.0e+0",
  45. 49: "@",
  46. }
  47. // langNumFmt defined number format code with unicode in different language.
  48. var langNumFmt = map[string]map[int]string{
  49. "zh-tw": zhtwNumFmt,
  50. "zh-cn": zhcnNumFmt,
  51. "zh-tw_unicode": zhtwUnicodeNumFmt,
  52. "zh-cn_unicode": zhcnUnicodeNumFmt,
  53. "ja-jp": jajpNumFmt,
  54. "ko-kr": kokrNumFmt,
  55. "ja-jp_unicode": jajpUnicodeNumFmt,
  56. "ko-kr_unicode": kokrUnicodeNumFmt,
  57. "th-th": ththNumFmt,
  58. "th-th_unicode": ththUnicodeNumFmt,
  59. }
  60. // zh-tw format code.
  61. var zhtwNumFmt = map[int]string{
  62. 27: "[$-404]e/m/d",
  63. 28: `[$-404]e"年"m"月"d"日"`,
  64. 29: `[$-404]e"年"m"月"d"日"`,
  65. 30: "m/d/yy",
  66. 31: `yyyy"年"m"月"d"日"`,
  67. 32: `hh"時"mm"分"`,
  68. 33: `hh"時"mm"分"ss"秒"`,
  69. 34: `上午/下午 hh"時"mm"分"`,
  70. 35: `上午/下午 hh"時"mm"分"ss"秒"`,
  71. 36: "[$-404]e/m/d",
  72. 50: "[$-404]e/m/d",
  73. 51: `[$-404]e"年"m"月"d"日"`,
  74. 52: `上午/下午 hh"時"mm"分"`,
  75. 53: `上午/下午 hh"時"mm"分"ss"秒"`,
  76. 54: `[$-404]e"年"m"月"d"日"`,
  77. 55: `上午/下午 hh"時"mm"分"`,
  78. 56: `上午/下午 hh"時"mm"分"ss"秒"`,
  79. 57: "[$-404]e/m/d",
  80. 58: `[$-404]e"年"m"月"d"日"`,
  81. }
  82. // zh-cn format code.
  83. var zhcnNumFmt = map[int]string{
  84. 27: `yyyy"年"m"月"`,
  85. 28: `m"月"d"日"`,
  86. 29: `m"月"d"日"`,
  87. 30: "m-d-yy",
  88. 31: `yyyy"年"m"月"d"日"`,
  89. 32: `h"时"mm"分"`,
  90. 33: `h"时"mm"分"ss"秒"`,
  91. 34: `上午/下午 h"时"mm"分"`,
  92. 35: `上午/下午 h"时"mm"分"ss"秒"`,
  93. 36: `yyyy"年"m"月"`,
  94. 50: `yyyy"年"m"月"`,
  95. 51: `m"月"d"日"`,
  96. 52: `yyyy"年"m"月"`,
  97. 53: `m"月"d"日"`,
  98. 54: `m"月"d"日"`,
  99. 55: `上午/下午 h"时"mm"分"`,
  100. 56: `上午/下午 h"时"mm"分"ss"秒"`,
  101. 57: `yyyy"年"m"月"`,
  102. 58: `m"月"d"日"`,
  103. }
  104. // zh-tw format code (with unicode values provided for language glyphs where
  105. // they occur).
  106. var zhtwUnicodeNumFmt = map[int]string{
  107. 27: "[$-404]e/m/d",
  108. 28: `[$-404]e"5E74"m"6708"d"65E5"`,
  109. 29: `[$-404]e"5E74"m"6708"d"65E5"`,
  110. 30: "m/d/yy",
  111. 31: `yyyy"5E74"m"6708"d"65E5"`,
  112. 32: `hh"6642"mm"5206"`,
  113. 33: `hh"6642"mm"5206"ss"79D2"`,
  114. 34: `4E0A5348/4E0B5348hh"6642"mm"5206"`,
  115. 35: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`,
  116. 36: "[$-404]e/m/d",
  117. 50: "[$-404]e/m/d",
  118. 51: `[$-404]e"5E74"m"6708"d"65E5"`,
  119. 52: `4E0A5348/4E0B5348hh"6642"mm"5206"`,
  120. 53: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`,
  121. 54: `[$-404]e"5E74"m"6708"d"65E5"`,
  122. 55: `4E0A5348/4E0B5348hh"6642"mm"5206"`,
  123. 56: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`,
  124. 57: "[$-404]e/m/d",
  125. 58: `[$-404]e"5E74"m"6708"d"65E5"`,
  126. }
  127. // zh-cn format code (with unicode values provided for language glyphs where
  128. // they occur).
  129. var zhcnUnicodeNumFmt = map[int]string{
  130. 27: `yyyy"5E74"m"6708"`,
  131. 28: `m"6708"d"65E5"`,
  132. 29: `m"6708"d"65E5"`,
  133. 30: "m-d-yy",
  134. 31: `yyyy"5E74"m"6708"d"65E5"`,
  135. 32: `h"65F6"mm"5206"`,
  136. 33: `h"65F6"mm"5206"ss"79D2"`,
  137. 34: `4E0A5348/4E0B5348h"65F6"mm"5206"`,
  138. 35: `4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2"`,
  139. 36: `yyyy"5E74"m"6708"`,
  140. 50: `yyyy"5E74"m"6708"`,
  141. 51: `m"6708"d"65E5"`,
  142. 52: `yyyy"5E74"m"6708"`,
  143. 53: `m"6708"d"65E5"`,
  144. 54: `m"6708"d"65E5"`,
  145. 55: `4E0A5348/4E0B5348h"65F6"mm"5206"`,
  146. 56: `4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2"`,
  147. 57: `yyyy"5E74"m"6708"`,
  148. 58: `m"6708"d"65E5"`,
  149. }
  150. // ja-jp format code.
  151. var jajpNumFmt = map[int]string{
  152. 27: "[$-411]ge.m.d",
  153. 28: `[$-411]ggge"年"m"月"d"日"`,
  154. 29: `[$-411]ggge"年"m"月"d"日"`,
  155. 30: "m/d/yy",
  156. 31: `yyyy"年"m"月"d"日"`,
  157. 32: `h"時"mm"分"`,
  158. 33: `h"時"mm"分"ss"秒"`,
  159. 34: `yyyy"年"m"月"`,
  160. 35: `m"月"d"日"`,
  161. 36: "[$-411]ge.m.d",
  162. 50: "[$-411]ge.m.d",
  163. 51: `[$-411]ggge"年"m"月"d"日"`,
  164. 52: `yyyy"年"m"月"`,
  165. 53: `m"月"d"日"`,
  166. 54: `[$-411]ggge"年"m"月"d"日"`,
  167. 55: `yyyy"年"m"月"`,
  168. 56: `m"月"d"日"`,
  169. 57: "[$-411]ge.m.d",
  170. 58: `[$-411]ggge"年"m"月"d"日"`,
  171. }
  172. // ko-kr format code.
  173. var kokrNumFmt = map[int]string{
  174. 27: `yyyy"年" mm"月" dd"日"`,
  175. 28: "mm-dd",
  176. 29: "mm-dd",
  177. 30: "mm-dd-yy",
  178. 31: `yyyy"년" mm"월" dd"일"`,
  179. 32: `h"시" mm"분"`,
  180. 33: `h"시" mm"분" ss"초"`,
  181. 34: `yyyy-mm-dd`,
  182. 35: `yyyy-mm-dd`,
  183. 36: `yyyy"年" mm"月" dd"日"`,
  184. 50: `yyyy"年" mm"月" dd"日"`,
  185. 51: "mm-dd",
  186. 52: "yyyy-mm-dd",
  187. 53: "yyyy-mm-dd",
  188. 54: "mm-dd",
  189. 55: "yyyy-mm-dd",
  190. 56: "yyyy-mm-dd",
  191. 57: `yyyy"年" mm"月" dd"日"`,
  192. 58: "mm-dd",
  193. }
  194. // ja-jp format code (with unicode values provided for language glyphs where
  195. // they occur).
  196. var jajpUnicodeNumFmt = map[int]string{
  197. 27: "[$-411]ge.m.d",
  198. 28: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  199. 29: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  200. 30: "m/d/yy",
  201. 31: `yyyy"5E74"m"6708"d"65E5"`,
  202. 32: `h"6642"mm"5206"`,
  203. 33: `h"6642"mm"5206"ss"79D2"`,
  204. 34: `yyyy"5E74"m"6708"`,
  205. 35: `m"6708"d"65E5"`,
  206. 36: "[$-411]ge.m.d",
  207. 50: "[$-411]ge.m.d",
  208. 51: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  209. 52: `yyyy"5E74"m"6708"`,
  210. 53: `m"6708"d"65E5"`,
  211. 54: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  212. 55: `yyyy"5E74"m"6708"`,
  213. 56: `m"6708"d"65E5"`,
  214. 57: "[$-411]ge.m.d",
  215. 58: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  216. }
  217. // ko-kr format code (with unicode values provided for language glyphs where
  218. // they occur).
  219. var kokrUnicodeNumFmt = map[int]string{
  220. 27: `yyyy"5E74" mm"6708" dd"65E5"`,
  221. 28: "mm-dd",
  222. 29: "mm-dd",
  223. 30: "mm-dd-yy",
  224. 31: `yyyy"B144" mm"C6D4" dd"C77C"`,
  225. 32: `h"C2DC" mm"BD84"`,
  226. 33: `h"C2DC" mm"BD84" ss"CD08"`,
  227. 34: "yyyy-mm-dd",
  228. 35: "yyyy-mm-dd",
  229. 36: `yyyy"5E74" mm"6708" dd"65E5"`,
  230. 50: `yyyy"5E74" mm"6708" dd"65E5"`,
  231. 51: "mm-dd",
  232. 52: "yyyy-mm-dd",
  233. 53: "yyyy-mm-dd",
  234. 54: "mm-dd",
  235. 55: "yyyy-mm-dd",
  236. 56: "yyyy-mm-dd",
  237. 57: `yyyy"5E74" mm"6708" dd"65E5"`,
  238. 58: "mm-dd",
  239. }
  240. // th-th format code.
  241. var ththNumFmt = map[int]string{
  242. 59: "t0",
  243. 60: "t0.00",
  244. 61: "t#,##0",
  245. 62: "t#,##0.00",
  246. 67: "t0%",
  247. 68: "t0.00%",
  248. 69: "t# ?/?",
  249. 70: "t# ??/??",
  250. 71: "ว/ด/ปปปป",
  251. 72: "ว-ดดด-ปป",
  252. 73: "ว-ดดด",
  253. 74: "ดดด-ปป",
  254. 75: "ช:นน",
  255. 76: "ช:นน:ทท",
  256. 77: "ว/ด/ปปปป ช:นน",
  257. 78: "นน:ทท",
  258. 79: "[ช]:นน:ทท",
  259. 80: "นน:ทท.0",
  260. 81: "d/m/bb",
  261. }
  262. // th-th format code (with unicode values provided for language glyphs where
  263. // they occur).
  264. var ththUnicodeNumFmt = map[int]string{
  265. 59: "t0",
  266. 60: "t0.00",
  267. 61: "t#,##0",
  268. 62: "t#,##0.00",
  269. 67: "t0%",
  270. 68: "t0.00%",
  271. 69: "t# ?/?",
  272. 70: "t# ??/??",
  273. 71: "0E27/0E14/0E1B0E1B0E1B0E1B",
  274. 72: "0E27-0E140E140E14-0E1B0E1B",
  275. 73: "0E27-0E140E140E14",
  276. 74: "0E140E140E14-0E1B0E1B",
  277. 75: "0E0A:0E190E19",
  278. 76: "0E0A:0E190E19:0E170E17",
  279. 77: "0E27/0E14/0E1B0E1B0E1B0E1B 0E0A:0E190E19",
  280. 78: "0E190E19:0E170E17",
  281. 79: "[0E0A]:0E190E19:0E170E17",
  282. 80: "0E190E19:0E170E17.0",
  283. 81: "d/m/bb",
  284. }
  285. // currencyNumFmt defined the currency number format map.
  286. var currencyNumFmt = map[int]string{
  287. 164: `"CN¥",##0.00`,
  288. 165: "[$$-409]#,##0.00",
  289. 166: "[$$-45C]#,##0.00",
  290. 167: "[$$-1004]#,##0.00",
  291. 168: "[$$-404]#,##0.00",
  292. 169: "[$$-C09]#,##0.00",
  293. 170: "[$$-2809]#,##0.00",
  294. 171: "[$$-1009]#,##0.00",
  295. 172: "[$$-2009]#,##0.00",
  296. 173: "[$$-1409]#,##0.00",
  297. 174: "[$$-4809]#,##0.00",
  298. 175: "[$$-2C09]#,##0.00",
  299. 176: "[$$-2409]#,##0.00",
  300. 177: "[$$-1000]#,##0.00",
  301. 178: `#,##0.00\ [$$-C0C]`,
  302. 179: "[$$-475]#,##0.00",
  303. 180: "[$$-83E]#,##0.00",
  304. 181: `[$$-86B]\ #,##0.00`,
  305. 182: `[$$-340A]\ #,##0.00`,
  306. 183: "[$$-240A]#,##0.00",
  307. 184: `[$$-300A]\ #,##0.00`,
  308. 185: "[$$-440A]#,##0.00",
  309. 186: "[$$-80A]#,##0.00",
  310. 187: "[$$-500A]#,##0.00",
  311. 188: "[$$-540A]#,##0.00",
  312. 189: `[$$-380A]\ #,##0.00`,
  313. }
  314. // builtInNumFmtFunc defined the format conversion functions map. Partial format
  315. // code doesn't support currently and will return original string.
  316. var builtInNumFmtFunc = map[int]func(i int, v string) string{
  317. 0: formatToString,
  318. 1: formatToInt,
  319. 2: formatToFloat,
  320. 3: formatToInt,
  321. 4: formatToFloat,
  322. 9: formatToC,
  323. 10: formatToD,
  324. 11: formatToE,
  325. 12: formatToString, // Doesn't support currently
  326. 13: formatToString, // Doesn't support currently
  327. 14: parseTime,
  328. 15: parseTime,
  329. 16: parseTime,
  330. 17: parseTime,
  331. 18: parseTime,
  332. 19: parseTime,
  333. 20: parseTime,
  334. 21: parseTime,
  335. 22: parseTime,
  336. 37: formatToA,
  337. 38: formatToA,
  338. 39: formatToB,
  339. 40: formatToB,
  340. 41: formatToString, // Doesn't support currently
  341. 42: formatToString, // Doesn't support currently
  342. 43: formatToString, // Doesn't support currently
  343. 44: formatToString, // Doesn't support currently
  344. 45: parseTime,
  345. 46: parseTime,
  346. 47: parseTime,
  347. 48: formatToE,
  348. 49: formatToString,
  349. }
  350. // formatToString provides function to return original string by given built-in
  351. // number formats code and cell string.
  352. func formatToString(i int, v string) string {
  353. return v
  354. }
  355. // formatToInt provides function to convert original string to integer format as
  356. // string type by given built-in number formats code and cell string.
  357. func formatToInt(i int, v string) string {
  358. f, err := strconv.ParseFloat(v, 64)
  359. if err != nil {
  360. return v
  361. }
  362. return fmt.Sprintf("%d", int(f))
  363. }
  364. // formatToFloat provides function to convert original string to float format as
  365. // string type by given built-in number formats code and cell string.
  366. func formatToFloat(i int, v string) string {
  367. f, err := strconv.ParseFloat(v, 64)
  368. if err != nil {
  369. return v
  370. }
  371. return fmt.Sprintf("%.2f", f)
  372. }
  373. // formatToA provides function to convert original string to special format as
  374. // string type by given built-in number formats code and cell string.
  375. func formatToA(i int, v string) string {
  376. f, err := strconv.ParseFloat(v, 64)
  377. if err != nil {
  378. return v
  379. }
  380. if f < 0 {
  381. t := int(math.Abs(f))
  382. return fmt.Sprintf("(%d)", t)
  383. }
  384. t := int(f)
  385. return fmt.Sprintf("%d", t)
  386. }
  387. // formatToB provides function to convert original string to special format as
  388. // string type by given built-in number formats code and cell string.
  389. func formatToB(i int, v string) string {
  390. f, err := strconv.ParseFloat(v, 64)
  391. if err != nil {
  392. return v
  393. }
  394. if f < 0 {
  395. return fmt.Sprintf("(%.2f)", f)
  396. }
  397. return fmt.Sprintf("%.2f", f)
  398. }
  399. // formatToC provides function to convert original string to special format as
  400. // string type by given built-in number formats code and cell string.
  401. func formatToC(i int, v string) string {
  402. f, err := strconv.ParseFloat(v, 64)
  403. if err != nil {
  404. return v
  405. }
  406. f = f * 100
  407. return fmt.Sprintf("%d%%", int(f))
  408. }
  409. // formatToD provides function to convert original string to special format as
  410. // string type by given built-in number formats code and cell string.
  411. func formatToD(i int, v string) string {
  412. f, err := strconv.ParseFloat(v, 64)
  413. if err != nil {
  414. return v
  415. }
  416. f = f * 100
  417. return fmt.Sprintf("%.2f%%", f)
  418. }
  419. // formatToE provides function to convert original string to special format as
  420. // string type by given built-in number formats code and cell string.
  421. func formatToE(i int, v string) string {
  422. f, err := strconv.ParseFloat(v, 64)
  423. if err != nil {
  424. return v
  425. }
  426. return fmt.Sprintf("%.e", f)
  427. }
  428. // parseTime provides function to returns a string parsed using time.Time.
  429. // Replace Excel placeholders with Go time placeholders. For example, replace
  430. // yyyy with 2006. These are in a specific order, due to the fact that m is used
  431. // in month, minute, and am/pm. It would be easier to fix that with regular
  432. // expressions, but if it's possible to keep this simple it would be easier to
  433. // maintain. Full-length month and days (e.g. March, Tuesday) have letters in
  434. // them that would be replaced by other characters below (such as the 'h' in
  435. // March, or the 'd' in Tuesday) below. First we convert them to arbitrary
  436. // characters unused in Excel Date formats, and then at the end, turn them to
  437. // what they should actually be.
  438. func parseTime(i int, v string) string {
  439. f, err := strconv.ParseFloat(v, 64)
  440. if err != nil {
  441. return v
  442. }
  443. val := timeFromExcelTime(f, false)
  444. format := builtInNumFmt[i]
  445. replacements := []struct{ xltime, gotime string }{
  446. {"yyyy", "2006"},
  447. {"yy", "06"},
  448. {"mmmm", "%%%%"},
  449. {"dddd", "&&&&"},
  450. {"dd", "02"},
  451. {"d", "2"},
  452. {"mmm", "Jan"},
  453. {"mmss", "0405"},
  454. {"ss", "05"},
  455. {"hh", "15"},
  456. {"h", "3"},
  457. {"mm:", "04:"},
  458. {":mm", ":04"},
  459. {"mm", "01"},
  460. {"am/pm", "pm"},
  461. {"m/", "1/"},
  462. {"%%%%", "January"},
  463. {"&&&&", "Monday"},
  464. }
  465. for _, repl := range replacements {
  466. format = strings.Replace(format, repl.xltime, repl.gotime, 1)
  467. }
  468. // If the hour is optional, strip it out, along with the possible dangling
  469. // colon that would remain.
  470. if val.Hour() < 1 {
  471. format = strings.Replace(format, "]:", "]", 1)
  472. format = strings.Replace(format, "[3]", "", 1)
  473. format = strings.Replace(format, "[15]", "", 1)
  474. } else {
  475. format = strings.Replace(format, "[3]", "3", 1)
  476. format = strings.Replace(format, "[15]", "15", 1)
  477. }
  478. return val.Format(format)
  479. }
  480. // stylesReader provides function to get the pointer to the structure after
  481. // deserialization of xl/styles.xml.
  482. func (f *File) stylesReader() *xlsxStyleSheet {
  483. if f.Styles == nil {
  484. var styleSheet xlsxStyleSheet
  485. xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
  486. f.Styles = &styleSheet
  487. }
  488. return f.Styles
  489. }
  490. // styleSheetWriter provides function to save xl/styles.xml after serialize
  491. // structure.
  492. func (f *File) styleSheetWriter() {
  493. if f.Styles != nil {
  494. output, _ := xml.Marshal(f.Styles)
  495. f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpace(string(output)))
  496. }
  497. }
  498. // parseFormatStyleSet provides function to parse the format settings of the
  499. // borders.
  500. func parseFormatStyleSet(style string) (*formatCellStyle, error) {
  501. format := formatCellStyle{
  502. DecimalPlaces: 2,
  503. }
  504. err := json.Unmarshal([]byte(style), &format)
  505. return &format, err
  506. }
  507. // NewStyle provides function to create style for cells by given style format.
  508. // Note that the color field uses RGB color code.
  509. //
  510. // The following shows the border styles sorted by excelize index number:
  511. //
  512. // | Index | Name | Weight | Style |
  513. // +-------+---------------+--------+-------------+
  514. // | 0 | None | 0 | |
  515. // | 1 | Continuous | 1 | ----------- |
  516. // | 2 | Continuous | 2 | ----------- |
  517. // | 3 | Dash | 1 | - - - - - - |
  518. // | 4 | Dot | 1 | . . . . . . |
  519. // | 5 | Continuous | 3 | ----------- |
  520. // | 6 | Double | 3 | =========== |
  521. // | 7 | Continuous | 0 | ----------- |
  522. // | 8 | Dash | 2 | - - - - - - |
  523. // | 9 | Dash Dot | 1 | - . - . - . |
  524. // | 10 | Dash Dot | 2 | - . - . - . |
  525. // | 11 | Dash Dot Dot | 1 | - . . - . . |
  526. // | 12 | Dash Dot Dot | 2 | - . . - . . |
  527. // | 13 | SlantDash Dot | 2 | / - . / - . |
  528. //
  529. // The following shows the borders in the order shown in the Excel dialog:
  530. //
  531. // | Index | Style | Index | Style |
  532. // +-------+-------------+-------+-------------+
  533. // | 0 | None | 12 | - . . - . . |
  534. // | 7 | ----------- | 13 | / - . / - . |
  535. // | 4 | . . . . . . | 10 | - . - . - . |
  536. // | 11 | - . . - . . | 8 | - - - - - - |
  537. // | 9 | - . - . - . | 2 | ----------- |
  538. // | 3 | - - - - - - | 5 | ----------- |
  539. // | 1 | ----------- | 6 | =========== |
  540. //
  541. // The following shows the shading styles sorted by excelize index number:
  542. //
  543. // | Index | Style | Index | Style |
  544. // +-------+-----------------+-------+-----------------+
  545. // | 0 | Horizontal | 3 | Diagonal down |
  546. // | 1 | Vertical | 4 | From corner |
  547. // | 2 | Diagonal Up | 5 | From center |
  548. //
  549. // The following shows the patterns styles sorted by excelize index number:
  550. //
  551. // | Index | Style | Index | Style |
  552. // +-------+-----------------+-------+-----------------+
  553. // | 0 | None | 10 | darkTrellis |
  554. // | 1 | solid | 11 | lightHorizontal |
  555. // | 2 | mediumGray | 12 | lightVertical |
  556. // | 3 | darkGray | 13 | lightDown |
  557. // | 4 | lightGray | 14 | lightUp |
  558. // | 5 | darkHorizontal | 15 | lightGrid |
  559. // | 6 | darkVertical | 16 | lightTrellis |
  560. // | 7 | darkDown | 17 | gray125 |
  561. // | 8 | darkUp | 18 | gray0625 |
  562. // | 9 | darkGrid | | |
  563. //
  564. // The following the type of horizontal alignment in cells:
  565. //
  566. // | Style |
  567. // +------------------+
  568. // | left |
  569. // | center |
  570. // | right |
  571. // | fill |
  572. // | justify |
  573. // | centerContinuous |
  574. // | distributed |
  575. //
  576. // The following the type of vertical alignment in cells:
  577. //
  578. // | Style |
  579. // +------------------+
  580. // | top |
  581. // | center |
  582. // | justify |
  583. // | distributed |
  584. //
  585. // The following the type of font underline style:
  586. //
  587. // | Style |
  588. // +------------------+
  589. // | single |
  590. // | double |
  591. //
  592. // Excel's built-in all languages formats are shown in the following table:
  593. //
  594. // | Index | Format String |
  595. // +-------+----------------------------------------------------+
  596. // | 0 | General |
  597. // | 1 | 0 |
  598. // | 2 | 0.00 |
  599. // | 3 | #,##0 |
  600. // | 4 | #,##0.00 |
  601. // | 5 | ($#,##0_);($#,##0) |
  602. // | 6 | ($#,##0_);[Red]($#,##0) |
  603. // | 7 | ($#,##0.00_);($#,##0.00) |
  604. // | 8 | ($#,##0.00_);[Red]($#,##0.00) |
  605. // | 9 | 0% |
  606. // | 10 | 0.00% |
  607. // | 11 | 0.00E+00 |
  608. // | 12 | # ?/? |
  609. // | 13 | # ??/?? |
  610. // | 14 | m/d/yy |
  611. // | 15 | d-mmm-yy |
  612. // | 16 | d-mmm |
  613. // | 17 | mmm-yy |
  614. // | 18 | h:mm AM/PM |
  615. // | 19 | h:mm:ss AM/PM |
  616. // | 20 | h:mm |
  617. // | 21 | h:mm:ss |
  618. // | 22 | m/d/yy h:mm |
  619. // | ... | ... |
  620. // | 37 | (#,##0_);(#,##0) |
  621. // | 38 | (#,##0_);[Red](#,##0) |
  622. // | 39 | (#,##0.00_);(#,##0.00) |
  623. // | 40 | (#,##0.00_);[Red](#,##0.00) |
  624. // | 41 | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
  625. // | 42 | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) |
  626. // | 43 | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
  627. // | 44 | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) |
  628. // | 45 | mm:ss |
  629. // | 46 | [h]:mm:ss |
  630. // | 47 | mm:ss.0 |
  631. // | 48 | ##0.0E+0 |
  632. // | 49 | @ |
  633. //
  634. // Excelize built-in currency formats are shown in the following table, only
  635. // support these types in the following table (Index number is used only for
  636. // markup and is not used inside an Excel file and you can't get formatted value
  637. // by the function GetCellValue) currently:
  638. //
  639. // | Index | Symbol |
  640. // +-------+----------------------------------------------------+
  641. // | 164 | CN¥ |
  642. // | 165 | $ English (China) |
  643. // | 166 | $ Cherokee (United States) |
  644. // | 167 | $ Chinese (Singapore) |
  645. // | 168 | $ Chinese (Taiwan) |
  646. // | 169 | $ English (Australia) |
  647. // | 170 | $ English (Belize) |
  648. // | 171 | $ English (Canada) |
  649. // | 172 | $ English (Jamaica) |
  650. // | 173 | $ English (New Zealand) |
  651. // | 174 | $ English (Singapore) |
  652. // | 175 | $ English (Trinidad & Tobago) |
  653. // | 176 | $ English (U.S. Vigin Islands) |
  654. // | 177 | $ English (United States) |
  655. // | 178 | $ French (Canada) |
  656. // | 179 | $ Hawaiian (United States) |
  657. // | 180 | $ Malay (Brunei) |
  658. // | 181 | $ Quechua (Ecuador) |
  659. // | 182 | $ Spanish (Chile) |
  660. // | 183 | $ Spanish (Colombia) |
  661. // | 184 | $ Spanish (Ecuador) |
  662. // | 185 | $ Spanish (El Salvador) |
  663. // | 186 | $ Spanish (Mexico) |
  664. // | 187 | $ Spanish (Puerto Rico) |
  665. // | 188 | $ Spanish (United States) |
  666. // | 189 | $ Spanish (Uruguay) |
  667. //
  668. func (f *File) NewStyle(style string) (int, error) {
  669. var cellXfsID int
  670. styleSheet := f.stylesReader()
  671. formatCellStyle, err := parseFormatStyleSet(style)
  672. if err != nil {
  673. return cellXfsID, err
  674. }
  675. numFmtID := setNumFmt(styleSheet, formatCellStyle)
  676. fontID := setFont(styleSheet, formatCellStyle)
  677. borderID := setBorders(styleSheet, formatCellStyle)
  678. fillID := setFills(styleSheet, formatCellStyle)
  679. applyAlignment, alignment := setAlignment(styleSheet, formatCellStyle)
  680. cellXfsID = setCellXfs(styleSheet, fontID, numFmtID, fillID, borderID, applyAlignment, alignment)
  681. return cellXfsID, nil
  682. }
  683. // setFont provides function to add font style by given cell format settings.
  684. func setFont(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  685. if formatCellStyle.Font == nil {
  686. return 0
  687. }
  688. fontUnderlineType := map[string]string{"single": "single", "double": "double"}
  689. if formatCellStyle.Font.Family == "" {
  690. formatCellStyle.Font.Family = "Calibri"
  691. }
  692. if formatCellStyle.Font.Size < 1 {
  693. formatCellStyle.Font.Size = 11
  694. }
  695. if formatCellStyle.Font.Color == "" {
  696. formatCellStyle.Font.Color = "#000000"
  697. }
  698. f := font{
  699. B: formatCellStyle.Font.Bold,
  700. I: formatCellStyle.Font.Italic,
  701. Sz: &attrValInt{Val: formatCellStyle.Font.Size},
  702. Color: &xlsxColor{RGB: getPaletteColor(formatCellStyle.Font.Color)},
  703. Name: &attrValString{Val: formatCellStyle.Font.Family},
  704. Family: &attrValInt{Val: 2},
  705. Scheme: &attrValString{Val: "minor"},
  706. }
  707. val, ok := fontUnderlineType[formatCellStyle.Font.Underline]
  708. if ok {
  709. f.U = &attrValString{Val: val}
  710. }
  711. font, _ := xml.Marshal(f)
  712. style.Fonts.Count++
  713. style.Fonts.Font = append(style.Fonts.Font, &xlsxFont{
  714. Font: string(font[6 : len(font)-7]),
  715. })
  716. return style.Fonts.Count - 1
  717. }
  718. // setNumFmt provides function to check if number format code in the range of
  719. // built-in values.
  720. func setNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  721. dp := "0."
  722. numFmtID := 164 // Default custom number format code from 164.
  723. if formatCellStyle.DecimalPlaces < 0 || formatCellStyle.DecimalPlaces > 30 {
  724. formatCellStyle.DecimalPlaces = 2
  725. }
  726. for i := 0; i < formatCellStyle.DecimalPlaces; i++ {
  727. dp += "0"
  728. }
  729. _, ok := builtInNumFmt[formatCellStyle.NumFmt]
  730. if !ok {
  731. fc, currency := currencyNumFmt[formatCellStyle.NumFmt]
  732. if !currency {
  733. return setLangNumFmt(style, formatCellStyle)
  734. }
  735. fc = strings.Replace(fc, "0.00", dp, -1)
  736. if style.NumFmts != nil {
  737. numFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1
  738. nf := xlsxNumFmt{
  739. FormatCode: fc,
  740. NumFmtID: numFmtID,
  741. }
  742. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  743. style.NumFmts.Count++
  744. } else {
  745. nf := xlsxNumFmt{
  746. FormatCode: fc,
  747. NumFmtID: numFmtID,
  748. }
  749. numFmts := xlsxNumFmts{
  750. NumFmt: []*xlsxNumFmt{&nf},
  751. Count: 1,
  752. }
  753. style.NumFmts = &numFmts
  754. }
  755. return numFmtID
  756. }
  757. return formatCellStyle.NumFmt
  758. }
  759. // setLangNumFmt provides function to set number format code with language.
  760. func setLangNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  761. numFmts, ok := langNumFmt[formatCellStyle.Lang]
  762. if !ok {
  763. return 0
  764. }
  765. var fc string
  766. fc, ok = numFmts[formatCellStyle.NumFmt]
  767. if !ok {
  768. return 0
  769. }
  770. nf := xlsxNumFmt{
  771. FormatCode: fc,
  772. NumFmtID: formatCellStyle.NumFmt,
  773. }
  774. if style.NumFmts != nil {
  775. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  776. style.NumFmts.Count++
  777. } else {
  778. numFmts := xlsxNumFmts{
  779. NumFmt: []*xlsxNumFmt{&nf},
  780. Count: 1,
  781. }
  782. style.NumFmts = &numFmts
  783. }
  784. return formatCellStyle.NumFmt
  785. }
  786. // setFills provides function to add fill elements in the styles.xml by given
  787. // cell format settings.
  788. func setFills(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  789. var patterns = []string{
  790. "none",
  791. "solid",
  792. "mediumGray",
  793. "darkGray",
  794. "lightGray",
  795. "darkHorizontal",
  796. "darkVertical",
  797. "darkDown",
  798. "darkUp",
  799. "darkGrid",
  800. "darkTrellis",
  801. "lightHorizontal",
  802. "lightVertical",
  803. "lightDown",
  804. "lightUp",
  805. "lightGrid",
  806. "lightTrellis",
  807. "gray125",
  808. "gray0625",
  809. }
  810. var variants = []float64{
  811. 90,
  812. 0,
  813. 45,
  814. 135,
  815. }
  816. var fill xlsxFill
  817. switch formatCellStyle.Fill.Type {
  818. case "gradient":
  819. if len(formatCellStyle.Fill.Color) != 2 {
  820. break
  821. }
  822. var gradient xlsxGradientFill
  823. switch formatCellStyle.Fill.Shading {
  824. case 0, 1, 2, 3:
  825. gradient.Degree = variants[formatCellStyle.Fill.Shading]
  826. case 4:
  827. gradient.Type = "path"
  828. case 5:
  829. gradient.Type = "path"
  830. gradient.Bottom = 0.5
  831. gradient.Left = 0.5
  832. gradient.Right = 0.5
  833. gradient.Top = 0.5
  834. default:
  835. break
  836. }
  837. var stops []*xlsxGradientFillStop
  838. for index, color := range formatCellStyle.Fill.Color {
  839. var stop xlsxGradientFillStop
  840. stop.Position = float64(index)
  841. stop.Color.RGB = getPaletteColor(color)
  842. stops = append(stops, &stop)
  843. }
  844. gradient.Stop = stops
  845. fill.GradientFill = &gradient
  846. case "pattern":
  847. if formatCellStyle.Fill.Pattern > 18 || formatCellStyle.Fill.Pattern < 0 {
  848. break
  849. }
  850. if len(formatCellStyle.Fill.Color) < 1 {
  851. break
  852. }
  853. var pattern xlsxPatternFill
  854. pattern.PatternType = patterns[formatCellStyle.Fill.Pattern]
  855. pattern.FgColor.RGB = getPaletteColor(formatCellStyle.Fill.Color[0])
  856. fill.PatternFill = &pattern
  857. }
  858. style.Fills.Count++
  859. style.Fills.Fill = append(style.Fills.Fill, &fill)
  860. return style.Fills.Count - 1
  861. }
  862. // setAlignment provides function to formatting information pertaining to text
  863. // alignment in cells. There are a variety of choices for how text is aligned
  864. // both horizontally and vertically, as well as indentation settings, and so on.
  865. func setAlignment(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) (bool, *xlsxAlignment) {
  866. if formatCellStyle.Alignment == nil {
  867. return false, &xlsxAlignment{}
  868. }
  869. var alignment = xlsxAlignment{
  870. Horizontal: formatCellStyle.Alignment.Horizontal,
  871. Indent: formatCellStyle.Alignment.Indent,
  872. JustifyLastLine: formatCellStyle.Alignment.JustifyLastLine,
  873. ReadingOrder: formatCellStyle.Alignment.ReadingOrder,
  874. RelativeIndent: formatCellStyle.Alignment.RelativeIndent,
  875. ShrinkToFit: formatCellStyle.Alignment.ShrinkToFit,
  876. TextRotation: formatCellStyle.Alignment.TextRotation,
  877. Vertical: formatCellStyle.Alignment.Vertical,
  878. WrapText: formatCellStyle.Alignment.WrapText,
  879. }
  880. return true, &alignment
  881. }
  882. // setBorders provides function to add border elements in the styles.xml by
  883. // given borders format settings.
  884. func setBorders(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  885. var styles = []string{
  886. "none",
  887. "thin",
  888. "medium",
  889. "dashed",
  890. "dotted",
  891. "thick",
  892. "double",
  893. "hair",
  894. "mediumDashed",
  895. "dashDot",
  896. "mediumDashDot",
  897. "dashDotDot",
  898. "mediumDashDotDot",
  899. "slantDashDot",
  900. }
  901. var border xlsxBorder
  902. for _, v := range formatCellStyle.Border {
  903. if v.Style > 13 || v.Style < 0 {
  904. continue
  905. }
  906. var color xlsxColor
  907. color.RGB = getPaletteColor(v.Color)
  908. switch v.Type {
  909. case "left":
  910. border.Left.Style = styles[v.Style]
  911. border.Left.Color = &color
  912. case "right":
  913. border.Right.Style = styles[v.Style]
  914. border.Right.Color = &color
  915. case "top":
  916. border.Top.Style = styles[v.Style]
  917. border.Top.Color = &color
  918. case "bottom":
  919. border.Bottom.Style = styles[v.Style]
  920. border.Bottom.Color = &color
  921. case "diagonalUp":
  922. border.Diagonal.Style = styles[v.Style]
  923. border.Diagonal.Color = &color
  924. border.DiagonalUp = true
  925. case "diagonalDown":
  926. border.Diagonal.Style = styles[v.Style]
  927. border.Diagonal.Color = &color
  928. border.DiagonalDown = true
  929. }
  930. }
  931. style.Borders.Count++
  932. style.Borders.Border = append(style.Borders.Border, &border)
  933. return style.Borders.Count - 1
  934. }
  935. // setCellXfs provides function to set describes all of the formatting for a
  936. // cell.
  937. func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment bool, alignment *xlsxAlignment) int {
  938. var xf xlsxXf
  939. xf.FontID = fontID
  940. if fontID != 0 {
  941. xf.ApplyFont = true
  942. }
  943. xf.NumFmtID = numFmtID
  944. if numFmtID != 0 {
  945. xf.ApplyNumberFormat = true
  946. }
  947. xf.FillID = fillID
  948. xf.BorderID = borderID
  949. style.CellXfs.Count++
  950. xf.Alignment = alignment
  951. xf.ApplyAlignment = applyAlignment
  952. style.CellXfs.Xf = append(style.CellXfs.Xf, xf)
  953. return style.CellXfs.Count - 1
  954. }
  955. // SetCellStyle provides function to add style attribute for cells by given
  956. // worksheet sheet index, coordinate area and style ID. Note that diagonalDown
  957. // and diagonalUp type border should be use same color in the same coordinate
  958. // area.
  959. //
  960. // For example create a borders of cell H9 on Sheet1:
  961. //
  962. // style, err := xlsx.NewStyle(`{"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}]}`)
  963. // if err != nil {
  964. // fmt.Println(err)
  965. // }
  966. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  967. //
  968. // Set gradient fill with vertical variants shading styles for cell H9 on
  969. // Sheet1:
  970. //
  971. // style, err := xlsx.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
  972. // if err != nil {
  973. // fmt.Println(err)
  974. // }
  975. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  976. //
  977. // Set solid style pattern fill for cell H9 on Sheet1:
  978. //
  979. // style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
  980. // if err != nil {
  981. // fmt.Println(err)
  982. // }
  983. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  984. //
  985. // Set alignment style for cell H9 on Sheet1:
  986. //
  987. // style, err := xlsx.NewStyle(`{"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}}`)
  988. // if err != nil {
  989. // fmt.Println(err)
  990. // }
  991. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  992. //
  993. // Dates and times in Excel are represented by real numbers, for example "Apr 7
  994. // 2017 12:00 PM" is represented by the number 42920.5. Set date and time format
  995. // for cell H9 on Sheet1:
  996. //
  997. // xlsx.SetCellValue("Sheet1", "H9", 42920.5)
  998. // style, err := xlsx.NewStyle(`{"number_format": 22}`)
  999. // if err != nil {
  1000. // fmt.Println(err)
  1001. // }
  1002. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1003. //
  1004. // Set font style for cell H9 on Sheet1:
  1005. //
  1006. // style, err := xlsx.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`)
  1007. // if err != nil {
  1008. // fmt.Println(err)
  1009. // }
  1010. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1011. //
  1012. func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
  1013. hcell = strings.ToUpper(hcell)
  1014. vcell = strings.ToUpper(vcell)
  1015. // Coordinate conversion, convert C1:B3 to 2,0,1,2.
  1016. hcol := string(strings.Map(letterOnlyMapF, hcell))
  1017. hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell))
  1018. hyAxis := hrow - 1
  1019. hxAxis := TitleToNumber(hcol)
  1020. vcol := string(strings.Map(letterOnlyMapF, vcell))
  1021. vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell))
  1022. vyAxis := vrow - 1
  1023. vxAxis := TitleToNumber(vcol)
  1024. if vxAxis < hxAxis {
  1025. hcell, vcell = vcell, hcell
  1026. vxAxis, hxAxis = hxAxis, vxAxis
  1027. }
  1028. if vyAxis < hyAxis {
  1029. hcell, vcell = vcell, hcell
  1030. vyAxis, hyAxis = hyAxis, vyAxis
  1031. }
  1032. // Correct the coordinate area, such correct C1:B3 to B1:C3.
  1033. hcell = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1)
  1034. vcell = ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
  1035. xlsx := f.workSheetReader(sheet)
  1036. completeRow(xlsx, vyAxis+1, vxAxis+1)
  1037. completeCol(xlsx, vyAxis+1, vxAxis+1)
  1038. for r, row := range xlsx.SheetData.Row {
  1039. for k, c := range row.C {
  1040. if checkCellInArea(c.R, hcell+":"+vcell) {
  1041. xlsx.SheetData.Row[r].C[k].S = styleID
  1042. }
  1043. }
  1044. }
  1045. }
  1046. // getPaletteColor provides function to convert the RBG color by given string.
  1047. func getPaletteColor(color string) string {
  1048. return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
  1049. }