styles.go 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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": map[int]string{
  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. }
  527. // builtInNumFmtFunc defined the format conversion functions map. Partial format
  528. // code doesn't support currently and will return original string.
  529. var builtInNumFmtFunc = map[int]func(i int, v string) string{
  530. 0: formatToString,
  531. 1: formatToInt,
  532. 2: formatToFloat,
  533. 3: formatToInt,
  534. 4: formatToFloat,
  535. 9: formatToC,
  536. 10: formatToD,
  537. 11: formatToE,
  538. 12: formatToString, // Doesn't support currently
  539. 13: formatToString, // Doesn't support currently
  540. 14: parseTime,
  541. 15: parseTime,
  542. 16: parseTime,
  543. 17: parseTime,
  544. 18: parseTime,
  545. 19: parseTime,
  546. 20: parseTime,
  547. 21: parseTime,
  548. 22: parseTime,
  549. 37: formatToA,
  550. 38: formatToA,
  551. 39: formatToB,
  552. 40: formatToB,
  553. 41: formatToString, // Doesn't support currently
  554. 42: formatToString, // Doesn't support currently
  555. 43: formatToString, // Doesn't support currently
  556. 44: formatToString, // Doesn't support currently
  557. 45: parseTime,
  558. 46: parseTime,
  559. 47: parseTime,
  560. 48: formatToE,
  561. 49: formatToString,
  562. }
  563. // formatToString provides function to return original string by given built-in
  564. // number formats code and cell string.
  565. func formatToString(i int, v string) string {
  566. return v
  567. }
  568. // formatToInt provides function to convert original string to integer format as
  569. // string type by given built-in number formats code and cell string.
  570. func formatToInt(i int, v string) string {
  571. f, err := strconv.ParseFloat(v, 64)
  572. if err != nil {
  573. return v
  574. }
  575. return fmt.Sprintf("%d", int(f))
  576. }
  577. // formatToFloat provides function to convert original string to float format as
  578. // string type by given built-in number formats code and cell string.
  579. func formatToFloat(i int, v string) string {
  580. f, err := strconv.ParseFloat(v, 64)
  581. if err != nil {
  582. return v
  583. }
  584. return fmt.Sprintf("%.2f", f)
  585. }
  586. // formatToA provides function to convert original string to special format as
  587. // string type by given built-in number formats code and cell string.
  588. func formatToA(i int, v string) string {
  589. f, err := strconv.ParseFloat(v, 64)
  590. if err != nil {
  591. return v
  592. }
  593. if f < 0 {
  594. t := int(math.Abs(f))
  595. return fmt.Sprintf("(%d)", t)
  596. }
  597. t := int(f)
  598. return fmt.Sprintf("%d", t)
  599. }
  600. // formatToB provides function to convert original string to special format as
  601. // string type by given built-in number formats code and cell string.
  602. func formatToB(i int, v string) string {
  603. f, err := strconv.ParseFloat(v, 64)
  604. if err != nil {
  605. return v
  606. }
  607. if f < 0 {
  608. return fmt.Sprintf("(%.2f)", f)
  609. }
  610. return fmt.Sprintf("%.2f", f)
  611. }
  612. // formatToC provides function to convert original string to special format as
  613. // string type by given built-in number formats code and cell string.
  614. func formatToC(i int, v string) string {
  615. f, err := strconv.ParseFloat(v, 64)
  616. if err != nil {
  617. return v
  618. }
  619. f = f * 100
  620. return fmt.Sprintf("%d%%", int(f))
  621. }
  622. // formatToD provides function to convert original string to special format as
  623. // string type by given built-in number formats code and cell string.
  624. func formatToD(i int, v string) string {
  625. f, err := strconv.ParseFloat(v, 64)
  626. if err != nil {
  627. return v
  628. }
  629. f = f * 100
  630. return fmt.Sprintf("%.2f%%", f)
  631. }
  632. // formatToE provides function to convert original string to special format as
  633. // string type by given built-in number formats code and cell string.
  634. func formatToE(i int, v string) string {
  635. f, err := strconv.ParseFloat(v, 64)
  636. if err != nil {
  637. return v
  638. }
  639. return fmt.Sprintf("%.e", f)
  640. }
  641. // parseTime provides function to returns a string parsed using time.Time.
  642. // Replace Excel placeholders with Go time placeholders. For example, replace
  643. // yyyy with 2006. These are in a specific order, due to the fact that m is used
  644. // in month, minute, and am/pm. It would be easier to fix that with regular
  645. // expressions, but if it's possible to keep this simple it would be easier to
  646. // maintain. Full-length month and days (e.g. March, Tuesday) have letters in
  647. // them that would be replaced by other characters below (such as the 'h' in
  648. // March, or the 'd' in Tuesday) below. First we convert them to arbitrary
  649. // characters unused in Excel Date formats, and then at the end, turn them to
  650. // what they should actually be.
  651. func parseTime(i int, v string) string {
  652. f, err := strconv.ParseFloat(v, 64)
  653. if err != nil {
  654. return v
  655. }
  656. val := timeFromExcelTime(f, false)
  657. format := builtInNumFmt[i]
  658. replacements := []struct{ xltime, gotime string }{
  659. {"yyyy", "2006"},
  660. {"yy", "06"},
  661. {"mmmm", "%%%%"},
  662. {"dddd", "&&&&"},
  663. {"dd", "02"},
  664. {"d", "2"},
  665. {"mmm", "Jan"},
  666. {"mmss", "0405"},
  667. {"ss", "05"},
  668. {"hh", "15"},
  669. {"h", "3"},
  670. {"mm:", "04:"},
  671. {":mm", ":04"},
  672. {"mm", "01"},
  673. {"am/pm", "pm"},
  674. {"m/", "1/"},
  675. {"%%%%", "January"},
  676. {"&&&&", "Monday"},
  677. }
  678. for _, repl := range replacements {
  679. format = strings.Replace(format, repl.xltime, repl.gotime, 1)
  680. }
  681. // If the hour is optional, strip it out, along with the possible dangling
  682. // colon that would remain.
  683. if val.Hour() < 1 {
  684. format = strings.Replace(format, "]:", "]", 1)
  685. format = strings.Replace(format, "[3]", "", 1)
  686. format = strings.Replace(format, "[15]", "", 1)
  687. } else {
  688. format = strings.Replace(format, "[3]", "3", 1)
  689. format = strings.Replace(format, "[15]", "15", 1)
  690. }
  691. return val.Format(format)
  692. }
  693. // stylesReader provides function to get the pointer to the structure after
  694. // deserialization of xl/styles.xml.
  695. func (f *File) stylesReader() *xlsxStyleSheet {
  696. if f.Styles == nil {
  697. var styleSheet xlsxStyleSheet
  698. xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
  699. f.Styles = &styleSheet
  700. }
  701. return f.Styles
  702. }
  703. // styleSheetWriter provides function to save xl/styles.xml after serialize
  704. // structure.
  705. func (f *File) styleSheetWriter() {
  706. if f.Styles != nil {
  707. output, _ := xml.Marshal(f.Styles)
  708. f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpace(string(output)))
  709. }
  710. }
  711. // parseFormatStyleSet provides function to parse the format settings of the
  712. // borders.
  713. func parseFormatStyleSet(style string) (*formatCellStyle, error) {
  714. format := formatCellStyle{
  715. DecimalPlaces: 2,
  716. }
  717. err := json.Unmarshal([]byte(style), &format)
  718. return &format, err
  719. }
  720. // NewStyle provides function to create style for cells by given style format.
  721. // Note that the color field uses RGB color code.
  722. //
  723. // The following shows the border styles sorted by excelize index number:
  724. //
  725. // | Index | Name | Weight | Style |
  726. // +-------+---------------+--------+-------------+
  727. // | 0 | None | 0 | |
  728. // | 1 | Continuous | 1 | ----------- |
  729. // | 2 | Continuous | 2 | ----------- |
  730. // | 3 | Dash | 1 | - - - - - - |
  731. // | 4 | Dot | 1 | . . . . . . |
  732. // | 5 | Continuous | 3 | ----------- |
  733. // | 6 | Double | 3 | =========== |
  734. // | 7 | Continuous | 0 | ----------- |
  735. // | 8 | Dash | 2 | - - - - - - |
  736. // | 9 | Dash Dot | 1 | - . - . - . |
  737. // | 10 | Dash Dot | 2 | - . - . - . |
  738. // | 11 | Dash Dot Dot | 1 | - . . - . . |
  739. // | 12 | Dash Dot Dot | 2 | - . . - . . |
  740. // | 13 | SlantDash Dot | 2 | / - . / - . |
  741. //
  742. // The following shows the borders in the order shown in the Excel dialog:
  743. //
  744. // | Index | Style | Index | Style |
  745. // +-------+-------------+-------+-------------+
  746. // | 0 | None | 12 | - . . - . . |
  747. // | 7 | ----------- | 13 | / - . / - . |
  748. // | 4 | . . . . . . | 10 | - . - . - . |
  749. // | 11 | - . . - . . | 8 | - - - - - - |
  750. // | 9 | - . - . - . | 2 | ----------- |
  751. // | 3 | - - - - - - | 5 | ----------- |
  752. // | 1 | ----------- | 6 | =========== |
  753. //
  754. // The following shows the shading styles sorted by excelize index number:
  755. //
  756. // | Index | Style | Index | Style |
  757. // +-------+-----------------+-------+-----------------+
  758. // | 0 | Horizontal | 3 | Diagonal down |
  759. // | 1 | Vertical | 4 | From corner |
  760. // | 2 | Diagonal Up | 5 | From center |
  761. //
  762. // The following shows the patterns styles sorted by excelize index number:
  763. //
  764. // | Index | Style | Index | Style |
  765. // +-------+-----------------+-------+-----------------+
  766. // | 0 | None | 10 | darkTrellis |
  767. // | 1 | solid | 11 | lightHorizontal |
  768. // | 2 | mediumGray | 12 | lightVertical |
  769. // | 3 | darkGray | 13 | lightDown |
  770. // | 4 | lightGray | 14 | lightUp |
  771. // | 5 | darkHorizontal | 15 | lightGrid |
  772. // | 6 | darkVertical | 16 | lightTrellis |
  773. // | 7 | darkDown | 17 | gray125 |
  774. // | 8 | darkUp | 18 | gray0625 |
  775. // | 9 | darkGrid | | |
  776. //
  777. // The following the type of horizontal alignment in cells:
  778. //
  779. // | Style |
  780. // +------------------+
  781. // | left |
  782. // | center |
  783. // | right |
  784. // | fill |
  785. // | justify |
  786. // | centerContinuous |
  787. // | distributed |
  788. //
  789. // The following the type of vertical alignment in cells:
  790. //
  791. // | Style |
  792. // +------------------+
  793. // | top |
  794. // | center |
  795. // | justify |
  796. // | distributed |
  797. //
  798. // The following the type of font underline style:
  799. //
  800. // | Style |
  801. // +------------------+
  802. // | single |
  803. // | double |
  804. //
  805. // Excel's built-in all languages formats are shown in the following table:
  806. //
  807. // | Index | Format String |
  808. // +-------+----------------------------------------------------+
  809. // | 0 | General |
  810. // | 1 | 0 |
  811. // | 2 | 0.00 |
  812. // | 3 | #,##0 |
  813. // | 4 | #,##0.00 |
  814. // | 5 | ($#,##0_);($#,##0) |
  815. // | 6 | ($#,##0_);[Red]($#,##0) |
  816. // | 7 | ($#,##0.00_);($#,##0.00) |
  817. // | 8 | ($#,##0.00_);[Red]($#,##0.00) |
  818. // | 9 | 0% |
  819. // | 10 | 0.00% |
  820. // | 11 | 0.00E+00 |
  821. // | 12 | # ?/? |
  822. // | 13 | # ??/?? |
  823. // | 14 | m/d/yy |
  824. // | 15 | d-mmm-yy |
  825. // | 16 | d-mmm |
  826. // | 17 | mmm-yy |
  827. // | 18 | h:mm AM/PM |
  828. // | 19 | h:mm:ss AM/PM |
  829. // | 20 | h:mm |
  830. // | 21 | h:mm:ss |
  831. // | 22 | m/d/yy h:mm |
  832. // | ... | ... |
  833. // | 37 | (#,##0_);(#,##0) |
  834. // | 38 | (#,##0_);[Red](#,##0) |
  835. // | 39 | (#,##0.00_);(#,##0.00) |
  836. // | 40 | (#,##0.00_);[Red](#,##0.00) |
  837. // | 41 | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
  838. // | 42 | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) |
  839. // | 43 | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
  840. // | 44 | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) |
  841. // | 45 | mm:ss |
  842. // | 46 | [h]:mm:ss |
  843. // | 47 | mm:ss.0 |
  844. // | 48 | ##0.0E+0 |
  845. // | 49 | @ |
  846. //
  847. // Excelize built-in currency formats are shown in the following table, only
  848. // support these types in the following table (Index number is used only for
  849. // markup and is not used inside an Excel file and you can't get formatted value
  850. // by the function GetCellValue) currently:
  851. //
  852. // | Index | Symbol |
  853. // +-------+---------------------------------------------------------------+
  854. // | 164 | CN¥ |
  855. // | 165 | $ English (China) |
  856. // | 166 | $ Cherokee (United States) |
  857. // | 167 | $ Chinese (Singapore) |
  858. // | 168 | $ Chinese (Taiwan) |
  859. // | 169 | $ English (Australia) |
  860. // | 170 | $ English (Belize) |
  861. // | 171 | $ English (Canada) |
  862. // | 172 | $ English (Jamaica) |
  863. // | 173 | $ English (New Zealand) |
  864. // | 174 | $ English (Singapore) |
  865. // | 175 | $ English (Trinidad & Tobago) |
  866. // | 176 | $ English (U.S. Vigin Islands) |
  867. // | 177 | $ English (United States) |
  868. // | 178 | $ French (Canada) |
  869. // | 179 | $ Hawaiian (United States) |
  870. // | 180 | $ Malay (Brunei) |
  871. // | 181 | $ Quechua (Ecuador) |
  872. // | 182 | $ Spanish (Chile) |
  873. // | 183 | $ Spanish (Colombia) |
  874. // | 184 | $ Spanish (Ecuador) |
  875. // | 185 | $ Spanish (El Salvador) |
  876. // | 186 | $ Spanish (Mexico) |
  877. // | 187 | $ Spanish (Puerto Rico) |
  878. // | 188 | $ Spanish (United States) |
  879. // | 189 | $ Spanish (Uruguay) |
  880. // | 190 | £ English (United Kingdom) |
  881. // | 191 | £ Scottish Gaelic (United Kingdom) |
  882. // | 192 | £ Welsh (United Kindom) |
  883. // | 193 | ¥ Chinese (China) |
  884. // | 194 | ¥ Japanese (Japan) |
  885. // | 195 | ¥ Sichuan Yi (China) |
  886. // | 196 | ¥ Tibetan (China) |
  887. // | 197 | ¥ Uyghur (China) |
  888. // | 198 | ֏ Armenian (Armenia) |
  889. // | 199 | ؋ Pashto (Afghanistan) |
  890. // | 200 | ؋ Persian (Afghanistan) |
  891. // | 201 | ৳ Bengali (Bangladesh) |
  892. // | 202 | ៛ Khmer (Cambodia) |
  893. // | 203 | ₡ Spanish (Costa Rica) |
  894. // | 204 | ₦ Hausa (Nigeria) |
  895. // | 205 | ₦ Igbo (Nigeria) |
  896. // | 206 | ₦ Yoruba (Nigeria) |
  897. // | 207 | ₩ Korean (South Korea) |
  898. // | 208 | ₪ Hebrew (Israel) |
  899. // | 209 | ₫ Vietnamese (Vietnam) |
  900. // | 210 | € Basque (Spain) |
  901. // | 211 | € Breton (France) |
  902. // | 212 | € Catalan (Spain) |
  903. // | 213 | € Corsican (France) |
  904. // | 214 | € Dutch (Belgium) |
  905. // | 215 | € Dutch (Netherlands) |
  906. // | 216 | € English (Ireland) |
  907. // | 217 | € Estonian (Estonia) |
  908. // | 218 | € Euro (€ 123) |
  909. // | 219 | € Euro (123 €) |
  910. // | 220 | € Finnish (Finland) |
  911. // | 221 | € French (Belgium) |
  912. // | 222 | € French (France) |
  913. // | 223 | € French (Luxembourg) |
  914. // | 224 | € French (Monaco) |
  915. // | 225 | € French (Réunion) |
  916. // | 226 | € Galician (Spain) |
  917. // | 227 | € German (Austria) |
  918. // | 228 | € German (Luxembourg) |
  919. // | 229 | € Greek (Greece) |
  920. // | 230 | € Inari Sami (Finland) |
  921. // | 231 | € Irish (Ireland) |
  922. // | 232 | € Italian (Italy) |
  923. // | 233 | € Latin (Italy) |
  924. // | 234 | € Latin, Serbian (Montenegro) |
  925. // | 235 | € Larvian (Latvia) |
  926. // | 236 | € Lithuanian (Lithuania) |
  927. // | 237 | € Lower Sorbian (Germany) |
  928. // | 238 | € Luxembourgish (Luxembourg) |
  929. // | 239 | € Maltese (Malta) |
  930. // | 240 | € Northern Sami (Finland) |
  931. // | 241 | € Occitan (France) |
  932. // | 242 | € Portuguese (Portugal) |
  933. // | 243 | € Serbian (Montenegro) |
  934. // | 244 | € Skolt Sami (Finland) |
  935. // | 245 | € Slovak (Slovakia) |
  936. // | 246 | € Slovenian (Slovenia) |
  937. // | 247 | € Spanish (Spain) |
  938. // | 248 | € Swedish (Finland) |
  939. // | 249 | € Swiss German (France) |
  940. // | 250 | € Upper Sorbian (Germany) |
  941. // | 251 | € Western Frisian (Netherlands) |
  942. // | 252 | ₭ Lao (Laos) |
  943. // | 253 | ₮ Mongolian (Mongolia) |
  944. // | 254 | ₮ Mongolian, Mongolian (Mongolia) |
  945. // | 255 | ₱ English (Philippines) |
  946. // | 256 | ₱ Filipino (Philippines) |
  947. // | 257 | ₴ Ukrainian (Ukraine) |
  948. // | 258 | ₸ Kazakh (Kazakhstan) |
  949. // | 259 | ₹ Arabic, Kashmiri (India) |
  950. // | 260 | ₹ English (India) |
  951. // | 261 | ₹ Gujarati (India) |
  952. // | 262 | ₹ Hindi (India) |
  953. // | 263 | ₹ Kannada (India) |
  954. // | 264 | ₹ Kashmiri (India) |
  955. // | 265 | ₹ Konkani (India) |
  956. // | 266 | ₹ Manipuri (India) |
  957. // | 267 | ₹ Marathi (India) |
  958. // | 268 | ₹ Nepali (India) |
  959. // | 269 | ₹ Oriya (India) |
  960. // | 270 | ₹ Punjabi (India) |
  961. // | 271 | ₹ Sanskrit (India) |
  962. // | 272 | ₹ Sindhi (India) |
  963. // | 273 | ₹ Tamil (India) |
  964. // | 274 | ₹ Urdu (India) |
  965. // | 275 | ₺ Turkish (Turkey) |
  966. // | 276 | ₼ Azerbaijani (Azerbaijan) |
  967. // | 277 | ₼ Cyrillic, Azerbaijani (Azerbaijan) |
  968. // | 278 | ₽ Russian (Russia) |
  969. // | 279 | ₽ Sakha (Russia) |
  970. // | 280 | ₾ Georgian (Georgia) |
  971. // | 281 | B/. Spanish (Panama) |
  972. // | 282 | Br Oromo (Ethiopia) |
  973. // | 283 | Br Somali (Ethiopia) |
  974. // | 284 | Br Tigrinya (Ethiopia) |
  975. // | 285 | Bs Quechua (Bolivia) |
  976. // | 286 | Bs Spanish (Bolivia) |
  977. // | 287 | BS. Spanish (Venezuela) |
  978. // | 288 | BWP Tswana (Botswana) |
  979. // | 289 | C$ Spanish (Nicaragua) |
  980. // | 290 | CA$ Latin, Inuktitut (Canada) |
  981. // | 291 | CA$ Mohawk (Canada) |
  982. // | 292 | CA$ Unified Canadian Aboriginal Syllabics, Inuktitut (Canada) |
  983. // | 293 | CFA French (Mali) |
  984. // | 294 | CFA French (Senegal) |
  985. // | 295 | CFA Fulah (Senegal) |
  986. // | 296 | CFA Wolof (Senegal) |
  987. // | 297 | CHF French (Switzerland) |
  988. // | 298 | CHF German (Liechtenstein) |
  989. // | 299 | CHF German (Switzerland) |
  990. // | 300 | CHF Italian (Switzerland) |
  991. // | 301 | CHF Romansh (Switzerland) |
  992. // | 302 | CLP Mapuche (Chile) |
  993. // | 303 | CN¥ Mongolian, Mongolian (China) |
  994. // | 304 | DZD Central Atlas Tamazight (Algeria) |
  995. // | 305 | FCFA French (Cameroon) |
  996. // | 306 | Ft Hungarian (Hungary) |
  997. // | 307 | G French (Haiti) |
  998. // | 308 | Gs. Spanish (Paraguay) |
  999. // | 309 | GTQ K'iche' (Guatemala) |
  1000. // | 310 | HK$ Chinese (Hong Kong (China)) |
  1001. // | 311 | HK$ English (Hong Kong (China)) |
  1002. // | 312 | HRK Croatian (Croatia) |
  1003. // | 313 | IDR English (Indonesia) |
  1004. // | 314 | IQD Arbic, Central Kurdish (Iraq) |
  1005. // | 315 | ISK Icelandic (Iceland) |
  1006. // | 316 | K Burmese (Myanmar (Burma)) |
  1007. // | 317 | Kč Czech (Czech Republic) |
  1008. // | 318 | KM Bosnian (Bosnia & Herzegovina) |
  1009. // | 319 | KM Croatian (Bosnia & Herzegovina) |
  1010. // | 320 | KM Latin, Serbian (Bosnia & Herzegovina) |
  1011. // | 321 | kr Faroese (Faroe Islands) |
  1012. // | 322 | kr Northern Sami (Norway) |
  1013. // | 323 | kr Northern Sami (Sweden) |
  1014. // | 324 | kr Norwegian Bokmål (Norway) |
  1015. // | 325 | kr Norwegian Nynorsk (Norway) |
  1016. // | 326 | kr Swedish (Sweden) |
  1017. // | 327 | kr. Danish (Denmark) |
  1018. // | 328 | kr. Kalaallisut (Greenland) |
  1019. // | 329 | Ksh Swahili (kenya) |
  1020. // | 330 | L Romanian (Moldova) |
  1021. // | 331 | L Russian (Moldova) |
  1022. // | 332 | L Spanish (Honduras) |
  1023. // | 333 | Lekë Albanian (Albania) |
  1024. // | 334 | MAD Arabic, Central Atlas Tamazight (Morocco) |
  1025. // | 335 | MAD French (Morocco) |
  1026. // | 336 | MAD Tifinagh, Central Atlas Tamazight (Morocco) |
  1027. // | 337 | MOP$ Chinese (Macau (China)) |
  1028. // | 338 | MVR Divehi (Maldives) |
  1029. // | 339 | Nfk Tigrinya (Eritrea) |
  1030. // | 340 | NGN Bini (Nigeria) |
  1031. // | 341 | NGN Fulah (Nigeria) |
  1032. // | 342 | NGN Ibibio (Nigeria) |
  1033. // | 343 | NGN Kanuri (Nigeria) |
  1034. // | 344 | NOK Lule Sami (Norway) |
  1035. // | 345 | NOK Southern Sami (Norway) |
  1036. // | 346 | NZ$ Maori (New Zealand) |
  1037. // | 347 | PKR Sindhi (Pakistan) |
  1038. // | 348 | PYG Guarani (Paraguay) |
  1039. // | 349 | Q Spanish (Guatemala) |
  1040. // | 350 | R Afrikaans (South Africa) |
  1041. // | 351 | R English (South Africa) |
  1042. // | 352 | R Zulu (South Africa) |
  1043. // | 353 | R$ Portuguese (Brazil) |
  1044. // | 354 | RD$ Spanish (Dominican Republic) |
  1045. // | 355 | RF Kinyarwanda (Rwanda) |
  1046. // | 356 | RM English (Malaysia) |
  1047. // | 357 | RM Malay (Malaysia) |
  1048. // | 358 | RON Romanian (Romania) |
  1049. // | 359 | Rp Indonesoan (Indonesia) |
  1050. // | 360 | Rs Urdu (Pakistan) |
  1051. // | 361 | Rs. Tamil (Sri Lanka) |
  1052. // | 362 | RSD Latin, Serbian (Serbia) |
  1053. // | 363 | RSD Serbian (Serbia) |
  1054. // | 364 | RUB Bashkir (Russia) |
  1055. // | 365 | RUB Tatar (Russia) |
  1056. // | 366 | S/. Quechua (Peru) |
  1057. // | 367 | S/. Spanish (Peru) |
  1058. // | 368 | SEK Lule Sami (Sweden) |
  1059. // | 369 | SEK Southern Sami (Sweden) |
  1060. // | 370 | soʻm Latin, Uzbek (Uzbekistan) |
  1061. // | 371 | soʻm Uzbek (Uzbekistan) |
  1062. // | 372 | SYP Syriac (Syria) |
  1063. // | 373 | THB Thai (Thailand) |
  1064. // | 374 | TMT Turkmen (Turkmenistan) |
  1065. // | 375 | US$ English (Zimbabwe) |
  1066. // | 376 | ZAR Northern Sotho (South Africa) |
  1067. // | 377 | ZAR Southern Sotho (South Africa) |
  1068. // | 378 | ZAR Tsonga (South Africa) |
  1069. // | 379 | ZAR Tswana (south Africa) |
  1070. // | 380 | ZAR Venda (South Africa) |
  1071. // | 381 | ZAR Xhosa (South Africa) |
  1072. // | 382 | zł Polish (Poland) |
  1073. // | 383 | ден Macedonian (Macedonia) |
  1074. // | 384 | KM Cyrillic, Bosnian (Bosnia & Herzegovina) |
  1075. // | 385 | KM Serbian (Bosnia & Herzegovina) |
  1076. // | 386 | лв. Bulgarian (Bulgaria) |
  1077. // | 387 | p. Belarusian (Belarus) |
  1078. // | 388 | сом Kyrgyz (Kyrgyzstan) |
  1079. // | 389 | сом Tajik (Tajikistan) |
  1080. // | 390 | ج.م. Arabic (Egypt) |
  1081. // | 391 | د.أ. Arabic (Jordan) |
  1082. // | 392 | د.أ. Arabic (United Arab Emirates) |
  1083. // | 393 | د.ب. Arabic (Bahrain) |
  1084. // | 394 | د.ت. Arabic (Tunisia) |
  1085. // | 395 | د.ج. Arabic (Algeria) |
  1086. // | 396 | د.ع. Arabic (Iraq) |
  1087. // | 397 | د.ك. Arabic (Kuwait) |
  1088. // | 398 | د.ل. Arabic (Libya) |
  1089. // | 399 | د.م. Arabic (Morocco) |
  1090. // | 400 | ر Punjabi (Pakistan) |
  1091. // | 401 | ر.س. Arabic (Saudi Arabia) |
  1092. // | 402 | ر.ع. Arabic (Oman) |
  1093. // | 403 | ر.ق. Arabic (Qatar) |
  1094. // | 404 | ر.ي. Arabic (Yemen) |
  1095. // | 405 | ریال Persian (Iran) |
  1096. // | 406 | ل.س. Arabic (Syria) |
  1097. // | 407 | ل.ل. Arabic (Lebanon) |
  1098. // | 408 | ብር Amharic (Ethiopia) |
  1099. // | 409 | रू Nepaol (Nepal) |
  1100. // | 410 | රු. Sinhala (Sri Lanka) |
  1101. // | 411 | ADP |
  1102. // | 412 | AED |
  1103. // | 413 | AFA |
  1104. // | 414 | AFN |
  1105. // | 415 | ALL |
  1106. // | 416 | AMD |
  1107. // | 417 | ANG |
  1108. // | 418 | AOA |
  1109. // | 419 | ARS |
  1110. // | 420 | ATS |
  1111. // | 421 | AUD |
  1112. // | 422 | AWG |
  1113. // | 423 | AZM |
  1114. // | 424 | AZN |
  1115. // | 425 | BAM |
  1116. // | 426 | BBD |
  1117. // | ... | ... |
  1118. //
  1119. func (f *File) NewStyle(style string) (int, error) {
  1120. var cellXfsID int
  1121. styleSheet := f.stylesReader()
  1122. formatCellStyle, err := parseFormatStyleSet(style)
  1123. if err != nil {
  1124. return cellXfsID, err
  1125. }
  1126. numFmtID := setNumFmt(styleSheet, formatCellStyle)
  1127. fontID := setFont(styleSheet, formatCellStyle)
  1128. borderID := setBorders(styleSheet, formatCellStyle)
  1129. fillID := setFills(styleSheet, formatCellStyle)
  1130. applyAlignment, alignment := setAlignment(styleSheet, formatCellStyle)
  1131. cellXfsID = setCellXfs(styleSheet, fontID, numFmtID, fillID, borderID, applyAlignment, alignment)
  1132. return cellXfsID, nil
  1133. }
  1134. // setFont provides function to add font style by given cell format settings.
  1135. func setFont(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1136. if formatCellStyle.Font == nil {
  1137. return 0
  1138. }
  1139. fontUnderlineType := map[string]string{"single": "single", "double": "double"}
  1140. if formatCellStyle.Font.Family == "" {
  1141. formatCellStyle.Font.Family = "Calibri"
  1142. }
  1143. if formatCellStyle.Font.Size < 1 {
  1144. formatCellStyle.Font.Size = 11
  1145. }
  1146. if formatCellStyle.Font.Color == "" {
  1147. formatCellStyle.Font.Color = "#000000"
  1148. }
  1149. f := font{
  1150. B: formatCellStyle.Font.Bold,
  1151. I: formatCellStyle.Font.Italic,
  1152. Sz: &attrValInt{Val: formatCellStyle.Font.Size},
  1153. Color: &xlsxColor{RGB: getPaletteColor(formatCellStyle.Font.Color)},
  1154. Name: &attrValString{Val: formatCellStyle.Font.Family},
  1155. Family: &attrValInt{Val: 2},
  1156. Scheme: &attrValString{Val: "minor"},
  1157. }
  1158. val, ok := fontUnderlineType[formatCellStyle.Font.Underline]
  1159. if ok {
  1160. f.U = &attrValString{Val: val}
  1161. }
  1162. font, _ := xml.Marshal(f)
  1163. style.Fonts.Count++
  1164. style.Fonts.Font = append(style.Fonts.Font, &xlsxFont{
  1165. Font: string(font[6 : len(font)-7]),
  1166. })
  1167. return style.Fonts.Count - 1
  1168. }
  1169. // setNumFmt provides function to check if number format code in the range of
  1170. // built-in values.
  1171. func setNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1172. dp := "0."
  1173. numFmtID := 164 // Default custom number format code from 164.
  1174. if formatCellStyle.DecimalPlaces < 0 || formatCellStyle.DecimalPlaces > 30 {
  1175. formatCellStyle.DecimalPlaces = 2
  1176. }
  1177. for i := 0; i < formatCellStyle.DecimalPlaces; i++ {
  1178. dp += "0"
  1179. }
  1180. _, ok := builtInNumFmt[formatCellStyle.NumFmt]
  1181. if !ok {
  1182. fc, currency := currencyNumFmt[formatCellStyle.NumFmt]
  1183. if !currency {
  1184. return setLangNumFmt(style, formatCellStyle)
  1185. }
  1186. fc = strings.Replace(fc, "0.00", dp, -1)
  1187. if formatCellStyle.NegRed {
  1188. fc = fc + ";[Red]" + fc
  1189. }
  1190. if style.NumFmts != nil {
  1191. numFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1
  1192. nf := xlsxNumFmt{
  1193. FormatCode: fc,
  1194. NumFmtID: numFmtID,
  1195. }
  1196. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1197. style.NumFmts.Count++
  1198. } else {
  1199. nf := xlsxNumFmt{
  1200. FormatCode: fc,
  1201. NumFmtID: numFmtID,
  1202. }
  1203. numFmts := xlsxNumFmts{
  1204. NumFmt: []*xlsxNumFmt{&nf},
  1205. Count: 1,
  1206. }
  1207. style.NumFmts = &numFmts
  1208. }
  1209. return numFmtID
  1210. }
  1211. return formatCellStyle.NumFmt
  1212. }
  1213. // setLangNumFmt provides function to set number format code with language.
  1214. func setLangNumFmt(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1215. numFmts, ok := langNumFmt[formatCellStyle.Lang]
  1216. if !ok {
  1217. return 0
  1218. }
  1219. var fc string
  1220. fc, ok = numFmts[formatCellStyle.NumFmt]
  1221. if !ok {
  1222. return 0
  1223. }
  1224. nf := xlsxNumFmt{
  1225. FormatCode: fc,
  1226. NumFmtID: formatCellStyle.NumFmt,
  1227. }
  1228. if style.NumFmts != nil {
  1229. style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf)
  1230. style.NumFmts.Count++
  1231. } else {
  1232. numFmts := xlsxNumFmts{
  1233. NumFmt: []*xlsxNumFmt{&nf},
  1234. Count: 1,
  1235. }
  1236. style.NumFmts = &numFmts
  1237. }
  1238. return formatCellStyle.NumFmt
  1239. }
  1240. // setFills provides function to add fill elements in the styles.xml by given
  1241. // cell format settings.
  1242. func setFills(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1243. var patterns = []string{
  1244. "none",
  1245. "solid",
  1246. "mediumGray",
  1247. "darkGray",
  1248. "lightGray",
  1249. "darkHorizontal",
  1250. "darkVertical",
  1251. "darkDown",
  1252. "darkUp",
  1253. "darkGrid",
  1254. "darkTrellis",
  1255. "lightHorizontal",
  1256. "lightVertical",
  1257. "lightDown",
  1258. "lightUp",
  1259. "lightGrid",
  1260. "lightTrellis",
  1261. "gray125",
  1262. "gray0625",
  1263. }
  1264. var variants = []float64{
  1265. 90,
  1266. 0,
  1267. 45,
  1268. 135,
  1269. }
  1270. var fill xlsxFill
  1271. switch formatCellStyle.Fill.Type {
  1272. case "gradient":
  1273. if len(formatCellStyle.Fill.Color) != 2 {
  1274. break
  1275. }
  1276. var gradient xlsxGradientFill
  1277. switch formatCellStyle.Fill.Shading {
  1278. case 0, 1, 2, 3:
  1279. gradient.Degree = variants[formatCellStyle.Fill.Shading]
  1280. case 4:
  1281. gradient.Type = "path"
  1282. case 5:
  1283. gradient.Type = "path"
  1284. gradient.Bottom = 0.5
  1285. gradient.Left = 0.5
  1286. gradient.Right = 0.5
  1287. gradient.Top = 0.5
  1288. default:
  1289. break
  1290. }
  1291. var stops []*xlsxGradientFillStop
  1292. for index, color := range formatCellStyle.Fill.Color {
  1293. var stop xlsxGradientFillStop
  1294. stop.Position = float64(index)
  1295. stop.Color.RGB = getPaletteColor(color)
  1296. stops = append(stops, &stop)
  1297. }
  1298. gradient.Stop = stops
  1299. fill.GradientFill = &gradient
  1300. case "pattern":
  1301. if formatCellStyle.Fill.Pattern > 18 || formatCellStyle.Fill.Pattern < 0 {
  1302. break
  1303. }
  1304. if len(formatCellStyle.Fill.Color) < 1 {
  1305. break
  1306. }
  1307. var pattern xlsxPatternFill
  1308. pattern.PatternType = patterns[formatCellStyle.Fill.Pattern]
  1309. pattern.FgColor.RGB = getPaletteColor(formatCellStyle.Fill.Color[0])
  1310. fill.PatternFill = &pattern
  1311. }
  1312. style.Fills.Count++
  1313. style.Fills.Fill = append(style.Fills.Fill, &fill)
  1314. return style.Fills.Count - 1
  1315. }
  1316. // setAlignment provides function to formatting information pertaining to text
  1317. // alignment in cells. There are a variety of choices for how text is aligned
  1318. // both horizontally and vertically, as well as indentation settings, and so on.
  1319. func setAlignment(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) (bool, *xlsxAlignment) {
  1320. if formatCellStyle.Alignment == nil {
  1321. return false, &xlsxAlignment{}
  1322. }
  1323. var alignment = xlsxAlignment{
  1324. Horizontal: formatCellStyle.Alignment.Horizontal,
  1325. Indent: formatCellStyle.Alignment.Indent,
  1326. JustifyLastLine: formatCellStyle.Alignment.JustifyLastLine,
  1327. ReadingOrder: formatCellStyle.Alignment.ReadingOrder,
  1328. RelativeIndent: formatCellStyle.Alignment.RelativeIndent,
  1329. ShrinkToFit: formatCellStyle.Alignment.ShrinkToFit,
  1330. TextRotation: formatCellStyle.Alignment.TextRotation,
  1331. Vertical: formatCellStyle.Alignment.Vertical,
  1332. WrapText: formatCellStyle.Alignment.WrapText,
  1333. }
  1334. return true, &alignment
  1335. }
  1336. // setBorders provides function to add border elements in the styles.xml by
  1337. // given borders format settings.
  1338. func setBorders(style *xlsxStyleSheet, formatCellStyle *formatCellStyle) int {
  1339. var styles = []string{
  1340. "none",
  1341. "thin",
  1342. "medium",
  1343. "dashed",
  1344. "dotted",
  1345. "thick",
  1346. "double",
  1347. "hair",
  1348. "mediumDashed",
  1349. "dashDot",
  1350. "mediumDashDot",
  1351. "dashDotDot",
  1352. "mediumDashDotDot",
  1353. "slantDashDot",
  1354. }
  1355. var border xlsxBorder
  1356. for _, v := range formatCellStyle.Border {
  1357. if v.Style > 13 || v.Style < 0 {
  1358. continue
  1359. }
  1360. var color xlsxColor
  1361. color.RGB = getPaletteColor(v.Color)
  1362. switch v.Type {
  1363. case "left":
  1364. border.Left.Style = styles[v.Style]
  1365. border.Left.Color = &color
  1366. case "right":
  1367. border.Right.Style = styles[v.Style]
  1368. border.Right.Color = &color
  1369. case "top":
  1370. border.Top.Style = styles[v.Style]
  1371. border.Top.Color = &color
  1372. case "bottom":
  1373. border.Bottom.Style = styles[v.Style]
  1374. border.Bottom.Color = &color
  1375. case "diagonalUp":
  1376. border.Diagonal.Style = styles[v.Style]
  1377. border.Diagonal.Color = &color
  1378. border.DiagonalUp = true
  1379. case "diagonalDown":
  1380. border.Diagonal.Style = styles[v.Style]
  1381. border.Diagonal.Color = &color
  1382. border.DiagonalDown = true
  1383. }
  1384. }
  1385. style.Borders.Count++
  1386. style.Borders.Border = append(style.Borders.Border, &border)
  1387. return style.Borders.Count - 1
  1388. }
  1389. // setCellXfs provides function to set describes all of the formatting for a
  1390. // cell.
  1391. func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment bool, alignment *xlsxAlignment) int {
  1392. var xf xlsxXf
  1393. xf.FontID = fontID
  1394. if fontID != 0 {
  1395. xf.ApplyFont = true
  1396. }
  1397. xf.NumFmtID = numFmtID
  1398. if numFmtID != 0 {
  1399. xf.ApplyNumberFormat = true
  1400. }
  1401. xf.FillID = fillID
  1402. xf.BorderID = borderID
  1403. style.CellXfs.Count++
  1404. xf.Alignment = alignment
  1405. xf.ApplyAlignment = applyAlignment
  1406. style.CellXfs.Xf = append(style.CellXfs.Xf, xf)
  1407. return style.CellXfs.Count - 1
  1408. }
  1409. // SetCellStyle provides function to add style attribute for cells by given
  1410. // worksheet sheet index, coordinate area and style ID. Note that diagonalDown
  1411. // and diagonalUp type border should be use same color in the same coordinate
  1412. // area.
  1413. //
  1414. // For example create a borders of cell H9 on Sheet1:
  1415. //
  1416. // 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}]}`)
  1417. // if err != nil {
  1418. // fmt.Println(err)
  1419. // }
  1420. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1421. //
  1422. // Set gradient fill with vertical variants shading styles for cell H9 on
  1423. // Sheet1:
  1424. //
  1425. // style, err := xlsx.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
  1426. // if err != nil {
  1427. // fmt.Println(err)
  1428. // }
  1429. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1430. //
  1431. // Set solid style pattern fill for cell H9 on Sheet1:
  1432. //
  1433. // style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
  1434. // if err != nil {
  1435. // fmt.Println(err)
  1436. // }
  1437. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1438. //
  1439. // Set alignment style for cell H9 on Sheet1:
  1440. //
  1441. // 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}}`)
  1442. // if err != nil {
  1443. // fmt.Println(err)
  1444. // }
  1445. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1446. //
  1447. // Dates and times in Excel are represented by real numbers, for example "Apr 7
  1448. // 2017 12:00 PM" is represented by the number 42920.5. Set date and time format
  1449. // for cell H9 on Sheet1:
  1450. //
  1451. // xlsx.SetCellValue("Sheet1", "H9", 42920.5)
  1452. // style, err := xlsx.NewStyle(`{"number_format": 22}`)
  1453. // if err != nil {
  1454. // fmt.Println(err)
  1455. // }
  1456. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1457. //
  1458. // Set font style for cell H9 on Sheet1:
  1459. //
  1460. // style, err := xlsx.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`)
  1461. // if err != nil {
  1462. // fmt.Println(err)
  1463. // }
  1464. // xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
  1465. //
  1466. func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
  1467. hcell = strings.ToUpper(hcell)
  1468. vcell = strings.ToUpper(vcell)
  1469. // Coordinate conversion, convert C1:B3 to 2,0,1,2.
  1470. hcol := string(strings.Map(letterOnlyMapF, hcell))
  1471. hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell))
  1472. hyAxis := hrow - 1
  1473. hxAxis := TitleToNumber(hcol)
  1474. vcol := string(strings.Map(letterOnlyMapF, vcell))
  1475. vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell))
  1476. vyAxis := vrow - 1
  1477. vxAxis := TitleToNumber(vcol)
  1478. if vxAxis < hxAxis {
  1479. hcell, vcell = vcell, hcell
  1480. vxAxis, hxAxis = hxAxis, vxAxis
  1481. }
  1482. if vyAxis < hyAxis {
  1483. hcell, vcell = vcell, hcell
  1484. vyAxis, hyAxis = hyAxis, vyAxis
  1485. }
  1486. // Correct the coordinate area, such correct C1:B3 to B1:C3.
  1487. hcell = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1)
  1488. vcell = ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
  1489. xlsx := f.workSheetReader(sheet)
  1490. completeRow(xlsx, vyAxis+1, vxAxis+1)
  1491. completeCol(xlsx, vyAxis+1, vxAxis+1)
  1492. for r, row := range xlsx.SheetData.Row {
  1493. for k, c := range row.C {
  1494. if checkCellInArea(c.R, hcell+":"+vcell) {
  1495. xlsx.SheetData.Row[r].C[k].S = styleID
  1496. }
  1497. }
  1498. }
  1499. }
  1500. // getPaletteColor provides function to convert the RBG color by given string.
  1501. func getPaletteColor(color string) string {
  1502. return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
  1503. }