styles.go 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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 values provided for
  48. // language glyphs where they occur) in different language.
  49. var langNumFmt = map[string]map[int]string{
  50. "zh-tw": {
  51. 27: "[$-404]e/m/d",
  52. 28: `[$-404]e"年"m"月"d"日"`,
  53. 29: `[$-404]e"年"m"月"d"日"`,
  54. 30: "m/d/yy",
  55. 31: `yyyy"年"m"月"d"日"`,
  56. 32: `hh"時"mm"分"`,
  57. 33: `hh"時"mm"分"ss"秒"`,
  58. 34: `上午/下午 hh"時"mm"分"`,
  59. 35: `上午/下午 hh"時"mm"分"ss"秒"`,
  60. 36: "[$-404]e/m/d",
  61. 50: "[$-404]e/m/d",
  62. 51: `[$-404]e"年"m"月"d"日"`,
  63. 52: `上午/下午 hh"時"mm"分"`,
  64. 53: `上午/下午 hh"時"mm"分"ss"秒"`,
  65. 54: `[$-404]e"年"m"月"d"日"`,
  66. 55: `上午/下午 hh"時"mm"分"`,
  67. 56: `上午/下午 hh"時"mm"分"ss"秒"`,
  68. 57: "[$-404]e/m/d",
  69. 58: `[$-404]e"年"m"月"d"日"`,
  70. },
  71. "zh-cn": {
  72. 27: `yyyy"年"m"月"`,
  73. 28: `m"月"d"日"`,
  74. 29: `m"月"d"日"`,
  75. 30: "m-d-yy",
  76. 31: `yyyy"年"m"月"d"日"`,
  77. 32: `h"时"mm"分"`,
  78. 33: `h"时"mm"分"ss"秒"`,
  79. 34: `上午/下午 h"时"mm"分"`,
  80. 35: `上午/下午 h"时"mm"分"ss"秒"`,
  81. 36: `yyyy"年"m"月"`,
  82. 50: `yyyy"年"m"月"`,
  83. 51: `m"月"d"日"`,
  84. 52: `yyyy"年"m"月"`,
  85. 53: `m"月"d"日"`,
  86. 54: `m"月"d"日"`,
  87. 55: `上午/下午 h"时"mm"分"`,
  88. 56: `上午/下午 h"时"mm"分"ss"秒"`,
  89. 57: `yyyy"年"m"月"`,
  90. 58: `m"月"d"日"`,
  91. },
  92. "zh-tw_unicode": {
  93. 27: "[$-404]e/m/d",
  94. 28: `[$-404]e"5E74"m"6708"d"65E5"`,
  95. 29: `[$-404]e"5E74"m"6708"d"65E5"`,
  96. 30: "m/d/yy",
  97. 31: `yyyy"5E74"m"6708"d"65E5"`,
  98. 32: `hh"6642"mm"5206"`,
  99. 33: `hh"6642"mm"5206"ss"79D2"`,
  100. 34: `4E0A5348/4E0B5348hh"6642"mm"5206"`,
  101. 35: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`,
  102. 36: "[$-404]e/m/d",
  103. 50: "[$-404]e/m/d",
  104. 51: `[$-404]e"5E74"m"6708"d"65E5"`,
  105. 52: `4E0A5348/4E0B5348hh"6642"mm"5206"`,
  106. 53: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`,
  107. 54: `[$-404]e"5E74"m"6708"d"65E5"`,
  108. 55: `4E0A5348/4E0B5348hh"6642"mm"5206"`,
  109. 56: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`,
  110. 57: "[$-404]e/m/d",
  111. 58: `[$-404]e"5E74"m"6708"d"65E5"`,
  112. },
  113. "zh-cn_unicode": {
  114. 27: `yyyy"5E74"m"6708"`,
  115. 28: `m"6708"d"65E5"`,
  116. 29: `m"6708"d"65E5"`,
  117. 30: "m-d-yy",
  118. 31: `yyyy"5E74"m"6708"d"65E5"`,
  119. 32: `h"65F6"mm"5206"`,
  120. 33: `h"65F6"mm"5206"ss"79D2"`,
  121. 34: `4E0A5348/4E0B5348h"65F6"mm"5206"`,
  122. 35: `4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2"`,
  123. 36: `yyyy"5E74"m"6708"`,
  124. 50: `yyyy"5E74"m"6708"`,
  125. 51: `m"6708"d"65E5"`,
  126. 52: `yyyy"5E74"m"6708"`,
  127. 53: `m"6708"d"65E5"`,
  128. 54: `m"6708"d"65E5"`,
  129. 55: `4E0A5348/4E0B5348h"65F6"mm"5206"`,
  130. 56: `4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2"`,
  131. 57: `yyyy"5E74"m"6708"`,
  132. 58: `m"6708"d"65E5"`,
  133. },
  134. "ja-jp": {
  135. 27: "[$-411]ge.m.d",
  136. 28: `[$-411]ggge"年"m"月"d"日"`,
  137. 29: `[$-411]ggge"年"m"月"d"日"`,
  138. 30: "m/d/yy",
  139. 31: `yyyy"年"m"月"d"日"`,
  140. 32: `h"時"mm"分"`,
  141. 33: `h"時"mm"分"ss"秒"`,
  142. 34: `yyyy"年"m"月"`,
  143. 35: `m"月"d"日"`,
  144. 36: "[$-411]ge.m.d",
  145. 50: "[$-411]ge.m.d",
  146. 51: `[$-411]ggge"年"m"月"d"日"`,
  147. 52: `yyyy"年"m"月"`,
  148. 53: `m"月"d"日"`,
  149. 54: `[$-411]ggge"年"m"月"d"日"`,
  150. 55: `yyyy"年"m"月"`,
  151. 56: `m"月"d"日"`,
  152. 57: "[$-411]ge.m.d",
  153. 58: `[$-411]ggge"年"m"月"d"日"`,
  154. },
  155. "ko-kr": {
  156. 27: `yyyy"年" mm"月" dd"日"`,
  157. 28: "mm-dd",
  158. 29: "mm-dd",
  159. 30: "mm-dd-yy",
  160. 31: `yyyy"년" mm"월" dd"일"`,
  161. 32: `h"시" mm"분"`,
  162. 33: `h"시" mm"분" ss"초"`,
  163. 34: `yyyy-mm-dd`,
  164. 35: `yyyy-mm-dd`,
  165. 36: `yyyy"年" mm"月" dd"日"`,
  166. 50: `yyyy"年" mm"月" dd"日"`,
  167. 51: "mm-dd",
  168. 52: "yyyy-mm-dd",
  169. 53: "yyyy-mm-dd",
  170. 54: "mm-dd",
  171. 55: "yyyy-mm-dd",
  172. 56: "yyyy-mm-dd",
  173. 57: `yyyy"年" mm"月" dd"日"`,
  174. 58: "mm-dd",
  175. },
  176. "ja-jp_unicode": {
  177. 27: "[$-411]ge.m.d",
  178. 28: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  179. 29: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  180. 30: "m/d/yy",
  181. 31: `yyyy"5E74"m"6708"d"65E5"`,
  182. 32: `h"6642"mm"5206"`,
  183. 33: `h"6642"mm"5206"ss"79D2"`,
  184. 34: `yyyy"5E74"m"6708"`,
  185. 35: `m"6708"d"65E5"`,
  186. 36: "[$-411]ge.m.d",
  187. 50: "[$-411]ge.m.d",
  188. 51: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  189. 52: `yyyy"5E74"m"6708"`,
  190. 53: `m"6708"d"65E5"`,
  191. 54: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  192. 55: `yyyy"5E74"m"6708"`,
  193. 56: `m"6708"d"65E5"`,
  194. 57: "[$-411]ge.m.d",
  195. 58: `[$-411]ggge"5E74"m"6708"d"65E5"`,
  196. },
  197. "ko-kr_unicode": {
  198. 27: `yyyy"5E74" mm"6708" dd"65E5"`,
  199. 28: "mm-dd",
  200. 29: "mm-dd",
  201. 30: "mm-dd-yy",
  202. 31: `yyyy"B144" mm"C6D4" dd"C77C"`,
  203. 32: `h"C2DC" mm"BD84"`,
  204. 33: `h"C2DC" mm"BD84" ss"CD08"`,
  205. 34: "yyyy-mm-dd",
  206. 35: "yyyy-mm-dd",
  207. 36: `yyyy"5E74" mm"6708" dd"65E5"`,
  208. 50: `yyyy"5E74" mm"6708" dd"65E5"`,
  209. 51: "mm-dd",
  210. 52: "yyyy-mm-dd",
  211. 53: "yyyy-mm-dd",
  212. 54: "mm-dd",
  213. 55: "yyyy-mm-dd",
  214. 56: "yyyy-mm-dd",
  215. 57: `yyyy"5E74" mm"6708" dd"65E5"`,
  216. 58: "mm-dd",
  217. },
  218. "th-th": {
  219. 59: "t0",
  220. 60: "t0.00",
  221. 61: "t#,##0",
  222. 62: "t#,##0.00",
  223. 67: "t0%",
  224. 68: "t0.00%",
  225. 69: "t# ?/?",
  226. 70: "t# ??/??",
  227. 71: "ว/ด/ปปปป",
  228. 72: "ว-ดดด-ปป",
  229. 73: "ว-ดดด",
  230. 74: "ดดด-ปป",
  231. 75: "ช:นน",
  232. 76: "ช:นน:ทท",
  233. 77: "ว/ด/ปปปป ช:นน",
  234. 78: "นน:ทท",
  235. 79: "[ช]:นน:ทท",
  236. 80: "นน:ทท.0",
  237. 81: "d/m/bb",
  238. },
  239. "th-th_unicode": {
  240. 59: "t0",
  241. 60: "t0.00",
  242. 61: "t#,##0",
  243. 62: "t#,##0.00",
  244. 67: "t0%",
  245. 68: "t0.00%",
  246. 69: "t# ?/?",
  247. 70: "t# ??/??",
  248. 71: "0E27/0E14/0E1B0E1B0E1B0E1B",
  249. 72: "0E27-0E140E140E14-0E1B0E1B",
  250. 73: "0E27-0E140E140E14",
  251. 74: "0E140E140E14-0E1B0E1B",
  252. 75: "0E0A:0E190E19",
  253. 76: "0E0A:0E190E19:0E170E17",
  254. 77: "0E27/0E14/0E1B0E1B0E1B0E1B 0E0A:0E190E19",
  255. 78: "0E190E19:0E170E17",
  256. 79: "[0E0A]:0E190E19:0E170E17",
  257. 80: "0E190E19:0E170E17.0",
  258. 81: "d/m/bb",
  259. },
  260. }
  261. // currencyNumFmt defined the currency number format map.
  262. var currencyNumFmt = map[int]string{
  263. 164: `"CN¥",##0.00`,
  264. 165: "[$$-409]#,##0.00",
  265. 166: "[$$-45C]#,##0.00",
  266. 167: "[$$-1004]#,##0.00",
  267. 168: "[$$-404]#,##0.00",
  268. 169: "[$$-C09]#,##0.00",
  269. 170: "[$$-2809]#,##0.00",
  270. 171: "[$$-1009]#,##0.00",
  271. 172: "[$$-2009]#,##0.00",
  272. 173: "[$$-1409]#,##0.00",
  273. 174: "[$$-4809]#,##0.00",
  274. 175: "[$$-2C09]#,##0.00",
  275. 176: "[$$-2409]#,##0.00",
  276. 177: "[$$-1000]#,##0.00",
  277. 178: `#,##0.00\ [$$-C0C]`,
  278. 179: "[$$-475]#,##0.00",
  279. 180: "[$$-83E]#,##0.00",
  280. 181: `[$$-86B]\ #,##0.00`,
  281. 182: `[$$-340A]\ #,##0.00`,
  282. 183: "[$$-240A]#,##0.00",
  283. 184: `[$$-300A]\ #,##0.00`,
  284. 185: "[$$-440A]#,##0.00",
  285. 186: "[$$-80A]#,##0.00",
  286. 187: "[$$-500A]#,##0.00",
  287. 188: "[$$-540A]#,##0.00",
  288. 189: `[$$-380A]\ #,##0.00`,
  289. 190: "[$£-809]#,##0.00",
  290. 191: "[$£-491]#,##0.00",
  291. 192: "[$£-452]#,##0.00",
  292. 193: "[$¥-804]#,##0.00",
  293. 194: "[$¥-411]#,##0.00",
  294. 195: "[$¥-478]#,##0.00",
  295. 196: "[$¥-451]#,##0.00",
  296. 197: "[$¥-480]#,##0.00",
  297. 198: "#,##0.00\\ [$\u058F-42B]",
  298. 199: "[$\u060B-463]#,##0.00",
  299. 200: "[$\u060B-48C]#,##0.00",
  300. 201: "[$\u09F3-845]\\ #,##0.00",
  301. 202: "#,##0.00[$\u17DB-453]",
  302. 203: "[$\u20A1-140A]#,##0.00",
  303. 204: "[$\u20A6-468]\\ #,##0.00",
  304. 205: "[$\u20A6-470]\\ #,##0.00",
  305. 206: "[$\u20A9-412]#,##0.00",
  306. 207: "[$\u20AA-40D]\\ #,##0.00",
  307. 208: "#,##0.00\\ [$\u20AB-42A]",
  308. 209: "#,##0.00\\ [$\u20AC-42D]",
  309. 210: "#,##0.00\\ [$\u20AC-47E]",
  310. 211: "#,##0.00\\ [$\u20AC-403]",
  311. 212: "#,##0.00\\ [$\u20AC-483]",
  312. 213: "[$\u20AC-813]\\ #,##0.00",
  313. 214: "[$\u20AC-413]\\ #,##0.00",
  314. 215: "[$\u20AC-1809]#,##0.00",
  315. 216: "#,##0.00\\ [$\u20AC-425]",
  316. 217: "[$\u20AC-2]\\ #,##0.00",
  317. 218: "#,##0.00\\ [$\u20AC-1]",
  318. 219: "#,##0.00\\ [$\u20AC-40B]",
  319. 220: "#,##0.00\\ [$\u20AC-80C]",
  320. 221: "#,##0.00\\ [$\u20AC-40C]",
  321. 222: "#,##0.00\\ [$\u20AC-140C]",
  322. 223: "#,##0.00\\ [$\u20AC-180C]",
  323. 224: "[$\u20AC-200C]#,##0.00",
  324. 225: "#,##0.00\\ [$\u20AC-456]",
  325. 226: "#,##0.00\\ [$\u20AC-C07]",
  326. 227: "#,##0.00\\ [$\u20AC-407]",
  327. 228: "#,##0.00\\ [$\u20AC-1007]",
  328. 229: "#,##0.00\\ [$\u20AC-408]",
  329. 230: "#,##0.00\\ [$\u20AC-243B]",
  330. 231: "[$\u20AC-83C]#,##0.00",
  331. 232: "[$\u20AC-410]\\ #,##0.00",
  332. 233: "[$\u20AC-476]#,##0.00",
  333. 234: "#,##0.00\\ [$\u20AC-2C1A]",
  334. 235: "[$\u20AC-426]\\ #,##0.00",
  335. 236: "#,##0.00\\ [$\u20AC-427]",
  336. 237: "#,##0.00\\ [$\u20AC-82E]",
  337. 238: "#,##0.00\\ [$\u20AC-46E]",
  338. 239: "[$\u20AC-43A]#,##0.00",
  339. 240: "#,##0.00\\ [$\u20AC-C3B]",
  340. 241: "#,##0.00\\ [$\u20AC-482]",
  341. 242: "#,##0.00\\ [$\u20AC-816]",
  342. 243: "#,##0.00\\ [$\u20AC-301A]",
  343. 244: "#,##0.00\\ [$\u20AC-203B]",
  344. 245: "#,##0.00\\ [$\u20AC-41B]",
  345. 246: "#,##0.00\\ [$\u20AC-424]",
  346. 247: "#,##0.00\\ [$\u20AC-C0A]",
  347. 248: "#,##0.00\\ [$\u20AC-81D]",
  348. 249: "#,##0.00\\ [$\u20AC-484]",
  349. 250: "#,##0.00\\ [$\u20AC-42E]",
  350. 251: "[$\u20AC-462]\\ #,##0.00",
  351. 252: "#,##0.00\\ [$₭-454]",
  352. 253: "#,##0.00\\ [$₮-450]",
  353. 254: "[$\u20AE-C50]#,##0.00",
  354. 255: "[$\u20B1-3409]#,##0.00",
  355. 256: "[$\u20B1-464]#,##0.00",
  356. 257: "#,##0.00[$\u20B4-422]",
  357. 258: "[$\u20B8-43F]#,##0.00",
  358. 259: "[$\u20B9-460]#,##0.00",
  359. 260: "[$\u20B9-4009]\\ #,##0.00",
  360. 261: "[$\u20B9-447]\\ #,##0.00",
  361. 262: "[$\u20B9-439]\\ #,##0.00",
  362. 263: "[$\u20B9-44B]\\ #,##0.00",
  363. 264: "[$\u20B9-860]#,##0.00",
  364. 265: "[$\u20B9-457]\\ #,##0.00",
  365. 266: "[$\u20B9-458]#,##0.00",
  366. 267: "[$\u20B9-44E]\\ #,##0.00",
  367. 268: "[$\u20B9-861]#,##0.00",
  368. 269: "[$\u20B9-448]\\ #,##0.00",
  369. 270: "[$\u20B9-446]\\ #,##0.00",
  370. 271: "[$\u20B9-44F]\\ #,##0.00",
  371. 272: "[$\u20B9-459]#,##0.00",
  372. 273: "[$\u20B9-449]\\ #,##0.00",
  373. 274: "[$\u20B9-820]#,##0.00",
  374. 275: "#,##0.00\\ [$\u20BA-41F]",
  375. 276: "#,##0.00\\ [$\u20BC-42C]",
  376. 277: "#,##0.00\\ [$\u20BC-82C]",
  377. 278: "#,##0.00\\ [$\u20BD-419]",
  378. 279: "#,##0.00[$\u20BD-485]",
  379. 280: "#,##0.00\\ [$\u20BE-437]",
  380. 281: "[$B/.-180A]\\ #,##0.00",
  381. 282: "[$Br-472]#,##0.00",
  382. 283: "[$Br-477]#,##0.00",
  383. 284: "#,##0.00[$Br-473]",
  384. 285: "[$Bs-46B]\\ #,##0.00",
  385. 286: "[$Bs-400A]\\ #,##0.00",
  386. 287: "[$Bs.-200A]\\ #,##0.00",
  387. 288: "[$BWP-832]\\ #,##0.00",
  388. 289: "[$C$-4C0A]#,##0.00",
  389. 290: "[$CA$-85D]#,##0.00",
  390. 291: "[$CA$-47C]#,##0.00",
  391. 292: "[$CA$-45D]#,##0.00",
  392. 293: "[$CFA-340C]#,##0.00",
  393. 294: "[$CFA-280C]#,##0.00",
  394. 295: "#,##0.00\\ [$CFA-867]",
  395. 296: "#,##0.00\\ [$CFA-488]",
  396. 297: "#,##0.00\\ [$CHF-100C]",
  397. 298: "[$CHF-1407]\\ #,##0.00",
  398. 299: "[$CHF-807]\\ #,##0.00",
  399. 300: "[$CHF-810]\\ #,##0.00",
  400. 301: "[$CHF-417]\\ #,##0.00",
  401. 302: "[$CLP-47A]\\ #,##0.00",
  402. 303: "[$CN¥-850]#,##0.00",
  403. 304: "#,##0.00\\ [$DZD-85F]",
  404. 305: "[$FCFA-2C0C]#,##0.00",
  405. 306: "#,##0.00\\ [$Ft-40E]",
  406. 307: "[$G-3C0C]#,##0.00",
  407. 308: "[$Gs.-3C0A]\\ #,##0.00",
  408. 309: "[$GTQ-486]#,##0.00",
  409. 310: "[$HK$-C04]#,##0.00",
  410. 311: "[$HK$-3C09]#,##0.00",
  411. 312: "#,##0.00\\ [$HRK-41A]",
  412. 313: "[$IDR-3809]#,##0.00",
  413. 314: "[$IQD-492]#,##0.00",
  414. 315: "#,##0.00\\ [$ISK-40F]",
  415. 316: "[$K-455]#,##0.00",
  416. 317: "#,##0.00\\ [$K\u010D-405]",
  417. 318: "#,##0.00\\ [$KM-141A]",
  418. 319: "#,##0.00\\ [$KM-101A]",
  419. 320: "#,##0.00\\ [$KM-181A]",
  420. 321: "[$kr-438]\\ #,##0.00",
  421. 322: "[$kr-43B]\\ #,##0.00",
  422. 323: "#,##0.00\\ [$kr-83B]",
  423. 324: "[$kr-414]\\ #,##0.00",
  424. 325: "[$kr-814]\\ #,##0.00",
  425. 326: "#,##0.00\\ [$kr-41D]",
  426. 327: "[$kr.-406]\\ #,##0.00",
  427. 328: "[$kr.-46F]\\ #,##0.00",
  428. 329: "[$Ksh-441]#,##0.00",
  429. 330: "[$L-818]#,##0.00",
  430. 331: "[$L-819]#,##0.00",
  431. 332: "[$L-480A]\\ #,##0.00",
  432. 333: "#,##0.00\\ [$Lek\u00EB-41C]",
  433. 334: "[$MAD-45F]#,##0.00",
  434. 335: "[$MAD-380C]#,##0.00",
  435. 336: "#,##0.00\\ [$MAD-105F]",
  436. 337: "[$MOP$-1404]#,##0.00",
  437. 338: "#,##0.00\\ [$MVR-465]_-",
  438. 339: "#,##0.00[$Nfk-873]",
  439. 340: "[$NGN-466]#,##0.00",
  440. 341: "[$NGN-467]#,##0.00",
  441. 342: "[$NGN-469]#,##0.00",
  442. 343: "[$NGN-471]#,##0.00",
  443. 344: "[$NOK-103B]\\ #,##0.00",
  444. 345: "[$NOK-183B]\\ #,##0.00",
  445. 346: "[$NZ$-481]#,##0.00",
  446. 347: "[$PKR-859]\\ #,##0.00",
  447. 348: "[$PYG-474]#,##0.00",
  448. 349: "[$Q-100A]#,##0.00",
  449. 350: "[$R-436]\\ #,##0.00",
  450. 351: "[$R-1C09]\\ #,##0.00",
  451. 352: "[$R-435]\\ #,##0.00",
  452. 353: "[$R$-416]\\ #,##0.00",
  453. 354: "[$RD$-1C0A]#,##0.00",
  454. 355: "#,##0.00\\ [$RF-487]",
  455. 356: "[$RM-4409]#,##0.00",
  456. 357: "[$RM-43E]#,##0.00",
  457. 358: "#,##0.00\\ [$RON-418]",
  458. 359: "[$Rp-421]#,##0.00",
  459. 360: "[$Rs-420]#,##0.00_-",
  460. 361: "[$Rs.-849]\\ #,##0.00",
  461. 362: "#,##0.00\\ [$RSD-81A]",
  462. 363: "#,##0.00\\ [$RSD-C1A]",
  463. 364: "#,##0.00\\ [$RUB-46D]",
  464. 365: "#,##0.00\\ [$RUB-444]",
  465. 366: "[$S/.-C6B]\\ #,##0.00",
  466. 367: "[$S/.-280A]\\ #,##0.00",
  467. 368: "#,##0.00\\ [$SEK-143B]",
  468. 369: "#,##0.00\\ [$SEK-1C3B]",
  469. 370: "#,##0.00\\ [$so\u02BBm-443]",
  470. 371: "#,##0.00\\ [$so\u02BBm-843]",
  471. 372: "#,##0.00\\ [$SYP-45A]",
  472. 373: "[$THB-41E]#,##0.00",
  473. 374: "#,##0.00[$TMT-442]",
  474. 375: "[$US$-3009]#,##0.00",
  475. 376: "[$ZAR-46C]\\ #,##0.00",
  476. 377: "[$ZAR-430]#,##0.00",
  477. 378: "[$ZAR-431]#,##0.00",
  478. 379: "[$ZAR-432]\\ #,##0.00",
  479. 380: "[$ZAR-433]#,##0.00",
  480. 381: "[$ZAR-434]\\ #,##0.00",
  481. 382: "#,##0.00\\ [$z\u0142-415]",
  482. 383: "#,##0.00\\ [$\u0434\u0435\u043D-42F]",
  483. 384: "#,##0.00\\ [$КМ-201A]",
  484. 385: "#,##0.00\\ [$КМ-1C1A]",
  485. 386: "#,##0.00\\ [$\u043B\u0432.-402]",
  486. 387: "#,##0.00\\ [$р.-423]",
  487. 388: "#,##0.00\\ [$\u0441\u043E\u043C-440]",
  488. 389: "#,##0.00\\ [$\u0441\u043E\u043C-428]",
  489. 390: "[$\u062C.\u0645.-C01]\\ #,##0.00_-",
  490. 391: "[$\u062F.\u0623.-2C01]\\ #,##0.00_-",
  491. 392: "[$\u062F.\u0625.-3801]\\ #,##0.00_-",
  492. 393: "[$\u062F.\u0628.-3C01]\\ #,##0.00_-",
  493. 394: "[$\u062F.\u062A.-1C01]\\ #,##0.00_-",
  494. 395: "[$\u062F.\u062C.-1401]\\ #,##0.00_-",
  495. 396: "[$\u062F.\u0639.-801]\\ #,##0.00_-",
  496. 397: "[$\u062F.\u0643.-3401]\\ #,##0.00_-",
  497. 398: "[$\u062F.\u0644.-1001]#,##0.00_-",
  498. 399: "[$\u062F.\u0645.-1801]\\ #,##0.00_-",
  499. 400: "[$\u0631-846]\\ #,##0.00",
  500. 401: "[$\u0631.\u0633.-401]\\ #,##0.00_-",
  501. 402: "[$\u0631.\u0639.-2001]\\ #,##0.00_-",
  502. 403: "[$\u0631.\u0642.-4001]\\ #,##0.00_-",
  503. 404: "[$\u0631.\u064A.-2401]\\ #,##0.00_-",
  504. 405: "[$\u0631\u06CC\u0627\u0644-429]#,##0.00_-",
  505. 406: "[$\u0644.\u0633.-2801]\\ #,##0.00_-",
  506. 407: "[$\u0644.\u0644.-3001]\\ #,##0.00_-",
  507. 408: "[$\u1265\u122D-45E]#,##0.00",
  508. 409: "[$\u0930\u0942-461]#,##0.00",
  509. 410: "[$\u0DBB\u0DD4.-45B]\\ #,##0.00",
  510. 411: "[$ADP]\\ #,##0.00",
  511. 412: "[$AED]\\ #,##0.00",
  512. 413: "[$AFA]\\ #,##0.00",
  513. 414: "[$AFN]\\ #,##0.00",
  514. 415: "[$ALL]\\ #,##0.00",
  515. 416: "[$AMD]\\ #,##0.00",
  516. 417: "[$ANG]\\ #,##0.00",
  517. 418: "[$AOA]\\ #,##0.00",
  518. 419: "[$ARS]\\ #,##0.00",
  519. 420: "[$ATS]\\ #,##0.00",
  520. 421: "[$AUD]\\ #,##0.00",
  521. 422: "[$AWG]\\ #,##0.00",
  522. 423: "[$AZM]\\ #,##0.00",
  523. 424: "[$AZN]\\ #,##0.00",
  524. 425: "[$BAM]\\ #,##0.00",
  525. 426: "[$BBD]\\ #,##0.00",
  526. 427: "[$BDT]\\ #,##0.00",
  527. 428: "[$BEF]\\ #,##0.00",
  528. 429: "[$BGL]\\ #,##0.00",
  529. 430: "[$BGN]\\ #,##0.00",
  530. 431: "[$BHD]\\ #,##0.00",
  531. 432: "[$BIF]\\ #,##0.00",
  532. 433: "[$BMD]\\ #,##0.00",
  533. 434: "[$BND]\\ #,##0.00",
  534. 435: "[$BOB]\\ #,##0.00",
  535. 436: "[$BOV]\\ #,##0.00",
  536. 437: "[$BRL]\\ #,##0.00",
  537. 438: "[$BSD]\\ #,##0.00",
  538. 439: "[$BTN]\\ #,##0.00",
  539. 440: "[$BWP]\\ #,##0.00",
  540. 441: "[$BYR]\\ #,##0.00",
  541. 442: "[$BZD]\\ #,##0.00",
  542. 443: "[$CAD]\\ #,##0.00",
  543. 444: "[$CDF]\\ #,##0.00",
  544. 445: "[$CHE]\\ #,##0.00",
  545. 446: "[$CHF]\\ #,##0.00",
  546. 447: "[$CHW]\\ #,##0.00",
  547. 448: "[$CLF]\\ #,##0.00",
  548. 449: "[$CLP]\\ #,##0.00",
  549. 450: "[$CNY]\\ #,##0.00",
  550. 451: "[$COP]\\ #,##0.00",
  551. 452: "[$COU]\\ #,##0.00",
  552. 453: "[$CRC]\\ #,##0.00",
  553. 454: "[$CSD]\\ #,##0.00",
  554. 455: "[$CUC]\\ #,##0.00",
  555. 456: "[$CVE]\\ #,##0.00",
  556. 457: "[$CYP]\\ #,##0.00",
  557. 458: "[$CZK]\\ #,##0.00",
  558. 459: "[$DEM]\\ #,##0.00",
  559. 460: "[$DJF]\\ #,##0.00",
  560. 461: "[$DKK]\\ #,##0.00",
  561. 462: "[$DOP]\\ #,##0.00",
  562. 463: "[$DZD]\\ #,##0.00",
  563. 464: "[$ECS]\\ #,##0.00",
  564. 465: "[$ECV]\\ #,##0.00",
  565. 466: "[$EEK]\\ #,##0.00",
  566. 467: "[$EGP]\\ #,##0.00",
  567. 468: "[$ERN]\\ #,##0.00",
  568. 469: "[$ESP]\\ #,##0.00",
  569. 470: "[$ETB]\\ #,##0.00",
  570. 471: "[$EUR]\\ #,##0.00",
  571. 472: "[$FIM]\\ #,##0.00",
  572. 473: "[$FJD]\\ #,##0.00",
  573. 474: "[$FKP]\\ #,##0.00",
  574. 475: "[$FRF]\\ #,##0.00",
  575. 476: "[$GBP]\\ #,##0.00",
  576. 477: "[$GEL]\\ #,##0.00",
  577. 478: "[$GHC]\\ #,##0.00",
  578. 479: "[$GHS]\\ #,##0.00",
  579. 480: "[$GIP]\\ #,##0.00",
  580. 481: "[$GMD]\\ #,##0.00",
  581. 482: "[$GNF]\\ #,##0.00",
  582. 483: "[$GRD]\\ #,##0.00",
  583. 484: "[$GTQ]\\ #,##0.00",
  584. 485: "[$GYD]\\ #,##0.00",
  585. 486: "[$HKD]\\ #,##0.00",
  586. 487: "[$HNL]\\ #,##0.00",
  587. 488: "[$HRK]\\ #,##0.00",
  588. 489: "[$HTG]\\ #,##0.00",
  589. 490: "[$HUF]\\ #,##0.00",
  590. 491: "[$IDR]\\ #,##0.00",
  591. 492: "[$IEP]\\ #,##0.00",
  592. 493: "[$ILS]\\ #,##0.00",
  593. 494: "[$INR]\\ #,##0.00",
  594. 495: "[$IQD]\\ #,##0.00",
  595. 496: "[$IRR]\\ #,##0.00",
  596. 497: "[$ISK]\\ #,##0.00",
  597. 498: "[$ITL]\\ #,##0.00",
  598. 499: "[$JMD]\\ #,##0.00",
  599. 500: "[$JOD]\\ #,##0.00",
  600. 501: "[$JPY]\\ #,##0.00",
  601. 502: "[$KAF]\\ #,##0.00",
  602. 503: "[$KES]\\ #,##0.00",
  603. 504: "[$KGS]\\ #,##0.00",
  604. 505: "[$KHR]\\ #,##0.00",
  605. 506: "[$KMF]\\ #,##0.00",
  606. 507: "[$KPW]\\ #,##0.00",
  607. 508: "[$KRW]\\ #,##0.00",
  608. 509: "[$KWD]\\ #,##0.00",
  609. 510: "[$KYD]\\ #,##0.00",
  610. 511: "[$KZT]\\ #,##0.00",
  611. 512: "[$LAK]\\ #,##0.00",
  612. 513: "[$LBP]\\ #,##0.00",
  613. 514: "[$LKR]\\ #,##0.00",
  614. 515: "[$LRD]\\ #,##0.00",
  615. 516: "[$LSL]\\ #,##0.00",
  616. 517: "[$LTL]\\ #,##0.00",
  617. 518: "[$LUF]\\ #,##0.00",
  618. 519: "[$LVL]\\ #,##0.00",
  619. 520: "[$LYD]\\ #,##0.00",
  620. 521: "[$MAD]\\ #,##0.00",
  621. 522: "[$MDL]\\ #,##0.00",
  622. 523: "[$MGA]\\ #,##0.00",
  623. 524: "[$MGF]\\ #,##0.00",
  624. 525: "[$MKD]\\ #,##0.00",
  625. 526: "[$MMK]\\ #,##0.00",
  626. 527: "[$MNT]\\ #,##0.00",
  627. 528: "[$MOP]\\ #,##0.00",
  628. 529: "[$MRO]\\ #,##0.00",
  629. 530: "[$MTL]\\ #,##0.00",
  630. 531: "[$MUR]\\ #,##0.00",
  631. 532: "[$MVR]\\ #,##0.00",
  632. 533: "[$MWK]\\ #,##0.00",
  633. 534: "[$MXN]\\ #,##0.00",
  634. 535: "[$MXV]\\ #,##0.00",
  635. 536: "[$MYR]\\ #,##0.00",
  636. 537: "[$MZM]\\ #,##0.00",
  637. 538: "[$MZN]\\ #,##0.00",
  638. 539: "[$NAD]\\ #,##0.00",
  639. 540: "[$NGN]\\ #,##0.00",
  640. 541: "[$NIO]\\ #,##0.00",
  641. 542: "[$NLG]\\ #,##0.00",
  642. 543: "[$NOK]\\ #,##0.00",
  643. 544: "[$NPR]\\ #,##0.00",
  644. 545: "[$NTD]\\ #,##0.00",
  645. 546: "[$NZD]\\ #,##0.00",
  646. 547: "[$OMR]\\ #,##0.00",
  647. 548: "[$PAB]\\ #,##0.00",
  648. 549: "[$PEN]\\ #,##0.00",
  649. 550: "[$PGK]\\ #,##0.00",
  650. 551: "[$PHP]\\ #,##0.00",
  651. 552: "[$PKR]\\ #,##0.00",
  652. 553: "[$PLN]\\ #,##0.00",
  653. 554: "[$PTE]\\ #,##0.00",
  654. 555: "[$PYG]\\ #,##0.00",
  655. 556: "[$QAR]\\ #,##0.00",
  656. 557: "[$ROL]\\ #,##0.00",
  657. 558: "[$RON]\\ #,##0.00",
  658. 559: "[$RSD]\\ #,##0.00",
  659. 560: "[$RUB]\\ #,##0.00",
  660. 561: "[$RUR]\\ #,##0.00",
  661. 562: "[$RWF]\\ #,##0.00",
  662. 563: "[$SAR]\\ #,##0.00",
  663. 564: "[$SBD]\\ #,##0.00",
  664. 565: "[$SCR]\\ #,##0.00",
  665. 566: "[$SDD]\\ #,##0.00",
  666. 567: "[$SDG]\\ #,##0.00",
  667. 568: "[$SDP]\\ #,##0.00",
  668. 569: "[$SEK]\\ #,##0.00",
  669. 570: "[$SGD]\\ #,##0.00",
  670. 571: "[$SHP]\\ #,##0.00",
  671. 572: "[$SIT]\\ #,##0.00",
  672. 573: "[$SKK]\\ #,##0.00",
  673. 574: "[$SLL]\\ #,##0.00",
  674. 575: "[$SOS]\\ #,##0.00",
  675. 576: "[$SPL]\\ #,##0.00",
  676. 577: "[$SRD]\\ #,##0.00",
  677. 578: "[$SRG]\\ #,##0.00",
  678. 579: "[$STD]\\ #,##0.00",
  679. 580: "[$SVC]\\ #,##0.00",
  680. 581: "[$SYP]\\ #,##0.00",
  681. 582: "[$SZL]\\ #,##0.00",
  682. 583: "[$THB]\\ #,##0.00",
  683. 584: "[$TJR]\\ #,##0.00",
  684. 585: "[$TJS]\\ #,##0.00",
  685. 586: "[$TMM]\\ #,##0.00",
  686. 587: "[$TMT]\\ #,##0.00",
  687. 588: "[$TND]\\ #,##0.00",
  688. 589: "[$TOP]\\ #,##0.00",
  689. 590: "[$TRL]\\ #,##0.00",
  690. 591: "[$TRY]\\ #,##0.00",
  691. 592: "[$TTD]\\ #,##0.00",
  692. 593: "[$TWD]\\ #,##0.00",
  693. 594: "[$TZS]\\ #,##0.00",
  694. 595: "[$UAH]\\ #,##0.00",
  695. 596: "[$UGX]\\ #,##0.00",
  696. 597: "[$USD]\\ #,##0.00",
  697. 598: "[$USN]\\ #,##0.00",
  698. 599: "[$USS]\\ #,##0.00",
  699. 600: "[$UYI]\\ #,##0.00",
  700. 601: "[$UYU]\\ #,##0.00",
  701. 602: "[$UZS]\\ #,##0.00",
  702. 603: "[$VEB]\\ #,##0.00",
  703. 604: "[$VEF]\\ #,##0.00",
  704. 605: "[$VND]\\ #,##0.00",
  705. 606: "[$VUV]\\ #,##0.00",
  706. 607: "[$WST]\\ #,##0.00",
  707. 608: "[$XAF]\\ #,##0.00",
  708. 609: "[$XAG]\\ #,##0.00",
  709. 610: "[$XAU]\\ #,##0.00",
  710. 611: "[$XB5]\\ #,##0.00",
  711. 612: "[$XBA]\\ #,##0.00",
  712. 613: "[$XBB]\\ #,##0.00",
  713. 614: "[$XBC]\\ #,##0.00",
  714. 615: "[$XBD]\\ #,##0.00",
  715. 616: "[$XCD]\\ #,##0.00",
  716. 617: "[$XDR]\\ #,##0.00",
  717. 618: "[$XFO]\\ #,##0.00",
  718. 619: "[$XFU]\\ #,##0.00",
  719. 620: "[$XOF]\\ #,##0.00",
  720. 621: "[$XPD]\\ #,##0.00",
  721. 622: "[$XPF]\\ #,##0.00",
  722. 623: "[$XPT]\\ #,##0.00",
  723. 624: "[$XTS]\\ #,##0.00",
  724. 625: "[$XXX]\\ #,##0.00",
  725. 626: "[$YER]\\ #,##0.00",
  726. 627: "[$YUM]\\ #,##0.00",
  727. 628: "[$ZAR]\\ #,##0.00",
  728. 629: "[$ZMK]\\ #,##0.00",
  729. 630: "[$ZMW]\\ #,##0.00",
  730. 631: "[$ZWD]\\ #,##0.00",
  731. 632: "[$ZWL]\\ #,##0.00",
  732. 633: "[$ZWN]\\ #,##0.00",
  733. 634: "[$ZWR]\\ #,##0.00",
  734. }
  735. // builtInNumFmtFunc defined the format conversion functions map. Partial format
  736. // code doesn't support currently and will return original string.
  737. var builtInNumFmtFunc = map[int]func(i int, v string) string{
  738. 0: formatToString,
  739. 1: formatToInt,
  740. 2: formatToFloat,
  741. 3: formatToInt,
  742. 4: formatToFloat,
  743. 9: formatToC,
  744. 10: formatToD,
  745. 11: formatToE,
  746. 12: formatToString, // Doesn't support currently
  747. 13: formatToString, // Doesn't support currently
  748. 14: parseTime,
  749. 15: parseTime,
  750. 16: parseTime,
  751. 17: parseTime,
  752. 18: parseTime,
  753. 19: parseTime,
  754. 20: parseTime,
  755. 21: parseTime,
  756. 22: parseTime,
  757. 37: formatToA,
  758. 38: formatToA,
  759. 39: formatToB,
  760. 40: formatToB,
  761. 41: formatToString, // Doesn't support currently
  762. 42: formatToString, // Doesn't support currently
  763. 43: formatToString, // Doesn't support currently
  764. 44: formatToString, // Doesn't support currently
  765. 45: parseTime,
  766. 46: parseTime,
  767. 47: parseTime,
  768. 48: formatToE,
  769. 49: formatToString,
  770. }
  771. // formatToString provides function to return original string by given built-in
  772. // number formats code and cell string.
  773. func formatToString(i int, v string) string {
  774. return v
  775. }
  776. // formatToInt provides function to convert original string to integer format as
  777. // string type by given built-in number formats code and cell string.
  778. func formatToInt(i int, v string) string {
  779. f, err := strconv.ParseFloat(v, 64)
  780. if err != nil {
  781. return v
  782. }
  783. return fmt.Sprintf("%d", int(f))
  784. }
  785. // formatToFloat provides function to convert original string to float format as
  786. // string type by given built-in number formats code and cell string.
  787. func formatToFloat(i int, v string) string {
  788. f, err := strconv.ParseFloat(v, 64)
  789. if err != nil {
  790. return v
  791. }
  792. return fmt.Sprintf("%.2f", f)
  793. }
  794. // formatToA provides function to convert original string to special format as
  795. // string type by given built-in number formats code and cell string.
  796. func formatToA(i int, v string) string {
  797. f, err := strconv.ParseFloat(v, 64)
  798. if err != nil {
  799. return v
  800. }
  801. if f < 0 {
  802. t := int(math.Abs(f))
  803. return fmt.Sprintf("(%d)", t)
  804. }
  805. t := int(f)
  806. return fmt.Sprintf("%d", t)
  807. }
  808. // formatToB provides function to convert original string to special format as
  809. // string type by given built-in number formats code and cell string.
  810. func formatToB(i int, v string) string {
  811. f, err := strconv.ParseFloat(v, 64)
  812. if err != nil {
  813. return v
  814. }
  815. if f < 0 {
  816. return fmt.Sprintf("(%.2f)", f)
  817. }
  818. return fmt.Sprintf("%.2f", f)
  819. }
  820. // formatToC provides function to convert original string to special format as
  821. // string type by given built-in number formats code and cell string.
  822. func formatToC(i int, v string) string {
  823. f, err := strconv.ParseFloat(v, 64)
  824. if err != nil {
  825. return v
  826. }
  827. f = f * 100
  828. return fmt.Sprintf("%d%%", int(f))
  829. }
  830. // formatToD provides function to convert original string to special format as
  831. // string type by given built-in number formats code and cell string.
  832. func formatToD(i int, v string) string {
  833. f, err := strconv.ParseFloat(v, 64)
  834. if err != nil {
  835. return v
  836. }
  837. f = f * 100
  838. return fmt.Sprintf("%.2f%%", f)
  839. }
  840. // formatToE provides function to convert original string to special format as
  841. // string type by given built-in number formats code and cell string.
  842. func formatToE(i int, v string) string {
  843. f, err := strconv.ParseFloat(v, 64)
  844. if err != nil {
  845. return v
  846. }
  847. return fmt.Sprintf("%.e", f)
  848. }
  849. // parseTime provides function to returns a string parsed using time.Time.
  850. // Replace Excel placeholders with Go time placeholders. For example, replace
  851. // yyyy with 2006. These are in a specific order, due to the fact that m is used
  852. // in month, minute, and am/pm. It would be easier to fix that with regular
  853. // expressions, but if it's possible to keep this simple it would be easier to
  854. // maintain. Full-length month and days (e.g. March, Tuesday) have letters in
  855. // them that would be replaced by other characters below (such as the 'h' in
  856. // March, or the 'd' in Tuesday) below. First we convert them to arbitrary
  857. // characters unused in Excel Date formats, and then at the end, turn them to
  858. // what they should actually be.
  859. func parseTime(i int, v string) string {
  860. f, err := strconv.ParseFloat(v, 64)
  861. if err != nil {
  862. return v
  863. }
  864. val := timeFromExcelTime(f, false)
  865. format := builtInNumFmt[i]
  866. replacements := []struct{ xltime, gotime string }{
  867. {"yyyy", "2006"},
  868. {"yy", "06"},
  869. {"mmmm", "%%%%"},
  870. {"dddd", "&&&&"},
  871. {"dd", "02"},
  872. {"d", "2"},
  873. {"mmm", "Jan"},
  874. {"mmss", "0405"},
  875. {"ss", "05"},
  876. {"hh", "15"},
  877. {"h", "3"},
  878. {"mm:", "04:"},
  879. {":mm", ":04"},
  880. {"mm", "01"},
  881. {"am/pm", "pm"},
  882. {"m/", "1/"},
  883. {"%%%%", "January"},
  884. {"&&&&", "Monday"},
  885. }
  886. for _, repl := range replacements {
  887. format = strings.Replace(format, repl.xltime, repl.gotime, 1)
  888. }
  889. // If the hour is optional, strip it out, along with the possible dangling
  890. // colon that would remain.
  891. if val.Hour() < 1 {
  892. format = strings.Replace(format, "]:", "]", 1)
  893. format = strings.Replace(format, "[3]", "", 1)
  894. format = strings.Replace(format, "[15]", "", 1)
  895. } else {
  896. format = strings.Replace(format, "[3]", "3", 1)
  897. format = strings.Replace(format, "[15]", "15", 1)
  898. }
  899. return val.Format(format)
  900. }
  901. // stylesReader provides function to get the pointer to the structure after
  902. // deserialization of xl/styles.xml.
  903. func (f *File) stylesReader() *xlsxStyleSheet {
  904. if f.Styles == nil {
  905. var styleSheet xlsxStyleSheet
  906. xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
  907. f.Styles = &styleSheet
  908. }
  909. return f.Styles
  910. }
  911. // styleSheetWriter provides function to save xl/styles.xml after serialize
  912. // structure.
  913. func (f *File) styleSheetWriter() {
  914. if f.Styles != nil {
  915. output, _ := xml.Marshal(f.Styles)
  916. f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpace(string(output)))
  917. }
  918. }
  919. // parseFormatStyleSet provides function to parse the format settings of the
  920. // borders.
  921. func parseFormatStyleSet(style string) (*formatCellStyle, error) {
  922. format := formatCellStyle{
  923. DecimalPlaces: 2,
  924. }
  925. err := json.Unmarshal([]byte(style), &format)
  926. return &format, err
  927. }
  928. // NewStyle provides function to create style for cells by given style format.
  929. // Note that the color field uses RGB color code.
  930. //
  931. // The following shows the border styles sorted by excelize index number:
  932. //
  933. // | Index | Name | Weight | Style |
  934. // +-------+---------------+--------+-------------+
  935. // | 0 | None | 0 | |
  936. // | 1 | Continuous | 1 | ----------- |
  937. // | 2 | Continuous | 2 | ----------- |
  938. // | 3 | Dash | 1 | - - - - - - |
  939. // | 4 | Dot | 1 | . . . . . . |
  940. // | 5 | Continuous | 3 | ----------- |
  941. // | 6 | Double | 3 | =========== |
  942. // | 7 | Continuous | 0 | ----------- |
  943. // | 8 | Dash | 2 | - - - - - - |
  944. // | 9 | Dash Dot | 1 | - . - . - . |
  945. // | 10 | Dash Dot | 2 | - . - . - . |
  946. // | 11 | Dash Dot Dot | 1 | - . . - . . |
  947. // | 12 | Dash Dot Dot | 2 | - . . - . . |
  948. // | 13 | SlantDash Dot | 2 | / - . / - . |
  949. //
  950. // The following shows the borders in the order shown in the Excel dialog:
  951. //
  952. // | Index | Style | Index | Style |
  953. // +-------+-------------+-------+-------------+
  954. // | 0 | None | 12 | - . . - . . |
  955. // | 7 | ----------- | 13 | / - . / - . |
  956. // | 4 | . . . . . . | 10 | - . - . - . |
  957. // | 11 | - . . - . . | 8 | - - - - - - |
  958. // | 9 | - . - . - . | 2 | ----------- |
  959. // | 3 | - - - - - - | 5 | ----------- |
  960. // | 1 | ----------- | 6 | =========== |
  961. //
  962. // The following shows the shading styles sorted by excelize index number:
  963. //
  964. // | Index | Style | Index | Style |
  965. // +-------+-----------------+-------+-----------------+
  966. // | 0 | Horizontal | 3 | Diagonal down |
  967. // | 1 | Vertical | 4 | From corner |
  968. // | 2 | Diagonal Up | 5 | From center |
  969. //
  970. // The following shows the patterns styles sorted by excelize index number:
  971. //
  972. // | Index | Style | Index | Style |
  973. // +-------+-----------------+-------+-----------------+
  974. // | 0 | None | 10 | darkTrellis |
  975. // | 1 | solid | 11 | lightHorizontal |
  976. // | 2 | mediumGray | 12 | lightVertical |
  977. // | 3 | darkGray | 13 | lightDown |
  978. // | 4 | lightGray | 14 | lightUp |
  979. // | 5 | darkHorizontal | 15 | lightGrid |
  980. // | 6 | darkVertical | 16 | lightTrellis |
  981. // | 7 | darkDown | 17 | gray125 |
  982. // | 8 | darkUp | 18 | gray0625 |
  983. // | 9 | darkGrid | | |
  984. //
  985. // The following the type of horizontal alignment in cells:
  986. //
  987. // | Style |
  988. // +------------------+
  989. // | left |
  990. // | center |
  991. // | right |
  992. // | fill |
  993. // | justify |
  994. // | centerContinuous |
  995. // | distributed |
  996. //
  997. // The following the type of vertical alignment in cells:
  998. //
  999. // | Style |
  1000. // +------------------+
  1001. // | top |
  1002. // | center |
  1003. // | justify |
  1004. // | distributed |
  1005. //
  1006. // The following the type of font underline style:
  1007. //
  1008. // | Style |
  1009. // +------------------+
  1010. // | single |
  1011. // | double |
  1012. //
  1013. // Excel's built-in all languages formats are shown in the following table:
  1014. //
  1015. // | Index | Format String |
  1016. // +-------+----------------------------------------------------+
  1017. // | 0 | General |
  1018. // | 1 | 0 |
  1019. // | 2 | 0.00 |
  1020. // | 3 | #,##0 |
  1021. // | 4 | #,##0.00 |
  1022. // | 5 | ($#,##0_);($#,##0) |
  1023. // | 6 | ($#,##0_);[Red]($#,##0) |
  1024. // | 7 | ($#,##0.00_);($#,##0.00) |
  1025. // | 8 | ($#,##0.00_);[Red]($#,##0.00) |
  1026. // | 9 | 0% |
  1027. // | 10 | 0.00% |
  1028. // | 11 | 0.00E+00 |
  1029. // | 12 | # ?/? |
  1030. // | 13 | # ??/?? |
  1031. // | 14 | m/d/yy |
  1032. // | 15 | d-mmm-yy |
  1033. // | 16 | d-mmm |
  1034. // | 17 | mmm-yy |
  1035. // | 18 | h:mm AM/PM |
  1036. // | 19 | h:mm:ss AM/PM |
  1037. // | 20 | h:mm |
  1038. // | 21 | h:mm:ss |
  1039. // | 22 | m/d/yy h:mm |
  1040. // | ... | ... |
  1041. // | 37 | (#,##0_);(#,##0) |
  1042. // | 38 | (#,##0_);[Red](#,##0) |
  1043. // | 39 | (#,##0.00_);(#,##0.00) |
  1044. // | 40 | (#,##0.00_);[Red](#,##0.00) |
  1045. // | 41 | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
  1046. // | 42 | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) |
  1047. // | 43 | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
  1048. // | 44 | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) |
  1049. // | 45 | mm:ss |
  1050. // | 46 | [h]:mm:ss |
  1051. // | 47 | mm:ss.0 |
  1052. // | 48 | ##0.0E+0 |
  1053. // | 49 | @ |
  1054. //
  1055. // Excelize built-in currency formats are shown in the following table, only
  1056. // support these types in the following table (Index number is used only for
  1057. // markup and is not used inside an Excel file and you can't get formatted value
  1058. // by the function GetCellValue) currently:
  1059. //
  1060. // | Index | Symbol |
  1061. // +-------+---------------------------------------------------------------+
  1062. // | 164 | CN¥ |
  1063. // | 165 | $ English (China) |
  1064. // | 166 | $ Cherokee (United States) |
  1065. // | 167 | $ Chinese (Singapore) |
  1066. // | 168 | $ Chinese (Taiwan) |
  1067. // | 169 | $ English (Australia) |
  1068. // | 170 | $ English (Belize) |
  1069. // | 171 | $ English (Canada) |
  1070. // | 172 | $ English (Jamaica) |
  1071. // | 173 | $ English (New Zealand) |
  1072. // | 174 | $ English (Singapore) |
  1073. // | 175 | $ English (Trinidad & Tobago) |
  1074. // | 176 | $ English (U.S. Vigin Islands) |
  1075. // | 177 | $ English (United States) |
  1076. // | 178 | $ French (Canada) |
  1077. // | 179 | $ Hawaiian (United States) |
  1078. // | 180 | $ Malay (Brunei) |
  1079. // | 181 | $ Quechua (Ecuador) |
  1080. // | 182 | $ Spanish (Chile) |
  1081. // | 183 | $ Spanish (Colombia) |
  1082. // | 184 | $ Spanish (Ecuador) |
  1083. // | 185 | $ Spanish (El Salvador) |
  1084. // | 186 | $ Spanish (Mexico) |
  1085. // | 187 | $ Spanish (Puerto Rico) |
  1086. // | 188 | $ Spanish (United States) |
  1087. // | 189 | $ Spanish (Uruguay) |
  1088. // | 190 | £ English (United Kingdom) |
  1089. // | 191 | £ Scottish Gaelic (United Kingdom) |
  1090. // | 192 | £ Welsh (United Kindom) |
  1091. // | 193 | ¥ Chinese (China) |
  1092. // | 194 | ¥ Japanese (Japan) |
  1093. // | 195 | ¥ Sichuan Yi (China) |
  1094. // | 196 | ¥ Tibetan (China) |
  1095. // | 197 | ¥ Uyghur (China) |
  1096. // | 198 | ֏ Armenian (Armenia) |
  1097. // | 199 | ؋ Pashto (Afghanistan) |
  1098. // | 200 | ؋ Persian (Afghanistan) |
  1099. // | 201 | ৳ Bengali (Bangladesh) |
  1100. // | 202 | ៛ Khmer (Cambodia) |
  1101. // | 203 | ₡ Spanish (Costa Rica) |
  1102. // | 204 | ₦ Hausa (Nigeria) |
  1103. // | 205 | ₦ Igbo (Nigeria) |
  1104. // | 206 | ₦ Yoruba (Nigeria) |
  1105. // | 207 | ₩ Korean (South Korea) |
  1106. // | 208 | ₪ Hebrew (Israel) |
  1107. // | 209 | ₫ Vietnamese (Vietnam) |
  1108. // | 210 | € Basque (Spain) |
  1109. // | 211 | € Breton (France) |
  1110. // | 212 | € Catalan (Spain) |
  1111. // | 213 | € Corsican (France) |
  1112. // | 214 | € Dutch (Belgium) |
  1113. // | 215 | € Dutch (Netherlands) |
  1114. // | 216 | € English (Ireland) |
  1115. // | 217 | € Estonian (Estonia) |
  1116. // | 218 | € Euro (€ 123) |
  1117. // | 219 | € Euro (123 €) |
  1118. // | 220 | € Finnish (Finland) |
  1119. // | 221 | € French (Belgium) |
  1120. // | 222 | € French (France) |
  1121. // | 223 | € French (Luxembourg) |
  1122. // | 224 | € French (Monaco) |
  1123. // | 225 | € French (Réunion) |
  1124. // | 226 | € Galician (Spain) |
  1125. // | 227 | € German (Austria) |
  1126. // | 228 | € German (Luxembourg) |
  1127. // | 229 | € Greek (Greece) |
  1128. // | 230 | € Inari Sami (Finland) |
  1129. // | 231 | € Irish (Ireland) |
  1130. // | 232 | € Italian (Italy) |
  1131. // | 233 | € Latin (Italy) |
  1132. // | 234 | € Latin, Serbian (Montenegro) |
  1133. // | 235 | € Larvian (Latvia) |
  1134. // | 236 | € Lithuanian (Lithuania) |
  1135. // | 237 | € Lower Sorbian (Germany) |
  1136. // | 238 | € Luxembourgish (Luxembourg) |
  1137. // | 239 | € Maltese (Malta) |
  1138. // | 240 | € Northern Sami (Finland) |
  1139. // | 241 | € Occitan (France) |
  1140. // | 242 | € Portuguese (Portugal) |
  1141. // | 243 | € Serbian (Montenegro) |
  1142. // | 244 | € Skolt Sami (Finland) |
  1143. // | 245 | € Slovak (Slovakia) |
  1144. // | 246 | € Slovenian (Slovenia) |
  1145. // | 247 | € Spanish (Spain) |
  1146. // | 248 | € Swedish (Finland) |
  1147. // | 249 | € Swiss German (France) |
  1148. // | 250 | € Upper Sorbian (Germany) |
  1149. // | 251 | € Western Frisian (Netherlands) |
  1150. // | 252 | ₭ Lao (Laos) |
  1151. // | 253 | ₮ Mongolian (Mongolia) |
  1152. // | 254 | ₮ Mongolian, Mongolian (Mongolia) |
  1153. // | 255 | ₱ English (Philippines) |
  1154. // | 256 | ₱ Filipino (Philippines) |
  1155. // | 257 | ₴ Ukrainian (Ukraine) |
  1156. // | 258 | ₸ Kazakh (Kazakhstan) |
  1157. // | 259 | ₹ Arabic, Kashmiri (India) |
  1158. // | 260 | ₹ English (India) |
  1159. // | 261 | ₹ Gujarati (India) |
  1160. // | 262 | ₹ Hindi (India) |
  1161. // | 263 | ₹ Kannada (India) |
  1162. // | 264 | ₹ Kashmiri (India) |
  1163. // | 265 | ₹ Konkani (India) |
  1164. // | 266 | ₹ Manipuri (India) |
  1165. // | 267 | ₹ Marathi (India) |
  1166. // | 268 | ₹ Nepali (India) |
  1167. // | 269 | ₹ Oriya (India) |
  1168. // | 270 | ₹ Punjabi (India) |
  1169. // | 271 | ₹ Sanskrit (India) |
  1170. // | 272 | ₹ Sindhi (India) |
  1171. // | 273 | ₹ Tamil (India) |
  1172. // | 274 | ₹ Urdu (India) |
  1173. // | 275 | ₺ Turkish (Turkey) |
  1174. // | 276 | ₼ Azerbaijani (Azerbaijan) |
  1175. // | 277 | ₼ Cyrillic, Azerbaijani (Azerbaijan) |
  1176. // | 278 | ₽ Russian (Russia) |
  1177. // | 279 | ₽ Sakha (Russia) |
  1178. // | 280 | ₾ Georgian (Georgia) |
  1179. // | 281 | B/. Spanish (Panama) |
  1180. // | 282 | Br Oromo (Ethiopia) |
  1181. // | 283 | Br Somali (Ethiopia) |
  1182. // | 284 | Br Tigrinya (Ethiopia) |
  1183. // | 285 | Bs Quechua (Bolivia) |
  1184. // | 286 | Bs Spanish (Bolivia) |
  1185. // | 287 | BS. Spanish (Venezuela) |
  1186. // | 288 | BWP Tswana (Botswana) |
  1187. // | 289 | C$ Spanish (Nicaragua) |
  1188. // | 290 | CA$ Latin, Inuktitut (Canada) |
  1189. // | 291 | CA$ Mohawk (Canada) |
  1190. // | 292 | CA$ Unified Canadian Aboriginal Syllabics, Inuktitut (Canada) |
  1191. // | 293 | CFA French (Mali) |
  1192. // | 294 | CFA French (Senegal) |
  1193. // | 295 | CFA Fulah (Senegal) |
  1194. // | 296 | CFA Wolof (Senegal) |
  1195. // | 297 | CHF French (Switzerland) |
  1196. // | 298 | CHF German (Liechtenstein) |
  1197. // | 299 | CHF German (Switzerland) |
  1198. // | 300 | CHF Italian (Switzerland) |
  1199. // | 301 | CHF Romansh (Switzerland) |
  1200. // | 302 | CLP Mapuche (Chile) |
  1201. // | 303 | CN¥ Mongolian, Mongolian (China) |
  1202. // | 304 | DZD Central Atlas Tamazight (Algeria) |
  1203. // | 305 | FCFA French (Cameroon) |
  1204. // | 306 | Ft Hungarian (Hungary) |
  1205. // | 307 | G French (Haiti) |
  1206. // | 308 | Gs. Spanish (Paraguay) |
  1207. // | 309 | GTQ K'iche' (Guatemala) |
  1208. // | 310 | HK$ Chinese (Hong Kong (China)) |
  1209. // | 311 | HK$ English (Hong Kong (China)) |
  1210. // | 312 | HRK Croatian (Croatia) |
  1211. // | 313 | IDR English (Indonesia) |
  1212. // | 314 | IQD Arbic, Central Kurdish (Iraq) |
  1213. // | 315 | ISK Icelandic (Iceland) |
  1214. // | 316 | K Burmese (Myanmar (Burma)) |
  1215. // | 317 | Kč Czech (Czech Republic) |
  1216. // | 318 | KM Bosnian (Bosnia & Herzegovina) |
  1217. // | 319 | KM Croatian (Bosnia & Herzegovina) |
  1218. // | 320 | KM Latin, Serbian (Bosnia & Herzegovina) |
  1219. // | 321 | kr Faroese (Faroe Islands) |
  1220. // | 322 | kr Northern Sami (Norway) |
  1221. // | 323 | kr Northern Sami (Sweden) |
  1222. // | 324 | kr Norwegian Bokmål (Norway) |
  1223. // | 325 | kr Norwegian Nynorsk (Norway) |
  1224. // | 326 | kr Swedish (Sweden) |
  1225. // | 327 | kr. Danish (Denmark) |
  1226. // | 328 | kr. Kalaallisut (Greenland) |
  1227. // | 329 | Ksh Swahili (kenya) |
  1228. // | 330 | L Romanian (Moldova) |
  1229. // | 331 | L Russian (Moldova) |
  1230. // | 332 | L Spanish (Honduras) |
  1231. // | 333 | Lekë Albanian (Albania) |
  1232. // | 334 | MAD Arabic, Central Atlas Tamazight (Morocco) |
  1233. // | 335 | MAD French (Morocco) |
  1234. // | 336 | MAD Tifinagh, Central Atlas Tamazight (Morocco) |
  1235. // | 337 | MOP$ Chinese (Macau (China)) |
  1236. // | 338 | MVR Divehi (Maldives) |
  1237. // | 339 | Nfk Tigrinya (Eritrea) |
  1238. // | 340 | NGN Bini (Nigeria) |
  1239. // | 341 | NGN Fulah (Nigeria) |
  1240. // | 342 | NGN Ibibio (Nigeria) |
  1241. // | 343 | NGN Kanuri (Nigeria) |
  1242. // | 344 | NOK Lule Sami (Norway) |
  1243. // | 345 | NOK Southern Sami (Norway) |
  1244. // | 346 | NZ$ Maori (New Zealand) |
  1245. // | 347 | PKR Sindhi (Pakistan) |
  1246. // | 348 | PYG Guarani (Paraguay) |
  1247. // | 349 | Q Spanish (Guatemala) |
  1248. // | 350 | R Afrikaans (South Africa) |
  1249. // | 351 | R English (South Africa) |
  1250. // | 352 | R Zulu (South Africa) |
  1251. // | 353 | R$ Portuguese (Brazil) |
  1252. // | 354 | RD$ Spanish (Dominican Republic) |
  1253. // | 355 | RF Kinyarwanda (Rwanda) |
  1254. // | 356 | RM English (Malaysia) |
  1255. // | 357 | RM Malay (Malaysia) |
  1256. // | 358 | RON Romanian (Romania) |
  1257. // | 359 | Rp Indonesoan (Indonesia) |
  1258. // | 360 | Rs Urdu (Pakistan) |
  1259. // | 361 | Rs. Tamil (Sri Lanka) |
  1260. // | 362 | RSD Latin, Serbian (Serbia) |
  1261. // | 363 | RSD Serbian (Serbia) |
  1262. // | 364 | RUB Bashkir (Russia) |
  1263. // | 365 | RUB Tatar (Russia) |
  1264. // | 366 | S/. Quechua (Peru) |
  1265. // | 367 | S/. Spanish (Peru) |
  1266. // | 368 | SEK Lule Sami (Sweden) |
  1267. // | 369 | SEK Southern Sami (Sweden) |
  1268. // | 370 | soʻm Latin, Uzbek (Uzbekistan) |
  1269. // | 371 | soʻm Uzbek (Uzbekistan) |
  1270. // | 372 | SYP Syriac (Syria) |
  1271. // | 373 | THB Thai (Thailand) |
  1272. // | 374 | TMT Turkmen (Turkmenistan) |
  1273. // | 375 | US$ English (Zimbabwe) |
  1274. // | 376 | ZAR Northern Sotho (South Africa) |
  1275. // | 377 | ZAR Southern Sotho (South Africa) |
  1276. // | 378 | ZAR Tsonga (South Africa) |
  1277. // | 379 | ZAR Tswana (south Africa) |
  1278. // | 380 | ZAR Venda (South Africa) |
  1279. // | 381 | ZAR Xhosa (South Africa) |
  1280. // | 382 | zł Polish (Poland) |
  1281. // | 383 | ден Macedonian (Macedonia) |
  1282. // | 384 | KM Cyrillic, Bosnian (Bosnia & Herzegovina) |
  1283. // | 385 | KM Serbian (Bosnia & Herzegovina) |
  1284. // | 386 | лв. Bulgarian (Bulgaria) |
  1285. // | 387 | p. Belarusian (Belarus) |
  1286. // | 388 | сом Kyrgyz (Kyrgyzstan) |
  1287. // | 389 | сом Tajik (Tajikistan) |
  1288. // | 390 | ج.م. Arabic (Egypt) |
  1289. // | 391 | د.أ. Arabic (Jordan) |
  1290. // | 392 | د.أ. Arabic (United Arab Emirates) |
  1291. // | 393 | د.ب. Arabic (Bahrain) |
  1292. // | 394 | د.ت. Arabic (Tunisia) |
  1293. // | 395 | د.ج. Arabic (Algeria) |
  1294. // | 396 | د.ع. Arabic (Iraq) |
  1295. // | 397 | د.ك. Arabic (Kuwait) |
  1296. // | 398 | د.ل. Arabic (Libya) |
  1297. // | 399 | د.م. Arabic (Morocco) |
  1298. // | 400 | ر Punjabi (Pakistan) |
  1299. // | 401 | ر.س. Arabic (Saudi Arabia) |
  1300. // | 402 | ر.ع. Arabic (Oman) |
  1301. // | 403 | ر.ق. Arabic (Qatar) |
  1302. // | 404 | ر.ي. Arabic (Yemen) |
  1303. // | 405 | ریال Persian (Iran) |
  1304. // | 406 | ل.س. Arabic (Syria) |
  1305. // | 407 | ل.ل. Arabic (Lebanon) |
  1306. // | 408 | ብር Amharic (Ethiopia) |
  1307. // | 409 | रू Nepaol (Nepal) |
  1308. // | 410 | රු. Sinhala (Sri Lanka) |
  1309. // | 411 | ADP |
  1310. // | 412 | AED |
  1311. // | 413 | AFA |
  1312. // | 414 | AFN |
  1313. // | 415 | ALL |
  1314. // | 416 | AMD |
  1315. // | 417 | ANG |
  1316. // | 418 | AOA |
  1317. // | 419 | ARS |
  1318. // | 420 | ATS |
  1319. // | 421 | AUD |
  1320. // | 422 | AWG |
  1321. // | 423 | AZM |
  1322. // | 424 | AZN |
  1323. // | 425 | BAM |
  1324. // | 426 | BBD |
  1325. // | 427 | BDT |
  1326. // | 428 | BEF |
  1327. // | 429 | BGL |
  1328. // | 430 | BGN |
  1329. // | 431 | BHD |
  1330. // | 432 | BIF |
  1331. // | 433 | BMD |
  1332. // | 434 | BND |
  1333. // | 435 | BOB |
  1334. // | 436 | BOV |
  1335. // | 437 | BRL |
  1336. // | 438 | BSD |
  1337. // | 439 | BTN |
  1338. // | 440 | BWP |
  1339. // | 441 | BYR |
  1340. // | 442 | BZD |
  1341. // | 443 | CAD |
  1342. // | 444 | CDF |
  1343. // | 445 | CHE |
  1344. // | 446 | CHF |
  1345. // | 447 | CHW |
  1346. // | 448 | CLF |
  1347. // | 449 | CLP |
  1348. // | 450 | CNY |
  1349. // | 451 | COP |
  1350. // | 452 | COU |
  1351. // | 453 | CRC |
  1352. // | 454 | CSD |
  1353. // | 455 | CUC |
  1354. // | 456 | CVE |
  1355. // | 457 | CYP |
  1356. // | 458 | CZK |
  1357. // | 459 | DEM |
  1358. // | 460 | DJF |
  1359. // | 461 | DKK |
  1360. // | 462 | DOP |
  1361. // | 463 | DZD |
  1362. // | 464 | ECS |
  1363. // | 465 | ECV |
  1364. // | 466 | EEK |
  1365. // | 467 | EGP |
  1366. // | 468 | ERN |
  1367. // | 469 | ESP |
  1368. // | 470 | ETB |
  1369. // | 471 | EUR |
  1370. // | 472 | FIM |
  1371. // | 473 | FJD |
  1372. // | 474 | FKP |
  1373. // | 475 | FRF |
  1374. // | 476 | GBP |
  1375. // | 477 | GEL |
  1376. // | 478 | GHC |
  1377. // | 479 | GHS |
  1378. // | 480 | GIP |
  1379. // | 481 | GMD |
  1380. // | 482 | GNF |
  1381. // | 483 | GRD |
  1382. // | 484 | GTQ |
  1383. // | 485 | GYD |
  1384. // | 486 | HKD |
  1385. // | 487 | HNL |
  1386. // | 488 | HRK |
  1387. // | 489 | HTG |
  1388. // | 490 | HUF |
  1389. // | 491 | IDR |
  1390. // | 492 | IEP |
  1391. // | 493 | ILS |
  1392. // | 494 | INR |
  1393. // | 495 | IQD |
  1394. // | 496 | IRR |
  1395. // | 497 | ISK |
  1396. // | 498 | ITL |
  1397. // | 499 | JMD |
  1398. // | 500 | JOD |
  1399. // | 501 | JPY |
  1400. // | 502 | KAF |
  1401. // | 503 | KES |
  1402. // | 504 | KGS |
  1403. // | 505 | KHR |
  1404. // | 506 | KMF |
  1405. // | 507 | KPW |
  1406. // | 508 | KRW |
  1407. // | 509 | KWD |
  1408. // | 510 | KYD |
  1409. // | 511 | KZT |
  1410. // | 512 | LAK |
  1411. // | 513 | LBP |
  1412. // | 514 | LKR |
  1413. // | 515 | LRD |
  1414. // | 516 | LSL |
  1415. // | 517 | LTL |
  1416. // | 518 | LUF |
  1417. // | 519 | LVL |
  1418. // | 520 | LYD |
  1419. // | 521 | MAD |
  1420. // | 522 | MDL |
  1421. // | 523 | MGA |
  1422. // | 524 | MGF |
  1423. // | 525 | MKD |
  1424. // | 526 | MMK |
  1425. // | 527 | MNT |
  1426. // | 528 | MOP |
  1427. // | 529 | MRO |
  1428. // | 530 | MTL |
  1429. // | 531 | MUR |
  1430. // | 532 | MVR |
  1431. // | 533 | MWK |
  1432. // | 534 | MXN |
  1433. // | 535 | MXV |
  1434. // | 536 | MYR |
  1435. // | 537 | MZM |
  1436. // | 538 | MZN |
  1437. // | 539 | NAD |
  1438. // | 540 | NGN |
  1439. // | 541 | NIO |
  1440. // | 542 | NLG |
  1441. // | 543 | NOK |
  1442. // | 544 | NPR |
  1443. // | 545 | NTD |
  1444. // | 546 | NZD |
  1445. // | 547 | OMR |
  1446. // | 548 | PAB |
  1447. // | 549 | PEN |
  1448. // | 550 | PGK |
  1449. // | 551 | PHP |
  1450. // | 552 | PKR |
  1451. // | 553 | PLN |
  1452. // | 554 | PTE |
  1453. // | 555 | PYG |
  1454. // | 556 | QAR |
  1455. // | 557 | ROL |
  1456. // | 558 | RON |
  1457. // | 559 | RSD |
  1458. // | 560 | RUB |
  1459. // | 561 | RUR |
  1460. // | 562 | RWF |
  1461. // | 563 | SAR |
  1462. // | 564 | SBD |
  1463. // | 565 | SCR |
  1464. // | 566 | SDD |
  1465. // | 567 | SDG |
  1466. // | 568 | SDP |
  1467. // | 569 | SEK |
  1468. // | 570 | SGD |
  1469. // | 571 | SHP |
  1470. // | 572 | SIT |
  1471. // | 573 | SKK |
  1472. // | 574 | SLL |
  1473. // | 575 | SOS |
  1474. // | 576 | SPL |
  1475. // | 577 | SRD |
  1476. // | 578 | SRG |
  1477. // | 579 | STD |
  1478. // | 580 | SVC |
  1479. // | 581 | SYP |
  1480. // | 582 | SZL |
  1481. // | 583 | THB |
  1482. // | 584 | TJR |
  1483. // | 585 | TJS |
  1484. // | 586 | TMM |
  1485. // | 587 | TMT |
  1486. // | 588 | TND |
  1487. // | 589 | TOP |
  1488. // | 590 | TRL |
  1489. // | 591 | TRY |
  1490. // | 592 | TTD |
  1491. // | 593 | TWD |
  1492. // | 594 | TZS |
  1493. // | 595 | UAH |
  1494. // | 596 | UGX |
  1495. // | 597 | USD |
  1496. // | 598 | USN |
  1497. // | 599 | USS |
  1498. // | 600 | UYI |
  1499. // | 601 | UYU |
  1500. // | 602 | UZS |
  1501. // | 603 | VEB |
  1502. // | 604 | VEF |
  1503. // | 605 | VND |
  1504. // | 606 | VUV |
  1505. // | 607 | WST |
  1506. // | 608 | XAF |
  1507. // | 609 | XAG |
  1508. // | 610 | XAU |
  1509. // | 611 | XB5 |
  1510. // | 612 | XBA |
  1511. // | 613 | XBB |
  1512. // | 614 | XBC |
  1513. // | 615 | XBD |
  1514. // | 616 | XCD |
  1515. // | 617 | XDR |
  1516. // | 618 | XFO |
  1517. // | 619 | XFU |
  1518. // | 620 | XOF |
  1519. // | 621 | XPD |
  1520. // | 622 | XPF |
  1521. // | 623 | XPT |
  1522. // | 624 | XTS |
  1523. // | 625 | XXX |
  1524. // | 626 | YER |
  1525. // | 627 | YUM |
  1526. // | 628 | ZAR |
  1527. // | 629 | ZMK |
  1528. // | 630 | ZMW |
  1529. // | 631 | ZWD |
  1530. // | 632 | ZWL |
  1531. // | 633 | ZWN |
  1532. // | 634 | ZWR |
  1533. //
  1534. func (f *File) NewStyle(style string) (int, error) {
  1535. var cellXfsID int
  1536. styleSheet := f.stylesReader()
  1537. formatCellStyle, err := parseFormatStyleSet(style)
  1538. if err != nil {
  1539. return cellXfsID, err
  1540. }
  1541. numFmtID := setNumFmt(styleSheet, formatCellStyle)
  1542. fontID := setFont(styleSheet, formatCellStyle)
  1543. borderID := setBorders(styleSheet, formatCellStyle)
  1544. fillID := setFills(styleSheet, formatCellStyle)
  1545. applyAlignment, alignment := setAlignment(styleSheet, formatCellStyle)
  1546. cellXfsID = setCellXfs(styleSheet, fontID, numFmtID, fillID, borderID, applyAlignment, alignment)
  1547. return cellXfsID, nil
  1548. }
  1549. // setFont provides function to add font style by given cell format settings.
  1550. func setFont(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1551. if formatCellStyle.Font == nil {
  1552. return 0
  1553. }
  1554. fontUnderlineType := map[string]string{"single": "single", "double": "double"}
  1555. if formatCellStyle.Font.Family == "" {
  1556. formatCellStyle.Font.Family = "Calibri"
  1557. }
  1558. if formatCellStyle.Font.Size < 1 {
  1559. formatCellStyle.Font.Size = 11
  1560. }
  1561. if formatCellStyle.Font.Color == "" {
  1562. formatCellStyle.Font.Color = "#000000"
  1563. }
  1564. f := font{
  1565. B: formatCellStyle.Font.Bold,
  1566. I: formatCellStyle.Font.Italic,
  1567. Sz: &attrValInt{Val: formatCellStyle.Font.Size},
  1568. Color: &xlsxColor{RGB: getPaletteColor(formatCellStyle.Font.Color)},
  1569. Name: &attrValString{Val: formatCellStyle.Font.Family},
  1570. Family: &attrValInt{Val: 2},
  1571. Scheme: &attrValString{Val: "minor"},
  1572. }
  1573. val, ok := fontUnderlineType[formatCellStyle.Font.Underline]
  1574. if ok {
  1575. f.U = &attrValString{Val: val}
  1576. }
  1577. font, _ := xml.Marshal(f)
  1578. style.Fonts.Count++
  1579. style.Fonts.Font = append(style.Fonts.Font, &xlsxFont{
  1580. Font: string(font[6 : len(font)-7]),
  1581. })
  1582. return style.Fonts.Count - 1
  1583. }
  1584. // setNumFmt provides function to check if number format code in the range of
  1585. // built-in values.
  1586. func setNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1587. dp := "0."
  1588. numFmtID := 164 // Default custom number format code from 164.
  1589. if formatCellStyle.DecimalPlaces < 0 || formatCellStyle.DecimalPlaces > 30 {
  1590. formatCellStyle.DecimalPlaces = 2
  1591. }
  1592. for i := 0; i < formatCellStyle.DecimalPlaces; i++ {
  1593. dp += "0"
  1594. }
  1595. _, ok := builtInNumFmt[formatCellStyle.NumFmt]
  1596. if !ok {
  1597. fc, currency := currencyNumFmt[formatCellStyle.NumFmt]
  1598. if !currency {
  1599. return setLangNumFmt(style, formatCellStyle)
  1600. }
  1601. fc = strings.Replace(fc, "0.00", dp, -1)
  1602. if formatCellStyle.NegRed {
  1603. fc = fc + ";[Red]" + fc
  1604. }
  1605. if style.NumFmts != nil {
  1606. numFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1
  1607. nf := xlsxNumFmt{
  1608. FormatCode: fc,
  1609. NumFmtID: numFmtID,
  1610. }
  1611. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1612. style.NumFmts.Count++
  1613. } else {
  1614. nf := xlsxNumFmt{
  1615. FormatCode: fc,
  1616. NumFmtID: numFmtID,
  1617. }
  1618. numFmts := xlsxNumFmts{
  1619. NumFmt: []*xlsxNumFmt{&nf},
  1620. Count: 1,
  1621. }
  1622. style.NumFmts = &numFmts
  1623. }
  1624. return numFmtID
  1625. }
  1626. return formatCellStyle.NumFmt
  1627. }
  1628. // setLangNumFmt provides function to set number format code with language.
  1629. func setLangNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1630. numFmts, ok := langNumFmt[formatCellStyle.Lang]
  1631. if !ok {
  1632. return 0
  1633. }
  1634. var fc string
  1635. fc, ok = numFmts[formatCellStyle.NumFmt]
  1636. if !ok {
  1637. return 0
  1638. }
  1639. nf := xlsxNumFmt{
  1640. FormatCode: fc,
  1641. NumFmtID: formatCellStyle.NumFmt,
  1642. }
  1643. if style.NumFmts != nil {
  1644. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1645. style.NumFmts.Count++
  1646. } else {
  1647. numFmts := xlsxNumFmts{
  1648. NumFmt: []*xlsxNumFmt{&nf},
  1649. Count: 1,
  1650. }
  1651. style.NumFmts = &numFmts
  1652. }
  1653. return formatCellStyle.NumFmt
  1654. }
  1655. // setFills provides function to add fill elements in the styles.xml by given
  1656. // cell format settings.
  1657. func setFills(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1658. var patterns = []string{
  1659. "none",
  1660. "solid",
  1661. "mediumGray",
  1662. "darkGray",
  1663. "lightGray",
  1664. "darkHorizontal",
  1665. "darkVertical",
  1666. "darkDown",
  1667. "darkUp",
  1668. "darkGrid",
  1669. "darkTrellis",
  1670. "lightHorizontal",
  1671. "lightVertical",
  1672. "lightDown",
  1673. "lightUp",
  1674. "lightGrid",
  1675. "lightTrellis",
  1676. "gray125",
  1677. "gray0625",
  1678. }
  1679. var variants = []float64{
  1680. 90,
  1681. 0,
  1682. 45,
  1683. 135,
  1684. }
  1685. var fill xlsxFill
  1686. switch formatCellStyle.Fill.Type {
  1687. case "gradient":
  1688. if len(formatCellStyle.Fill.Color) != 2 {
  1689. break
  1690. }
  1691. var gradient xlsxGradientFill
  1692. switch formatCellStyle.Fill.Shading {
  1693. case 0, 1, 2, 3:
  1694. gradient.Degree = variants[formatCellStyle.Fill.Shading]
  1695. case 4:
  1696. gradient.Type = "path"
  1697. case 5:
  1698. gradient.Type = "path"
  1699. gradient.Bottom = 0.5
  1700. gradient.Left = 0.5
  1701. gradient.Right = 0.5
  1702. gradient.Top = 0.5
  1703. default:
  1704. break
  1705. }
  1706. var stops []*xlsxGradientFillStop
  1707. for index, color := range formatCellStyle.Fill.Color {
  1708. var stop xlsxGradientFillStop
  1709. stop.Position = float64(index)
  1710. stop.Color.RGB = getPaletteColor(color)
  1711. stops = append(stops, &stop)
  1712. }
  1713. gradient.Stop = stops
  1714. fill.GradientFill = &gradient
  1715. case "pattern":
  1716. if formatCellStyle.Fill.Pattern > 18 || formatCellStyle.Fill.Pattern < 0 {
  1717. break
  1718. }
  1719. if len(formatCellStyle.Fill.Color) < 1 {
  1720. break
  1721. }
  1722. var pattern xlsxPatternFill
  1723. pattern.PatternType = patterns[formatCellStyle.Fill.Pattern]
  1724. pattern.FgColor.RGB = getPaletteColor(formatCellStyle.Fill.Color[0])
  1725. fill.PatternFill = &pattern
  1726. }
  1727. style.Fills.Count++
  1728. style.Fills.Fill = append(style.Fills.Fill, &fill)
  1729. return style.Fills.Count - 1
  1730. }
  1731. // setAlignment provides function to formatting information pertaining to text
  1732. // alignment in cells. There are a variety of choices for how text is aligned
  1733. // both horizontally and vertically, as well as indentation settings, and so on.
  1734. func setAlignment(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) (bool, *xlsxAlignment) {
  1735. if formatCellStyle.Alignment == nil {
  1736. return false, &xlsxAlignment{}
  1737. }
  1738. var alignment = xlsxAlignment{
  1739. Horizontal: formatCellStyle.Alignment.Horizontal,
  1740. Indent: formatCellStyle.Alignment.Indent,
  1741. JustifyLastLine: formatCellStyle.Alignment.JustifyLastLine,
  1742. ReadingOrder: formatCellStyle.Alignment.ReadingOrder,
  1743. RelativeIndent: formatCellStyle.Alignment.RelativeIndent,
  1744. ShrinkToFit: formatCellStyle.Alignment.ShrinkToFit,
  1745. TextRotation: formatCellStyle.Alignment.TextRotation,
  1746. Vertical: formatCellStyle.Alignment.Vertical,
  1747. WrapText: formatCellStyle.Alignment.WrapText,
  1748. }
  1749. return true, &alignment
  1750. }
  1751. // setBorders provides function to add border elements in the styles.xml by
  1752. // given borders format settings.
  1753. func setBorders(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1754. var styles = []string{
  1755. "none",
  1756. "thin",
  1757. "medium",
  1758. "dashed",
  1759. "dotted",
  1760. "thick",
  1761. "double",
  1762. "hair",
  1763. "mediumDashed",
  1764. "dashDot",
  1765. "mediumDashDot",
  1766. "dashDotDot",
  1767. "mediumDashDotDot",
  1768. "slantDashDot",
  1769. }
  1770. var border xlsxBorder
  1771. for _, v := range formatCellStyle.Border {
  1772. if v.Style > 13 || v.Style < 0 {
  1773. continue
  1774. }
  1775. var color xlsxColor
  1776. color.RGB = getPaletteColor(v.Color)
  1777. switch v.Type {
  1778. case "left":
  1779. border.Left.Style = styles[v.Style]
  1780. border.Left.Color = &color
  1781. case "right":
  1782. border.Right.Style = styles[v.Style]
  1783. border.Right.Color = &color
  1784. case "top":
  1785. border.Top.Style = styles[v.Style]
  1786. border.Top.Color = &color
  1787. case "bottom":
  1788. border.Bottom.Style = styles[v.Style]
  1789. border.Bottom.Color = &color
  1790. case "diagonalUp":
  1791. border.Diagonal.Style = styles[v.Style]
  1792. border.Diagonal.Color = &color
  1793. border.DiagonalUp = true
  1794. case "diagonalDown":
  1795. border.Diagonal.Style = styles[v.Style]
  1796. border.Diagonal.Color = &color
  1797. border.DiagonalDown = true
  1798. }
  1799. }
  1800. style.Borders.Count++
  1801. style.Borders.Border = append(style.Borders.Border, &border)
  1802. return style.Borders.Count - 1
  1803. }
  1804. // setCellXfs provides function to set describes all of the formatting for a
  1805. // cell.
  1806. func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment bool, alignment *xlsxAlignment) int {
  1807. var xf xlsxXf
  1808. xf.FontID = fontID
  1809. if fontID != 0 {
  1810. xf.ApplyFont = true
  1811. }
  1812. xf.NumFmtID = numFmtID
  1813. if numFmtID != 0 {
  1814. xf.ApplyNumberFormat = true
  1815. }
  1816. xf.FillID = fillID
  1817. xf.BorderID = borderID
  1818. style.CellXfs.Count++
  1819. xf.Alignment = alignment
  1820. xf.ApplyAlignment = applyAlignment
  1821. style.CellXfs.Xf = append(style.CellXfs.Xf, xf)
  1822. return style.CellXfs.Count - 1
  1823. }
  1824. // SetCellStyle provides function to add style attribute for cells by given
  1825. // worksheet sheet index, coordinate area and style ID. Note that diagonalDown
  1826. // and diagonalUp type border should be use same color in the same coordinate
  1827. // area.
  1828. //
  1829. // For example create a borders of cell H9 on Sheet1:
  1830. //
  1831. // 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}]}`)
  1832. // if err != nil {
  1833. // fmt.Println(err)
  1834. // }
  1835. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1836. //
  1837. // Set gradient fill with vertical variants shading styles for cell H9 on
  1838. // Sheet1:
  1839. //
  1840. // style, err := xlsx.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
  1841. // if err != nil {
  1842. // fmt.Println(err)
  1843. // }
  1844. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1845. //
  1846. // Set solid style pattern fill for cell H9 on Sheet1:
  1847. //
  1848. // style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
  1849. // if err != nil {
  1850. // fmt.Println(err)
  1851. // }
  1852. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1853. //
  1854. // Set alignment style for cell H9 on Sheet1:
  1855. //
  1856. // 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}}`)
  1857. // if err != nil {
  1858. // fmt.Println(err)
  1859. // }
  1860. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1861. //
  1862. // Dates and times in Excel are represented by real numbers, for example "Apr 7
  1863. // 2017 12:00 PM" is represented by the number 42920.5. Set date and time format
  1864. // for cell H9 on Sheet1:
  1865. //
  1866. // xlsx.SetCellValue("Sheet1", "H9", 42920.5)
  1867. // style, err := xlsx.NewStyle(`{"number_format": 22}`)
  1868. // if err != nil {
  1869. // fmt.Println(err)
  1870. // }
  1871. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1872. //
  1873. // Set font style for cell H9 on Sheet1:
  1874. //
  1875. // style, err := xlsx.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`)
  1876. // if err != nil {
  1877. // fmt.Println(err)
  1878. // }
  1879. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1880. //
  1881. func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
  1882. hcell = strings.ToUpper(hcell)
  1883. vcell = strings.ToUpper(vcell)
  1884. // Coordinate conversion, convert C1:B3 to 2,0,1,2.
  1885. hcol := string(strings.Map(letterOnlyMapF, hcell))
  1886. hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell))
  1887. hyAxis := hrow - 1
  1888. hxAxis := TitleToNumber(hcol)
  1889. vcol := string(strings.Map(letterOnlyMapF, vcell))
  1890. vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell))
  1891. vyAxis := vrow - 1
  1892. vxAxis := TitleToNumber(vcol)
  1893. if vxAxis < hxAxis {
  1894. hcell, vcell = vcell, hcell
  1895. vxAxis, hxAxis = hxAxis, vxAxis
  1896. }
  1897. if vyAxis < hyAxis {
  1898. hcell, vcell = vcell, hcell
  1899. vyAxis, hyAxis = hyAxis, vyAxis
  1900. }
  1901. // Correct the coordinate area, such correct C1:B3 to B1:C3.
  1902. hcell = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1)
  1903. vcell = ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
  1904. xlsx := f.workSheetReader(sheet)
  1905. completeRow(xlsx, vyAxis+1, vxAxis+1)
  1906. completeCol(xlsx, vyAxis+1, vxAxis+1)
  1907. for r, row := range xlsx.SheetData.Row {
  1908. for k, c := range row.C {
  1909. if checkCellInArea(c.R, hcell+":"+vcell) {
  1910. xlsx.SheetData.Row[r].C[k].S = styleID
  1911. }
  1912. }
  1913. }
  1914. }
  1915. // getPaletteColor provides function to convert the RBG color by given string.
  1916. func getPaletteColor(color string) string {
  1917. return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
  1918. }