styles.go 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  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. // Number format code in zh-tw language:
  1056. //
  1057. // Index | Symbol
  1058. // -------+-------------------------------------------
  1059. // 27 | [$-404]e/m/d
  1060. // 28 | [$-404]e"年"m"月"d"日"
  1061. // 29 | [$-404]e"年"m"月"d"日"
  1062. // 30 | m/d/yy
  1063. // 31 | yyyy"年"m"月"d"日"
  1064. // 32 | hh"時"mm"分"
  1065. // 33 | hh"時"mm"分"ss"秒"
  1066. // 34 | 上午/下午 hh"時"mm"分"
  1067. // 35 | 上午/下午 hh"時"mm"分"ss"秒"
  1068. // 36 | [$-404]e/m/d
  1069. // 50 | [$-404]e/m/d
  1070. // 51 | [$-404]e"年"m"月"d"日"
  1071. // 52 | 上午/下午 hh"時"mm"分"
  1072. // 53 | 上午/下午 hh"時"mm"分"ss"秒"
  1073. // 54 | [$-404]e"年"m"月"d"日"
  1074. // 55 | 上午/下午 hh"時"mm"分"
  1075. // 56 | 上午/下午 hh"時"mm"分"ss"秒"
  1076. // 57 | [$-404]e/m/d
  1077. // 58 | [$-404]e"年"m"月"d"日"
  1078. //
  1079. // Number format code in zh-cn language:
  1080. //
  1081. // Index | Symbol
  1082. // -------+-------------------------------------------
  1083. // 27 | yyyy"年"m"月"
  1084. // 28 | m"月"d"日"
  1085. // 29 | m"月"d"日"
  1086. // 30 | m-d-yy
  1087. // 31 | yyyy"年"m"月"d"日"
  1088. // 32 | h"时"mm"分"
  1089. // 33 | h"时"mm"分"ss"秒"
  1090. // 34 | 上午/下午 h"时"mm"分"
  1091. // 35 | 上午/下午 h"时"mm"分"ss"秒
  1092. // 36 | yyyy"年"m"月
  1093. // 50 | yyyy"年"m"月
  1094. // 51 | m"月"d"日
  1095. // 52 | yyyy"年"m"月
  1096. // 53 | m"月"d"日
  1097. // 54 | m"月"d"日
  1098. // 55 | 上午/下午 h"时"mm"分
  1099. // 56 | 上午/下午 h"时"mm"分"ss"秒
  1100. // 57 | yyyy"年"m"月
  1101. // 58 | m"月"d"日"
  1102. //
  1103. // Number format code with unicode values provided for language glyphs where
  1104. // they occur in zh-tw language:
  1105. //
  1106. // Index | Symbol
  1107. // -------+-------------------------------------------
  1108. // 27 | [$-404]e/m/
  1109. // 28 | [$-404]e"5E74"m"6708"d"65E5
  1110. // 29 | [$-404]e"5E74"m"6708"d"65E5
  1111. // 30 | m/d/y
  1112. // 31 | yyyy"5E74"m"6708"d"65E5
  1113. // 32 | hh"6642"mm"5206
  1114. // 33 | hh"6642"mm"5206"ss"79D2
  1115. // 34 | 4E0A5348/4E0B5348hh"6642"mm"5206
  1116. // 35 | 4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2
  1117. // 36 | [$-404]e/m/
  1118. // 50 | [$-404]e/m/
  1119. // 51 | [$-404]e"5E74"m"6708"d"65E5
  1120. // 52 | 4E0A5348/4E0B5348hh"6642"mm"5206
  1121. // 53 | 4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2
  1122. // 54 | [$-404]e"5E74"m"6708"d"65E5
  1123. // 55 | 4E0A5348/4E0B5348hh"6642"mm"5206
  1124. // 56 | 4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2
  1125. // 57 | [$-404]e/m/
  1126. // 58 | [$-404]e"5E74"m"6708"d"65E5"
  1127. //
  1128. // Number format code with unicode values provided for language glyphs where
  1129. // they occur in zh-cn language:
  1130. //
  1131. // Index | Symbol
  1132. // -------+-------------------------------------------
  1133. // 27 | yyyy"5E74"m"6708
  1134. // 28 | m"6708"d"65E5
  1135. // 29 | m"6708"d"65E5
  1136. // 30 | m-d-y
  1137. // 31 | yyyy"5E74"m"6708"d"65E5
  1138. // 32 | h"65F6"mm"5206
  1139. // 33 | h"65F6"mm"5206"ss"79D2
  1140. // 34 | 4E0A5348/4E0B5348h"65F6"mm"5206
  1141. // 35 | 4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2
  1142. // 36 | yyyy"5E74"m"6708
  1143. // 50 | yyyy"5E74"m"6708
  1144. // 51 | m"6708"d"65E5
  1145. // 52 | yyyy"5E74"m"6708
  1146. // 53 | m"6708"d"65E5
  1147. // 54 | m"6708"d"65E5
  1148. // 55 | 4E0A5348/4E0B5348h"65F6"mm"5206
  1149. // 56 | 4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2
  1150. // 57 | yyyy"5E74"m"6708
  1151. // 58 | m"6708"d"65E5"`,
  1152. //
  1153. // Number format code in ja-jp language:
  1154. //
  1155. // Index | Symbol
  1156. // -------+-------------------------------------------
  1157. // 27 | [$-411]ge.m.
  1158. // 28 | [$-411]ggge"年"m"月"d"日
  1159. // 29 | [$-411]ggge"年"m"月"d"日
  1160. // 30 | m/d/y
  1161. // 31 | yyyy"年"m"月"d"日
  1162. // 32 | h"時"mm"分
  1163. // 33 | h"時"mm"分"ss"秒
  1164. // 34 | yyyy"年"m"月
  1165. // 35 | m"月"d"日
  1166. // 36 | [$-411]ge.m.
  1167. // 50 | [$-411]ge.m.
  1168. // 51 | [$-411]ggge"年"m"月"d"日
  1169. // 52 | yyyy"年"m"月
  1170. // 53 | m"月"d"日
  1171. // 54 | [$-411]ggge"年"m"月"d"日
  1172. // 55 | yyyy"年"m"月
  1173. // 56 | m"月"d"日
  1174. // 57 | [$-411]ge.m.
  1175. // 58 | [$-411]ggge"年"m"月"d"日"
  1176. //
  1177. // Number format code in th-th language:
  1178. //
  1179. // Index | Symbol
  1180. // -------+-------------------------------------------
  1181. // 27 | yyyy"年" mm"月" dd"日
  1182. // 28 | mm-d
  1183. // 29 | mm-d
  1184. // 30 | mm-dd-y
  1185. // 31 | yyyy"년" mm"월" dd"일
  1186. // 32 | h"시" mm"분
  1187. // 33 | h"시" mm"분" ss"초
  1188. // 34 | yyyy-mm-d
  1189. // 35 | yyyy-mm-d
  1190. // 36 | yyyy"年" mm"月" dd"日
  1191. // 50 | yyyy"年" mm"月" dd"日
  1192. // 51 | mm-d
  1193. // 52 | yyyy-mm-d
  1194. // 53 | yyyy-mm-d
  1195. // 54 | mm-d
  1196. // 55 | yyyy-mm-d
  1197. // 56 | yyyy-mm-d
  1198. // 57 | yyyy"年" mm"月" dd"日
  1199. // 58 | mm-dd
  1200. //
  1201. // Number format code with unicode values provided for language glyphs where
  1202. // they occur in ja-jp language:
  1203. //
  1204. // Index | Symbol
  1205. // -------+-------------------------------------------
  1206. // 27 | [$-411]ge.m.
  1207. // 28 | [$-411]ggge"5E74"m"6708"d"65E5
  1208. // 29 | [$-411]ggge"5E74"m"6708"d"65E5
  1209. // 30 | m/d/y
  1210. // 31 | yyyy"5E74"m"6708"d"65E5
  1211. // 32 | h"6642"mm"5206
  1212. // 33 | h"6642"mm"5206"ss"79D2
  1213. // 34 | yyyy"5E74"m"6708
  1214. // 35 | m"6708"d"65E5
  1215. // 36 | [$-411]ge.m.
  1216. // 50 | [$-411]ge.m.
  1217. // 51 | [$-411]ggge"5E74"m"6708"d"65E5
  1218. // 52 | yyyy"5E74"m"6708
  1219. // 53 | m"6708"d"65E5
  1220. // 54 | [$-411]ggge"5E74"m"6708"d"65E5
  1221. // 55 | yyyy"5E74"m"6708
  1222. // 56 | m"6708"d"65E5
  1223. // 57 | [$-411]ge.m.
  1224. // 58 | [$-411]ggge"5E74"m"6708"d"65E5"
  1225. //
  1226. // Number format code with unicode values provided for language glyphs where
  1227. // they occur in ko-kr language:
  1228. //
  1229. // Index | Symbol
  1230. // -------+-------------------------------------------
  1231. // 27 | yyyy"5E74" mm"6708" dd"65E5
  1232. // 28 | mm-d
  1233. // 29 | mm-d
  1234. // 30 | mm-dd-y
  1235. // 31 | yyyy"B144" mm"C6D4" dd"C77C
  1236. // 32 | h"C2DC" mm"BD84
  1237. // 33 | h"C2DC" mm"BD84" ss"CD08
  1238. // 34 | yyyy-mm-d
  1239. // 35 | yyyy-mm-d
  1240. // 36 | yyyy"5E74" mm"6708" dd"65E5
  1241. // 50 | yyyy"5E74" mm"6708" dd"65E5
  1242. // 51 | mm-d
  1243. // 52 | yyyy-mm-d
  1244. // 53 | yyyy-mm-d
  1245. // 54 | mm-d
  1246. // 55 | yyyy-mm-d
  1247. // 56 | yyyy-mm-d
  1248. // 57 | yyyy"5E74" mm"6708" dd"65E5
  1249. // 58 | mm-dd
  1250. //
  1251. // Number format code in ko-kr language:
  1252. //
  1253. // Index | Symbol
  1254. // -------+-------------------------------------------
  1255. // 59 | t
  1256. // 60 | t0.0
  1257. // 61 | t#,##
  1258. // 62 | t#,##0.0
  1259. // 67 | t0
  1260. // 68 | t0.00
  1261. // 69 | t# ?/
  1262. // 70 | t# ??/?
  1263. // 71 | ว/ด/ปปป
  1264. // 72 | ว-ดดด-ป
  1265. // 73 | ว-ดด
  1266. // 74 | ดดด-ป
  1267. // 75 | ช:น
  1268. // 76 | ช:นน:ท
  1269. // 77 | ว/ด/ปปปป ช:น
  1270. // 78 | นน:ท
  1271. // 79 | [ช]:นน:ท
  1272. // 80 | นน:ทท.
  1273. // 81 | d/m/bb
  1274. //
  1275. // Number format code with unicode values provided for language glyphs where
  1276. // they occur in th-th language:
  1277. //
  1278. // Index | Symbol
  1279. // -------+-------------------------------------------
  1280. // 59 | t
  1281. // 60 | t0.0
  1282. // 61 | t#,##
  1283. // 62 | t#,##0.0
  1284. // 67 | t0
  1285. // 68 | t0.00
  1286. // 69 | t# ?/
  1287. // 70 | t# ??/?
  1288. // 71 | 0E27/0E14/0E1B0E1B0E1B0E1
  1289. // 72 | 0E27-0E140E140E14-0E1B0E1
  1290. // 73 | 0E27-0E140E140E1
  1291. // 74 | 0E140E140E14-0E1B0E1
  1292. // 75 | 0E0A:0E190E1
  1293. // 76 | 0E0A:0E190E19:0E170E1
  1294. // 77 | 0E27/0E14/0E1B0E1B0E1B0E1B 0E0A:0E190E1
  1295. // 78 | 0E190E19:0E170E1
  1296. // 79 | [0E0A]:0E190E19:0E170E1
  1297. // 80 | 0E190E19:0E170E17.
  1298. // 81 | d/m/bb
  1299. //
  1300. // Excelize built-in currency formats are shown in the following table, only
  1301. // support these types in the following table (Index number is used only for
  1302. // markup and is not used inside an Excel file and you can't get formatted value
  1303. // by the function GetCellValue) currently:
  1304. //
  1305. // Index | Symbol
  1306. // -------+---------------------------------------------------------------
  1307. // 164 | CN¥
  1308. // 165 | $ English (China)
  1309. // 166 | $ Cherokee (United States)
  1310. // 167 | $ Chinese (Singapore)
  1311. // 168 | $ Chinese (Taiwan)
  1312. // 169 | $ English (Australia)
  1313. // 170 | $ English (Belize)
  1314. // 171 | $ English (Canada)
  1315. // 172 | $ English (Jamaica)
  1316. // 173 | $ English (New Zealand)
  1317. // 174 | $ English (Singapore)
  1318. // 175 | $ English (Trinidad & Tobago)
  1319. // 176 | $ English (U.S. Vigin Islands)
  1320. // 177 | $ English (United States)
  1321. // 178 | $ French (Canada)
  1322. // 179 | $ Hawaiian (United States)
  1323. // 180 | $ Malay (Brunei)
  1324. // 181 | $ Quechua (Ecuador)
  1325. // 182 | $ Spanish (Chile)
  1326. // 183 | $ Spanish (Colombia)
  1327. // 184 | $ Spanish (Ecuador)
  1328. // 185 | $ Spanish (El Salvador)
  1329. // 186 | $ Spanish (Mexico)
  1330. // 187 | $ Spanish (Puerto Rico)
  1331. // 188 | $ Spanish (United States)
  1332. // 189 | $ Spanish (Uruguay)
  1333. // 190 | £ English (United Kingdom)
  1334. // 191 | £ Scottish Gaelic (United Kingdom)
  1335. // 192 | £ Welsh (United Kindom)
  1336. // 193 | ¥ Chinese (China)
  1337. // 194 | ¥ Japanese (Japan)
  1338. // 195 | ¥ Sichuan Yi (China)
  1339. // 196 | ¥ Tibetan (China)
  1340. // 197 | ¥ Uyghur (China)
  1341. // 198 | ֏ Armenian (Armenia)
  1342. // 199 | ؋ Pashto (Afghanistan)
  1343. // 200 | ؋ Persian (Afghanistan)
  1344. // 201 | ৳ Bengali (Bangladesh)
  1345. // 202 | ៛ Khmer (Cambodia)
  1346. // 203 | ₡ Spanish (Costa Rica)
  1347. // 204 | ₦ Hausa (Nigeria)
  1348. // 205 | ₦ Igbo (Nigeria)
  1349. // 206 | ₦ Yoruba (Nigeria)
  1350. // 207 | ₩ Korean (South Korea)
  1351. // 208 | ₪ Hebrew (Israel)
  1352. // 209 | ₫ Vietnamese (Vietnam)
  1353. // 210 | € Basque (Spain)
  1354. // 211 | € Breton (France)
  1355. // 212 | € Catalan (Spain)
  1356. // 213 | € Corsican (France)
  1357. // 214 | € Dutch (Belgium)
  1358. // 215 | € Dutch (Netherlands)
  1359. // 216 | € English (Ireland)
  1360. // 217 | € Estonian (Estonia)
  1361. // 218 | € Euro (€ 123)
  1362. // 219 | € Euro (123 €)
  1363. // 220 | € Finnish (Finland)
  1364. // 221 | € French (Belgium)
  1365. // 222 | € French (France)
  1366. // 223 | € French (Luxembourg)
  1367. // 224 | € French (Monaco)
  1368. // 225 | € French (Réunion)
  1369. // 226 | € Galician (Spain)
  1370. // 227 | € German (Austria)
  1371. // 228 | € German (Luxembourg)
  1372. // 229 | € Greek (Greece)
  1373. // 230 | € Inari Sami (Finland)
  1374. // 231 | € Irish (Ireland)
  1375. // 232 | € Italian (Italy)
  1376. // 233 | € Latin (Italy)
  1377. // 234 | € Latin, Serbian (Montenegro)
  1378. // 235 | € Larvian (Latvia)
  1379. // 236 | € Lithuanian (Lithuania)
  1380. // 237 | € Lower Sorbian (Germany)
  1381. // 238 | € Luxembourgish (Luxembourg)
  1382. // 239 | € Maltese (Malta)
  1383. // 240 | € Northern Sami (Finland)
  1384. // 241 | € Occitan (France)
  1385. // 242 | € Portuguese (Portugal)
  1386. // 243 | € Serbian (Montenegro)
  1387. // 244 | € Skolt Sami (Finland)
  1388. // 245 | € Slovak (Slovakia)
  1389. // 246 | € Slovenian (Slovenia)
  1390. // 247 | € Spanish (Spain)
  1391. // 248 | € Swedish (Finland)
  1392. // 249 | € Swiss German (France)
  1393. // 250 | € Upper Sorbian (Germany)
  1394. // 251 | € Western Frisian (Netherlands)
  1395. // 252 | ₭ Lao (Laos)
  1396. // 253 | ₮ Mongolian (Mongolia)
  1397. // 254 | ₮ Mongolian, Mongolian (Mongolia)
  1398. // 255 | ₱ English (Philippines)
  1399. // 256 | ₱ Filipino (Philippines)
  1400. // 257 | ₴ Ukrainian (Ukraine)
  1401. // 258 | ₸ Kazakh (Kazakhstan)
  1402. // 259 | ₹ Arabic, Kashmiri (India)
  1403. // 260 | ₹ English (India)
  1404. // 261 | ₹ Gujarati (India)
  1405. // 262 | ₹ Hindi (India)
  1406. // 263 | ₹ Kannada (India)
  1407. // 264 | ₹ Kashmiri (India)
  1408. // 265 | ₹ Konkani (India)
  1409. // 266 | ₹ Manipuri (India)
  1410. // 267 | ₹ Marathi (India)
  1411. // 268 | ₹ Nepali (India)
  1412. // 269 | ₹ Oriya (India)
  1413. // 270 | ₹ Punjabi (India)
  1414. // 271 | ₹ Sanskrit (India)
  1415. // 272 | ₹ Sindhi (India)
  1416. // 273 | ₹ Tamil (India)
  1417. // 274 | ₹ Urdu (India)
  1418. // 275 | ₺ Turkish (Turkey)
  1419. // 276 | ₼ Azerbaijani (Azerbaijan)
  1420. // 277 | ₼ Cyrillic, Azerbaijani (Azerbaijan)
  1421. // 278 | ₽ Russian (Russia)
  1422. // 279 | ₽ Sakha (Russia)
  1423. // 280 | ₾ Georgian (Georgia)
  1424. // 281 | B/. Spanish (Panama)
  1425. // 282 | Br Oromo (Ethiopia)
  1426. // 283 | Br Somali (Ethiopia)
  1427. // 284 | Br Tigrinya (Ethiopia)
  1428. // 285 | Bs Quechua (Bolivia)
  1429. // 286 | Bs Spanish (Bolivia)
  1430. // 287 | BS. Spanish (Venezuela)
  1431. // 288 | BWP Tswana (Botswana)
  1432. // 289 | C$ Spanish (Nicaragua)
  1433. // 290 | CA$ Latin, Inuktitut (Canada)
  1434. // 291 | CA$ Mohawk (Canada)
  1435. // 292 | CA$ Unified Canadian Aboriginal Syllabics, Inuktitut (Canada)
  1436. // 293 | CFA French (Mali)
  1437. // 294 | CFA French (Senegal)
  1438. // 295 | CFA Fulah (Senegal)
  1439. // 296 | CFA Wolof (Senegal)
  1440. // 297 | CHF French (Switzerland)
  1441. // 298 | CHF German (Liechtenstein)
  1442. // 299 | CHF German (Switzerland)
  1443. // 300 | CHF Italian (Switzerland)
  1444. // 301 | CHF Romansh (Switzerland)
  1445. // 302 | CLP Mapuche (Chile)
  1446. // 303 | CN¥ Mongolian, Mongolian (China)
  1447. // 304 | DZD Central Atlas Tamazight (Algeria)
  1448. // 305 | FCFA French (Cameroon)
  1449. // 306 | Ft Hungarian (Hungary)
  1450. // 307 | G French (Haiti)
  1451. // 308 | Gs. Spanish (Paraguay)
  1452. // 309 | GTQ K'iche' (Guatemala)
  1453. // 310 | HK$ Chinese (Hong Kong (China))
  1454. // 311 | HK$ English (Hong Kong (China))
  1455. // 312 | HRK Croatian (Croatia)
  1456. // 313 | IDR English (Indonesia)
  1457. // 314 | IQD Arbic, Central Kurdish (Iraq)
  1458. // 315 | ISK Icelandic (Iceland)
  1459. // 316 | K Burmese (Myanmar (Burma))
  1460. // 317 | Kč Czech (Czech Republic)
  1461. // 318 | KM Bosnian (Bosnia & Herzegovina)
  1462. // 319 | KM Croatian (Bosnia & Herzegovina)
  1463. // 320 | KM Latin, Serbian (Bosnia & Herzegovina)
  1464. // 321 | kr Faroese (Faroe Islands)
  1465. // 322 | kr Northern Sami (Norway)
  1466. // 323 | kr Northern Sami (Sweden)
  1467. // 324 | kr Norwegian Bokmål (Norway)
  1468. // 325 | kr Norwegian Nynorsk (Norway)
  1469. // 326 | kr Swedish (Sweden)
  1470. // 327 | kr. Danish (Denmark)
  1471. // 328 | kr. Kalaallisut (Greenland)
  1472. // 329 | Ksh Swahili (kenya)
  1473. // 330 | L Romanian (Moldova)
  1474. // 331 | L Russian (Moldova)
  1475. // 332 | L Spanish (Honduras)
  1476. // 333 | Lekë Albanian (Albania)
  1477. // 334 | MAD Arabic, Central Atlas Tamazight (Morocco)
  1478. // 335 | MAD French (Morocco)
  1479. // 336 | MAD Tifinagh, Central Atlas Tamazight (Morocco)
  1480. // 337 | MOP$ Chinese (Macau (China))
  1481. // 338 | MVR Divehi (Maldives)
  1482. // 339 | Nfk Tigrinya (Eritrea)
  1483. // 340 | NGN Bini (Nigeria)
  1484. // 341 | NGN Fulah (Nigeria)
  1485. // 342 | NGN Ibibio (Nigeria)
  1486. // 343 | NGN Kanuri (Nigeria)
  1487. // 344 | NOK Lule Sami (Norway)
  1488. // 345 | NOK Southern Sami (Norway)
  1489. // 346 | NZ$ Maori (New Zealand)
  1490. // 347 | PKR Sindhi (Pakistan)
  1491. // 348 | PYG Guarani (Paraguay)
  1492. // 349 | Q Spanish (Guatemala)
  1493. // 350 | R Afrikaans (South Africa)
  1494. // 351 | R English (South Africa)
  1495. // 352 | R Zulu (South Africa)
  1496. // 353 | R$ Portuguese (Brazil)
  1497. // 354 | RD$ Spanish (Dominican Republic)
  1498. // 355 | RF Kinyarwanda (Rwanda)
  1499. // 356 | RM English (Malaysia)
  1500. // 357 | RM Malay (Malaysia)
  1501. // 358 | RON Romanian (Romania)
  1502. // 359 | Rp Indonesoan (Indonesia)
  1503. // 360 | Rs Urdu (Pakistan)
  1504. // 361 | Rs. Tamil (Sri Lanka)
  1505. // 362 | RSD Latin, Serbian (Serbia)
  1506. // 363 | RSD Serbian (Serbia)
  1507. // 364 | RUB Bashkir (Russia)
  1508. // 365 | RUB Tatar (Russia)
  1509. // 366 | S/. Quechua (Peru)
  1510. // 367 | S/. Spanish (Peru)
  1511. // 368 | SEK Lule Sami (Sweden)
  1512. // 369 | SEK Southern Sami (Sweden)
  1513. // 370 | soʻm Latin, Uzbek (Uzbekistan)
  1514. // 371 | soʻm Uzbek (Uzbekistan)
  1515. // 372 | SYP Syriac (Syria)
  1516. // 373 | THB Thai (Thailand)
  1517. // 374 | TMT Turkmen (Turkmenistan)
  1518. // 375 | US$ English (Zimbabwe)
  1519. // 376 | ZAR Northern Sotho (South Africa)
  1520. // 377 | ZAR Southern Sotho (South Africa)
  1521. // 378 | ZAR Tsonga (South Africa)
  1522. // 379 | ZAR Tswana (south Africa)
  1523. // 380 | ZAR Venda (South Africa)
  1524. // 381 | ZAR Xhosa (South Africa)
  1525. // 382 | zł Polish (Poland)
  1526. // 383 | ден Macedonian (Macedonia)
  1527. // 384 | KM Cyrillic, Bosnian (Bosnia & Herzegovina)
  1528. // 385 | KM Serbian (Bosnia & Herzegovina)
  1529. // 386 | лв. Bulgarian (Bulgaria)
  1530. // 387 | p. Belarusian (Belarus)
  1531. // 388 | сом Kyrgyz (Kyrgyzstan)
  1532. // 389 | сом Tajik (Tajikistan)
  1533. // 390 | ج.م. Arabic (Egypt)
  1534. // 391 | د.أ. Arabic (Jordan)
  1535. // 392 | د.أ. Arabic (United Arab Emirates)
  1536. // 393 | د.ب. Arabic (Bahrain)
  1537. // 394 | د.ت. Arabic (Tunisia)
  1538. // 395 | د.ج. Arabic (Algeria)
  1539. // 396 | د.ع. Arabic (Iraq)
  1540. // 397 | د.ك. Arabic (Kuwait)
  1541. // 398 | د.ل. Arabic (Libya)
  1542. // 399 | د.م. Arabic (Morocco)
  1543. // 400 | ر Punjabi (Pakistan)
  1544. // 401 | ر.س. Arabic (Saudi Arabia)
  1545. // 402 | ر.ع. Arabic (Oman)
  1546. // 403 | ر.ق. Arabic (Qatar)
  1547. // 404 | ر.ي. Arabic (Yemen)
  1548. // 405 | ریال Persian (Iran)
  1549. // 406 | ل.س. Arabic (Syria)
  1550. // 407 | ل.ل. Arabic (Lebanon)
  1551. // 408 | ብር Amharic (Ethiopia)
  1552. // 409 | रू Nepaol (Nepal)
  1553. // 410 | රු. Sinhala (Sri Lanka)
  1554. // 411 | ADP
  1555. // 412 | AED
  1556. // 413 | AFA
  1557. // 414 | AFN
  1558. // 415 | ALL
  1559. // 416 | AMD
  1560. // 417 | ANG
  1561. // 418 | AOA
  1562. // 419 | ARS
  1563. // 420 | ATS
  1564. // 421 | AUD
  1565. // 422 | AWG
  1566. // 423 | AZM
  1567. // 424 | AZN
  1568. // 425 | BAM
  1569. // 426 | BBD
  1570. // 427 | BDT
  1571. // 428 | BEF
  1572. // 429 | BGL
  1573. // 430 | BGN
  1574. // 431 | BHD
  1575. // 432 | BIF
  1576. // 433 | BMD
  1577. // 434 | BND
  1578. // 435 | BOB
  1579. // 436 | BOV
  1580. // 437 | BRL
  1581. // 438 | BSD
  1582. // 439 | BTN
  1583. // 440 | BWP
  1584. // 441 | BYR
  1585. // 442 | BZD
  1586. // 443 | CAD
  1587. // 444 | CDF
  1588. // 445 | CHE
  1589. // 446 | CHF
  1590. // 447 | CHW
  1591. // 448 | CLF
  1592. // 449 | CLP
  1593. // 450 | CNY
  1594. // 451 | COP
  1595. // 452 | COU
  1596. // 453 | CRC
  1597. // 454 | CSD
  1598. // 455 | CUC
  1599. // 456 | CVE
  1600. // 457 | CYP
  1601. // 458 | CZK
  1602. // 459 | DEM
  1603. // 460 | DJF
  1604. // 461 | DKK
  1605. // 462 | DOP
  1606. // 463 | DZD
  1607. // 464 | ECS
  1608. // 465 | ECV
  1609. // 466 | EEK
  1610. // 467 | EGP
  1611. // 468 | ERN
  1612. // 469 | ESP
  1613. // 470 | ETB
  1614. // 471 | EUR
  1615. // 472 | FIM
  1616. // 473 | FJD
  1617. // 474 | FKP
  1618. // 475 | FRF
  1619. // 476 | GBP
  1620. // 477 | GEL
  1621. // 478 | GHC
  1622. // 479 | GHS
  1623. // 480 | GIP
  1624. // 481 | GMD
  1625. // 482 | GNF
  1626. // 483 | GRD
  1627. // 484 | GTQ
  1628. // 485 | GYD
  1629. // 486 | HKD
  1630. // 487 | HNL
  1631. // 488 | HRK
  1632. // 489 | HTG
  1633. // 490 | HUF
  1634. // 491 | IDR
  1635. // 492 | IEP
  1636. // 493 | ILS
  1637. // 494 | INR
  1638. // 495 | IQD
  1639. // 496 | IRR
  1640. // 497 | ISK
  1641. // 498 | ITL
  1642. // 499 | JMD
  1643. // 500 | JOD
  1644. // 501 | JPY
  1645. // 502 | KAF
  1646. // 503 | KES
  1647. // 504 | KGS
  1648. // 505 | KHR
  1649. // 506 | KMF
  1650. // 507 | KPW
  1651. // 508 | KRW
  1652. // 509 | KWD
  1653. // 510 | KYD
  1654. // 511 | KZT
  1655. // 512 | LAK
  1656. // 513 | LBP
  1657. // 514 | LKR
  1658. // 515 | LRD
  1659. // 516 | LSL
  1660. // 517 | LTL
  1661. // 518 | LUF
  1662. // 519 | LVL
  1663. // 520 | LYD
  1664. // 521 | MAD
  1665. // 522 | MDL
  1666. // 523 | MGA
  1667. // 524 | MGF
  1668. // 525 | MKD
  1669. // 526 | MMK
  1670. // 527 | MNT
  1671. // 528 | MOP
  1672. // 529 | MRO
  1673. // 530 | MTL
  1674. // 531 | MUR
  1675. // 532 | MVR
  1676. // 533 | MWK
  1677. // 534 | MXN
  1678. // 535 | MXV
  1679. // 536 | MYR
  1680. // 537 | MZM
  1681. // 538 | MZN
  1682. // 539 | NAD
  1683. // 540 | NGN
  1684. // 541 | NIO
  1685. // 542 | NLG
  1686. // 543 | NOK
  1687. // 544 | NPR
  1688. // 545 | NTD
  1689. // 546 | NZD
  1690. // 547 | OMR
  1691. // 548 | PAB
  1692. // 549 | PEN
  1693. // 550 | PGK
  1694. // 551 | PHP
  1695. // 552 | PKR
  1696. // 553 | PLN
  1697. // 554 | PTE
  1698. // 555 | PYG
  1699. // 556 | QAR
  1700. // 557 | ROL
  1701. // 558 | RON
  1702. // 559 | RSD
  1703. // 560 | RUB
  1704. // 561 | RUR
  1705. // 562 | RWF
  1706. // 563 | SAR
  1707. // 564 | SBD
  1708. // 565 | SCR
  1709. // 566 | SDD
  1710. // 567 | SDG
  1711. // 568 | SDP
  1712. // 569 | SEK
  1713. // 570 | SGD
  1714. // 571 | SHP
  1715. // 572 | SIT
  1716. // 573 | SKK
  1717. // 574 | SLL
  1718. // 575 | SOS
  1719. // 576 | SPL
  1720. // 577 | SRD
  1721. // 578 | SRG
  1722. // 579 | STD
  1723. // 580 | SVC
  1724. // 581 | SYP
  1725. // 582 | SZL
  1726. // 583 | THB
  1727. // 584 | TJR
  1728. // 585 | TJS
  1729. // 586 | TMM
  1730. // 587 | TMT
  1731. // 588 | TND
  1732. // 589 | TOP
  1733. // 590 | TRL
  1734. // 591 | TRY
  1735. // 592 | TTD
  1736. // 593 | TWD
  1737. // 594 | TZS
  1738. // 595 | UAH
  1739. // 596 | UGX
  1740. // 597 | USD
  1741. // 598 | USN
  1742. // 599 | USS
  1743. // 600 | UYI
  1744. // 601 | UYU
  1745. // 602 | UZS
  1746. // 603 | VEB
  1747. // 604 | VEF
  1748. // 605 | VND
  1749. // 606 | VUV
  1750. // 607 | WST
  1751. // 608 | XAF
  1752. // 609 | XAG
  1753. // 610 | XAU
  1754. // 611 | XB5
  1755. // 612 | XBA
  1756. // 613 | XBB
  1757. // 614 | XBC
  1758. // 615 | XBD
  1759. // 616 | XCD
  1760. // 617 | XDR
  1761. // 618 | XFO
  1762. // 619 | XFU
  1763. // 620 | XOF
  1764. // 621 | XPD
  1765. // 622 | XPF
  1766. // 623 | XPT
  1767. // 624 | XTS
  1768. // 625 | XXX
  1769. // 626 | YER
  1770. // 627 | YUM
  1771. // 628 | ZAR
  1772. // 629 | ZMK
  1773. // 630 | ZMW
  1774. // 631 | ZWD
  1775. // 632 | ZWL
  1776. // 633 | ZWN
  1777. // 634 | ZWR
  1778. //
  1779. // Excelize support set custom number format for cell. For example, set number
  1780. // as date type in Uruguay (Spanish) format for Sheet1!A6:
  1781. //
  1782. // xlsx := excelize.NewFile()
  1783. // xlsx.SetCellValue("Sheet1", "A6", 42920.5)
  1784. // style, _ := xlsx.NewStyle(`{"custom_number_format": "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@"}`)
  1785. // xlsx.SetCellStyle("Sheet1", "A6", "A6", style)
  1786. //
  1787. // Cell Sheet1!A6 in the Excel Application: martes, 04 de Julio de 2017
  1788. //
  1789. func (f *File) NewStyle(style string) (int, error) {
  1790. var cellXfsID int
  1791. styleSheet := f.stylesReader()
  1792. formatCellStyle, err := parseFormatStyleSet(style)
  1793. if err != nil {
  1794. return cellXfsID, err
  1795. }
  1796. numFmtID := setNumFmt(styleSheet, formatCellStyle)
  1797. fontID := setFont(styleSheet, formatCellStyle)
  1798. borderID := setBorders(styleSheet, formatCellStyle)
  1799. fillID := setFills(styleSheet, formatCellStyle)
  1800. applyAlignment, alignment := setAlignment(styleSheet, formatCellStyle)
  1801. cellXfsID = setCellXfs(styleSheet, fontID, numFmtID, fillID, borderID, applyAlignment, alignment)
  1802. return cellXfsID, nil
  1803. }
  1804. // setFont provides function to add font style by given cell format settings.
  1805. func setFont(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1806. if formatCellStyle.Font == nil {
  1807. return 0
  1808. }
  1809. fontUnderlineType := map[string]string{"single": "single", "double": "double"}
  1810. if formatCellStyle.Font.Family == "" {
  1811. formatCellStyle.Font.Family = "Calibri"
  1812. }
  1813. if formatCellStyle.Font.Size < 1 {
  1814. formatCellStyle.Font.Size = 11
  1815. }
  1816. if formatCellStyle.Font.Color == "" {
  1817. formatCellStyle.Font.Color = "#000000"
  1818. }
  1819. f := font{
  1820. B: formatCellStyle.Font.Bold,
  1821. I: formatCellStyle.Font.Italic,
  1822. Sz: &attrValInt{Val: formatCellStyle.Font.Size},
  1823. Color: &xlsxColor{RGB: getPaletteColor(formatCellStyle.Font.Color)},
  1824. Name: &attrValString{Val: formatCellStyle.Font.Family},
  1825. Family: &attrValInt{Val: 2},
  1826. Scheme: &attrValString{Val: "minor"},
  1827. }
  1828. val, ok := fontUnderlineType[formatCellStyle.Font.Underline]
  1829. if ok {
  1830. f.U = &attrValString{Val: val}
  1831. }
  1832. font, _ := xml.Marshal(f)
  1833. style.Fonts.Count++
  1834. style.Fonts.Font = append(style.Fonts.Font, &xlsxFont{
  1835. Font: string(font[6 : len(font)-7]),
  1836. })
  1837. return style.Fonts.Count - 1
  1838. }
  1839. // setNumFmt provides function to check if number format code in the range of
  1840. // built-in values.
  1841. func setNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1842. dp := "0."
  1843. numFmtID := 164 // Default custom number format code from 164.
  1844. if formatCellStyle.DecimalPlaces < 0 || formatCellStyle.DecimalPlaces > 30 {
  1845. formatCellStyle.DecimalPlaces = 2
  1846. }
  1847. for i := 0; i < formatCellStyle.DecimalPlaces; i++ {
  1848. dp += "0"
  1849. }
  1850. if formatCellStyle.CustomNumFmt != nil {
  1851. return setCustomNumFmt(style, formatCellStyle)
  1852. }
  1853. _, ok := builtInNumFmt[formatCellStyle.NumFmt]
  1854. if !ok {
  1855. fc, currency := currencyNumFmt[formatCellStyle.NumFmt]
  1856. if !currency {
  1857. return setLangNumFmt(style, formatCellStyle)
  1858. }
  1859. fc = strings.Replace(fc, "0.00", dp, -1)
  1860. if formatCellStyle.NegRed {
  1861. fc = fc + ";[Red]" + fc
  1862. }
  1863. if style.NumFmts != nil {
  1864. numFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1
  1865. nf := xlsxNumFmt{
  1866. FormatCode: fc,
  1867. NumFmtID: numFmtID,
  1868. }
  1869. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1870. style.NumFmts.Count++
  1871. } else {
  1872. nf := xlsxNumFmt{
  1873. FormatCode: fc,
  1874. NumFmtID: numFmtID,
  1875. }
  1876. numFmts := xlsxNumFmts{
  1877. NumFmt: []*xlsxNumFmt{&nf},
  1878. Count: 1,
  1879. }
  1880. style.NumFmts = &numFmts
  1881. }
  1882. return numFmtID
  1883. }
  1884. return formatCellStyle.NumFmt
  1885. }
  1886. // setCustomNumFmt provides function to set custom number format code.
  1887. func setCustomNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1888. nf := xlsxNumFmt{FormatCode: *formatCellStyle.CustomNumFmt}
  1889. if style.NumFmts != nil {
  1890. nf.NumFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1
  1891. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1892. style.NumFmts.Count++
  1893. } else {
  1894. nf.NumFmtID = 164
  1895. numFmts := xlsxNumFmts{
  1896. NumFmt: []*xlsxNumFmt{&nf},
  1897. Count: 1,
  1898. }
  1899. style.NumFmts = &numFmts
  1900. }
  1901. return nf.NumFmtID
  1902. }
  1903. // setLangNumFmt provides function to set number format code with language.
  1904. func setLangNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1905. numFmts, ok := langNumFmt[formatCellStyle.Lang]
  1906. if !ok {
  1907. return 0
  1908. }
  1909. var fc string
  1910. fc, ok = numFmts[formatCellStyle.NumFmt]
  1911. if !ok {
  1912. return 0
  1913. }
  1914. nf := xlsxNumFmt{FormatCode: fc}
  1915. if style.NumFmts != nil {
  1916. nf.NumFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1
  1917. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1918. style.NumFmts.Count++
  1919. } else {
  1920. nf.NumFmtID = formatCellStyle.NumFmt
  1921. numFmts := xlsxNumFmts{
  1922. NumFmt: []*xlsxNumFmt{&nf},
  1923. Count: 1,
  1924. }
  1925. style.NumFmts = &numFmts
  1926. }
  1927. return nf.NumFmtID
  1928. }
  1929. // setFills provides function to add fill elements in the styles.xml by given
  1930. // cell format settings.
  1931. func setFills(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1932. var patterns = []string{
  1933. "none",
  1934. "solid",
  1935. "mediumGray",
  1936. "darkGray",
  1937. "lightGray",
  1938. "darkHorizontal",
  1939. "darkVertical",
  1940. "darkDown",
  1941. "darkUp",
  1942. "darkGrid",
  1943. "darkTrellis",
  1944. "lightHorizontal",
  1945. "lightVertical",
  1946. "lightDown",
  1947. "lightUp",
  1948. "lightGrid",
  1949. "lightTrellis",
  1950. "gray125",
  1951. "gray0625",
  1952. }
  1953. var variants = []float64{
  1954. 90,
  1955. 0,
  1956. 45,
  1957. 135,
  1958. }
  1959. var fill xlsxFill
  1960. switch formatCellStyle.Fill.Type {
  1961. case "gradient":
  1962. if len(formatCellStyle.Fill.Color) != 2 {
  1963. break
  1964. }
  1965. var gradient xlsxGradientFill
  1966. switch formatCellStyle.Fill.Shading {
  1967. case 0, 1, 2, 3:
  1968. gradient.Degree = variants[formatCellStyle.Fill.Shading]
  1969. case 4:
  1970. gradient.Type = "path"
  1971. case 5:
  1972. gradient.Type = "path"
  1973. gradient.Bottom = 0.5
  1974. gradient.Left = 0.5
  1975. gradient.Right = 0.5
  1976. gradient.Top = 0.5
  1977. default:
  1978. break
  1979. }
  1980. var stops []*xlsxGradientFillStop
  1981. for index, color := range formatCellStyle.Fill.Color {
  1982. var stop xlsxGradientFillStop
  1983. stop.Position = float64(index)
  1984. stop.Color.RGB = getPaletteColor(color)
  1985. stops = append(stops, &stop)
  1986. }
  1987. gradient.Stop = stops
  1988. fill.GradientFill = &gradient
  1989. case "pattern":
  1990. if formatCellStyle.Fill.Pattern > 18 || formatCellStyle.Fill.Pattern < 0 {
  1991. break
  1992. }
  1993. if len(formatCellStyle.Fill.Color) < 1 {
  1994. break
  1995. }
  1996. var pattern xlsxPatternFill
  1997. pattern.PatternType = patterns[formatCellStyle.Fill.Pattern]
  1998. pattern.FgColor.RGB = getPaletteColor(formatCellStyle.Fill.Color[0])
  1999. fill.PatternFill = &pattern
  2000. }
  2001. style.Fills.Count++
  2002. style.Fills.Fill = append(style.Fills.Fill, &fill)
  2003. return style.Fills.Count - 1
  2004. }
  2005. // setAlignment provides function to formatting information pertaining to text
  2006. // alignment in cells. There are a variety of choices for how text is aligned
  2007. // both horizontally and vertically, as well as indentation settings, and so on.
  2008. func setAlignment(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) (bool, *xlsxAlignment) {
  2009. if formatCellStyle.Alignment == nil {
  2010. return false, &xlsxAlignment{}
  2011. }
  2012. var alignment = xlsxAlignment{
  2013. Horizontal: formatCellStyle.Alignment.Horizontal,
  2014. Indent: formatCellStyle.Alignment.Indent,
  2015. JustifyLastLine: formatCellStyle.Alignment.JustifyLastLine,
  2016. ReadingOrder: formatCellStyle.Alignment.ReadingOrder,
  2017. RelativeIndent: formatCellStyle.Alignment.RelativeIndent,
  2018. ShrinkToFit: formatCellStyle.Alignment.ShrinkToFit,
  2019. TextRotation: formatCellStyle.Alignment.TextRotation,
  2020. Vertical: formatCellStyle.Alignment.Vertical,
  2021. WrapText: formatCellStyle.Alignment.WrapText,
  2022. }
  2023. return true, &alignment
  2024. }
  2025. // setBorders provides function to add border elements in the styles.xml by
  2026. // given borders format settings.
  2027. func setBorders(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  2028. var styles = []string{
  2029. "none",
  2030. "thin",
  2031. "medium",
  2032. "dashed",
  2033. "dotted",
  2034. "thick",
  2035. "double",
  2036. "hair",
  2037. "mediumDashed",
  2038. "dashDot",
  2039. "mediumDashDot",
  2040. "dashDotDot",
  2041. "mediumDashDotDot",
  2042. "slantDashDot",
  2043. }
  2044. var border xlsxBorder
  2045. for _, v := range formatCellStyle.Border {
  2046. if v.Style > 13 || v.Style < 0 {
  2047. continue
  2048. }
  2049. var color xlsxColor
  2050. color.RGB = getPaletteColor(v.Color)
  2051. switch v.Type {
  2052. case "left":
  2053. border.Left.Style = styles[v.Style]
  2054. border.Left.Color = &color
  2055. case "right":
  2056. border.Right.Style = styles[v.Style]
  2057. border.Right.Color = &color
  2058. case "top":
  2059. border.Top.Style = styles[v.Style]
  2060. border.Top.Color = &color
  2061. case "bottom":
  2062. border.Bottom.Style = styles[v.Style]
  2063. border.Bottom.Color = &color
  2064. case "diagonalUp":
  2065. border.Diagonal.Style = styles[v.Style]
  2066. border.Diagonal.Color = &color
  2067. border.DiagonalUp = true
  2068. case "diagonalDown":
  2069. border.Diagonal.Style = styles[v.Style]
  2070. border.Diagonal.Color = &color
  2071. border.DiagonalDown = true
  2072. }
  2073. }
  2074. style.Borders.Count++
  2075. style.Borders.Border = append(style.Borders.Border, &border)
  2076. return style.Borders.Count - 1
  2077. }
  2078. // setCellXfs provides function to set describes all of the formatting for a
  2079. // cell.
  2080. func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment bool, alignment *xlsxAlignment) int {
  2081. var xf xlsxXf
  2082. xf.FontID = fontID
  2083. if fontID != 0 {
  2084. xf.ApplyFont = true
  2085. }
  2086. xf.NumFmtID = numFmtID
  2087. if numFmtID != 0 {
  2088. xf.ApplyNumberFormat = true
  2089. }
  2090. xf.FillID = fillID
  2091. xf.BorderID = borderID
  2092. style.CellXfs.Count++
  2093. xf.Alignment = alignment
  2094. xf.ApplyAlignment = applyAlignment
  2095. xfID := 0
  2096. xf.XfID = &xfID
  2097. style.CellXfs.Xf = append(style.CellXfs.Xf, xf)
  2098. return style.CellXfs.Count - 1
  2099. }
  2100. // SetCellStyle provides function to add style attribute for cells by given
  2101. // worksheet sheet index, coordinate area and style ID. Note that diagonalDown
  2102. // and diagonalUp type border should be use same color in the same coordinate
  2103. // area.
  2104. //
  2105. // For example create a borders of cell H9 on Sheet1:
  2106. //
  2107. // 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}]}`)
  2108. // if err != nil {
  2109. // fmt.Println(err)
  2110. // }
  2111. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  2112. //
  2113. // Set gradient fill with vertical variants shading styles for cell H9 on
  2114. // Sheet1:
  2115. //
  2116. // style, err := xlsx.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
  2117. // if err != nil {
  2118. // fmt.Println(err)
  2119. // }
  2120. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  2121. //
  2122. // Set solid style pattern fill for cell H9 on Sheet1:
  2123. //
  2124. // style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
  2125. // if err != nil {
  2126. // fmt.Println(err)
  2127. // }
  2128. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  2129. //
  2130. // Set alignment style for cell H9 on Sheet1:
  2131. //
  2132. // 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}}`)
  2133. // if err != nil {
  2134. // fmt.Println(err)
  2135. // }
  2136. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  2137. //
  2138. // Dates and times in Excel are represented by real numbers, for example "Apr 7
  2139. // 2017 12:00 PM" is represented by the number 42920.5. Set date and time format
  2140. // for cell H9 on Sheet1:
  2141. //
  2142. // xlsx.SetCellValue("Sheet1", "H9", 42920.5)
  2143. // style, err := xlsx.NewStyle(`{"number_format": 22}`)
  2144. // if err != nil {
  2145. // fmt.Println(err)
  2146. // }
  2147. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  2148. //
  2149. // Set font style for cell H9 on Sheet1:
  2150. //
  2151. // style, err := xlsx.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`)
  2152. // if err != nil {
  2153. // fmt.Println(err)
  2154. // }
  2155. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  2156. //
  2157. func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
  2158. hcell = strings.ToUpper(hcell)
  2159. vcell = strings.ToUpper(vcell)
  2160. // Coordinate conversion, convert C1:B3 to 2,0,1,2.
  2161. hcol := string(strings.Map(letterOnlyMapF, hcell))
  2162. hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell))
  2163. hyAxis := hrow - 1
  2164. hxAxis := TitleToNumber(hcol)
  2165. vcol := string(strings.Map(letterOnlyMapF, vcell))
  2166. vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell))
  2167. vyAxis := vrow - 1
  2168. vxAxis := TitleToNumber(vcol)
  2169. if vxAxis < hxAxis {
  2170. hcell, vcell = vcell, hcell
  2171. vxAxis, hxAxis = hxAxis, vxAxis
  2172. }
  2173. if vyAxis < hyAxis {
  2174. hcell, vcell = vcell, hcell
  2175. vyAxis, hyAxis = hyAxis, vyAxis
  2176. }
  2177. // Correct the coordinate area, such correct C1:B3 to B1:C3.
  2178. hcell = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1)
  2179. vcell = ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
  2180. xlsx := f.workSheetReader(sheet)
  2181. completeRow(xlsx, vyAxis+1, vxAxis+1)
  2182. completeCol(xlsx, vyAxis+1, vxAxis+1)
  2183. for r, row := range xlsx.SheetData.Row {
  2184. for k, c := range row.C {
  2185. if checkCellInArea(c.R, hcell+":"+vcell) {
  2186. xlsx.SheetData.Row[r].C[k].S = styleID
  2187. }
  2188. }
  2189. }
  2190. }
  2191. // getPaletteColor provides function to convert the RBG color by given string.
  2192. func getPaletteColor(color string) string {
  2193. return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
  2194. }