bf0febb1f1d0e9f30ef521d70c350e880a28b5ed.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. <?php
  2. class PHPExcel_Helper_HTML
  3. {
  4. protected static $colourMap = array(
  5. 'aliceblue' => 'f0f8ff',
  6. 'antiquewhite' => 'faebd7',
  7. 'antiquewhite1' => 'ffefdb',
  8. 'antiquewhite2' => 'eedfcc',
  9. 'antiquewhite3' => 'cdc0b0',
  10. 'antiquewhite4' => '8b8378',
  11. 'aqua' => '00ffff',
  12. 'aquamarine1' => '7fffd4',
  13. 'aquamarine2' => '76eec6',
  14. 'aquamarine4' => '458b74',
  15. 'azure1' => 'f0ffff',
  16. 'azure2' => 'e0eeee',
  17. 'azure3' => 'c1cdcd',
  18. 'azure4' => '838b8b',
  19. 'beige' => 'f5f5dc',
  20. 'bisque1' => 'ffe4c4',
  21. 'bisque2' => 'eed5b7',
  22. 'bisque3' => 'cdb79e',
  23. 'bisque4' => '8b7d6b',
  24. 'black' => '000000',
  25. 'blanchedalmond' => 'ffebcd',
  26. 'blue' => '0000ff',
  27. 'blue1' => '0000ff',
  28. 'blue2' => '0000ee',
  29. 'blue4' => '00008b',
  30. 'blueviolet' => '8a2be2',
  31. 'brown' => 'a52a2a',
  32. 'brown1' => 'ff4040',
  33. 'brown2' => 'ee3b3b',
  34. 'brown3' => 'cd3333',
  35. 'brown4' => '8b2323',
  36. 'burlywood' => 'deb887',
  37. 'burlywood1' => 'ffd39b',
  38. 'burlywood2' => 'eec591',
  39. 'burlywood3' => 'cdaa7d',
  40. 'burlywood4' => '8b7355',
  41. 'cadetblue' => '5f9ea0',
  42. 'cadetblue1' => '98f5ff',
  43. 'cadetblue2' => '8ee5ee',
  44. 'cadetblue3' => '7ac5cd',
  45. 'cadetblue4' => '53868b',
  46. 'chartreuse1' => '7fff00',
  47. 'chartreuse2' => '76ee00',
  48. 'chartreuse3' => '66cd00',
  49. 'chartreuse4' => '458b00',
  50. 'chocolate' => 'd2691e',
  51. 'chocolate1' => 'ff7f24',
  52. 'chocolate2' => 'ee7621',
  53. 'chocolate3' => 'cd661d',
  54. 'coral' => 'ff7f50',
  55. 'coral1' => 'ff7256',
  56. 'coral2' => 'ee6a50',
  57. 'coral3' => 'cd5b45',
  58. 'coral4' => '8b3e2f',
  59. 'cornflowerblue' => '6495ed',
  60. 'cornsilk1' => 'fff8dc',
  61. 'cornsilk2' => 'eee8cd',
  62. 'cornsilk3' => 'cdc8b1',
  63. 'cornsilk4' => '8b8878',
  64. 'cyan1' => '00ffff',
  65. 'cyan2' => '00eeee',
  66. 'cyan3' => '00cdcd',
  67. 'cyan4' => '008b8b',
  68. 'darkgoldenrod' => 'b8860b',
  69. 'darkgoldenrod1' => 'ffb90f',
  70. 'darkgoldenrod2' => 'eead0e',
  71. 'darkgoldenrod3' => 'cd950c',
  72. 'darkgoldenrod4' => '8b6508',
  73. 'darkgreen' => '006400',
  74. 'darkkhaki' => 'bdb76b',
  75. 'darkolivegreen' => '556b2f',
  76. 'darkolivegreen1' => 'caff70',
  77. 'darkolivegreen2' => 'bcee68',
  78. 'darkolivegreen3' => 'a2cd5a',
  79. 'darkolivegreen4' => '6e8b3d',
  80. 'darkorange' => 'ff8c00',
  81. 'darkorange1' => 'ff7f00',
  82. 'darkorange2' => 'ee7600',
  83. 'darkorange3' => 'cd6600',
  84. 'darkorange4' => '8b4500',
  85. 'darkorchid' => '9932cc',
  86. 'darkorchid1' => 'bf3eff',
  87. 'darkorchid2' => 'b23aee',
  88. 'darkorchid3' => '9a32cd',
  89. 'darkorchid4' => '68228b',
  90. 'darksalmon' => 'e9967a',
  91. 'darkseagreen' => '8fbc8f',
  92. 'darkseagreen1' => 'c1ffc1',
  93. 'darkseagreen2' => 'b4eeb4',
  94. 'darkseagreen3' => '9bcd9b',
  95. 'darkseagreen4' => '698b69',
  96. 'darkslateblue' => '483d8b',
  97. 'darkslategray' => '2f4f4f',
  98. 'darkslategray1' => '97ffff',
  99. 'darkslategray2' => '8deeee',
  100. 'darkslategray3' => '79cdcd',
  101. 'darkslategray4' => '528b8b',
  102. 'darkturquoise' => '00ced1',
  103. 'darkviolet' => '9400d3',
  104. 'deeppink1' => 'ff1493',
  105. 'deeppink2' => 'ee1289',
  106. 'deeppink3' => 'cd1076',
  107. 'deeppink4' => '8b0a50',
  108. 'deepskyblue1' => '00bfff',
  109. 'deepskyblue2' => '00b2ee',
  110. 'deepskyblue3' => '009acd',
  111. 'deepskyblue4' => '00688b',
  112. 'dimgray' => '696969',
  113. 'dodgerblue1' => '1e90ff',
  114. 'dodgerblue2' => '1c86ee',
  115. 'dodgerblue3' => '1874cd',
  116. 'dodgerblue4' => '104e8b',
  117. 'firebrick' => 'b22222',
  118. 'firebrick1' => 'ff3030',
  119. 'firebrick2' => 'ee2c2c',
  120. 'firebrick3' => 'cd2626',
  121. 'firebrick4' => '8b1a1a',
  122. 'floralwhite' => 'fffaf0',
  123. 'forestgreen' => '228b22',
  124. 'fuchsia' => 'ff00ff',
  125. 'gainsboro' => 'dcdcdc',
  126. 'ghostwhite' => 'f8f8ff',
  127. 'gold1' => 'ffd700',
  128. 'gold2' => 'eec900',
  129. 'gold3' => 'cdad00',
  130. 'gold4' => '8b7500',
  131. 'goldenrod' => 'daa520',
  132. 'goldenrod1' => 'ffc125',
  133. 'goldenrod2' => 'eeb422',
  134. 'goldenrod3' => 'cd9b1d',
  135. 'goldenrod4' => '8b6914',
  136. 'gray' => 'bebebe',
  137. 'gray1' => '030303',
  138. 'gray10' => '1a1a1a',
  139. 'gray11' => '1c1c1c',
  140. 'gray12' => '1f1f1f',
  141. 'gray13' => '212121',
  142. 'gray14' => '242424',
  143. 'gray15' => '262626',
  144. 'gray16' => '292929',
  145. 'gray17' => '2b2b2b',
  146. 'gray18' => '2e2e2e',
  147. 'gray19' => '303030',
  148. 'gray2' => '050505',
  149. 'gray20' => '333333',
  150. 'gray21' => '363636',
  151. 'gray22' => '383838',
  152. 'gray23' => '3b3b3b',
  153. 'gray24' => '3d3d3d',
  154. 'gray25' => '404040',
  155. 'gray26' => '424242',
  156. 'gray27' => '454545',
  157. 'gray28' => '474747',
  158. 'gray29' => '4a4a4a',
  159. 'gray3' => '080808',
  160. 'gray30' => '4d4d4d',
  161. 'gray31' => '4f4f4f',
  162. 'gray32' => '525252',
  163. 'gray33' => '545454',
  164. 'gray34' => '575757',
  165. 'gray35' => '595959',
  166. 'gray36' => '5c5c5c',
  167. 'gray37' => '5e5e5e',
  168. 'gray38' => '616161',
  169. 'gray39' => '636363',
  170. 'gray4' => '0a0a0a',
  171. 'gray40' => '666666',
  172. 'gray41' => '696969',
  173. 'gray42' => '6b6b6b',
  174. 'gray43' => '6e6e6e',
  175. 'gray44' => '707070',
  176. 'gray45' => '737373',
  177. 'gray46' => '757575',
  178. 'gray47' => '787878',
  179. 'gray48' => '7a7a7a',
  180. 'gray49' => '7d7d7d',
  181. 'gray5' => '0d0d0d',
  182. 'gray50' => '7f7f7f',
  183. 'gray51' => '828282',
  184. 'gray52' => '858585',
  185. 'gray53' => '878787',
  186. 'gray54' => '8a8a8a',
  187. 'gray55' => '8c8c8c',
  188. 'gray56' => '8f8f8f',
  189. 'gray57' => '919191',
  190. 'gray58' => '949494',
  191. 'gray59' => '969696',
  192. 'gray6' => '0f0f0f',
  193. 'gray60' => '999999',
  194. 'gray61' => '9c9c9c',
  195. 'gray62' => '9e9e9e',
  196. 'gray63' => 'a1a1a1',
  197. 'gray64' => 'a3a3a3',
  198. 'gray65' => 'a6a6a6',
  199. 'gray66' => 'a8a8a8',
  200. 'gray67' => 'ababab',
  201. 'gray68' => 'adadad',
  202. 'gray69' => 'b0b0b0',
  203. 'gray7' => '121212',
  204. 'gray70' => 'b3b3b3',
  205. 'gray71' => 'b5b5b5',
  206. 'gray72' => 'b8b8b8',
  207. 'gray73' => 'bababa',
  208. 'gray74' => 'bdbdbd',
  209. 'gray75' => 'bfbfbf',
  210. 'gray76' => 'c2c2c2',
  211. 'gray77' => 'c4c4c4',
  212. 'gray78' => 'c7c7c7',
  213. 'gray79' => 'c9c9c9',
  214. 'gray8' => '141414',
  215. 'gray80' => 'cccccc',
  216. 'gray81' => 'cfcfcf',
  217. 'gray82' => 'd1d1d1',
  218. 'gray83' => 'd4d4d4',
  219. 'gray84' => 'd6d6d6',
  220. 'gray85' => 'd9d9d9',
  221. 'gray86' => 'dbdbdb',
  222. 'gray87' => 'dedede',
  223. 'gray88' => 'e0e0e0',
  224. 'gray89' => 'e3e3e3',
  225. 'gray9' => '171717',
  226. 'gray90' => 'e5e5e5',
  227. 'gray91' => 'e8e8e8',
  228. 'gray92' => 'ebebeb',
  229. 'gray93' => 'ededed',
  230. 'gray94' => 'f0f0f0',
  231. 'gray95' => 'f2f2f2',
  232. 'gray97' => 'f7f7f7',
  233. 'gray98' => 'fafafa',
  234. 'gray99' => 'fcfcfc',
  235. 'green' => '00ff00',
  236. 'green1' => '00ff00',
  237. 'green2' => '00ee00',
  238. 'green3' => '00cd00',
  239. 'green4' => '008b00',
  240. 'greenyellow' => 'adff2f',
  241. 'honeydew1' => 'f0fff0',
  242. 'honeydew2' => 'e0eee0',
  243. 'honeydew3' => 'c1cdc1',
  244. 'honeydew4' => '838b83',
  245. 'hotpink' => 'ff69b4',
  246. 'hotpink1' => 'ff6eb4',
  247. 'hotpink2' => 'ee6aa7',
  248. 'hotpink3' => 'cd6090',
  249. 'hotpink4' => '8b3a62',
  250. 'indianred' => 'cd5c5c',
  251. 'indianred1' => 'ff6a6a',
  252. 'indianred2' => 'ee6363',
  253. 'indianred3' => 'cd5555',
  254. 'indianred4' => '8b3a3a',
  255. 'ivory1' => 'fffff0',
  256. 'ivory2' => 'eeeee0',
  257. 'ivory3' => 'cdcdc1',
  258. 'ivory4' => '8b8b83',
  259. 'khaki' => 'f0e68c',
  260. 'khaki1' => 'fff68f',
  261. 'khaki2' => 'eee685',
  262. 'khaki3' => 'cdc673',
  263. 'khaki4' => '8b864e',
  264. 'lavender' => 'e6e6fa',
  265. 'lavenderblush1' => 'fff0f5',
  266. 'lavenderblush2' => 'eee0e5',
  267. 'lavenderblush3' => 'cdc1c5',
  268. 'lavenderblush4' => '8b8386',
  269. 'lawngreen' => '7cfc00',
  270. 'lemonchiffon1' => 'fffacd',
  271. 'lemonchiffon2' => 'eee9bf',
  272. 'lemonchiffon3' => 'cdc9a5',
  273. 'lemonchiffon4' => '8b8970',
  274. 'light' => 'eedd82',
  275. 'lightblue' => 'add8e6',
  276. 'lightblue1' => 'bfefff',
  277. 'lightblue2' => 'b2dfee',
  278. 'lightblue3' => '9ac0cd',
  279. 'lightblue4' => '68838b',
  280. 'lightcoral' => 'f08080',
  281. 'lightcyan1' => 'e0ffff',
  282. 'lightcyan2' => 'd1eeee',
  283. 'lightcyan3' => 'b4cdcd',
  284. 'lightcyan4' => '7a8b8b',
  285. 'lightgoldenrod1' => 'ffec8b',
  286. 'lightgoldenrod2' => 'eedc82',
  287. 'lightgoldenrod3' => 'cdbe70',
  288. 'lightgoldenrod4' => '8b814c',
  289. 'lightgoldenrodyellow' => 'fafad2',
  290. 'lightgray' => 'd3d3d3',
  291. 'lightpink' => 'ffb6c1',
  292. 'lightpink1' => 'ffaeb9',
  293. 'lightpink2' => 'eea2ad',
  294. 'lightpink3' => 'cd8c95',
  295. 'lightpink4' => '8b5f65',
  296. 'lightsalmon1' => 'ffa07a',
  297. 'lightsalmon2' => 'ee9572',
  298. 'lightsalmon3' => 'cd8162',
  299. 'lightsalmon4' => '8b5742',
  300. 'lightseagreen' => '20b2aa',
  301. 'lightskyblue' => '87cefa',
  302. 'lightskyblue1' => 'b0e2ff',
  303. 'lightskyblue2' => 'a4d3ee',
  304. 'lightskyblue3' => '8db6cd',
  305. 'lightskyblue4' => '607b8b',
  306. 'lightslateblue' => '8470ff',
  307. 'lightslategray' => '778899',
  308. 'lightsteelblue' => 'b0c4de',
  309. 'lightsteelblue1' => 'cae1ff',
  310. 'lightsteelblue2' => 'bcd2ee',
  311. 'lightsteelblue3' => 'a2b5cd',
  312. 'lightsteelblue4' => '6e7b8b',
  313. 'lightyellow1' => 'ffffe0',
  314. 'lightyellow2' => 'eeeed1',
  315. 'lightyellow3' => 'cdcdb4',
  316. 'lightyellow4' => '8b8b7a',
  317. 'lime' => '00ff00',
  318. 'limegreen' => '32cd32',
  319. 'linen' => 'faf0e6',
  320. 'magenta' => 'ff00ff',
  321. 'magenta2' => 'ee00ee',
  322. 'magenta3' => 'cd00cd',
  323. 'magenta4' => '8b008b',
  324. 'maroon' => 'b03060',
  325. 'maroon1' => 'ff34b3',
  326. 'maroon2' => 'ee30a7',
  327. 'maroon3' => 'cd2990',
  328. 'maroon4' => '8b1c62',
  329. 'medium' => '66cdaa',
  330. 'mediumaquamarine' => '66cdaa',
  331. 'mediumblue' => '0000cd',
  332. 'mediumorchid' => 'ba55d3',
  333. 'mediumorchid1' => 'e066ff',
  334. 'mediumorchid2' => 'd15fee',
  335. 'mediumorchid3' => 'b452cd',
  336. 'mediumorchid4' => '7a378b',
  337. 'mediumpurple' => '9370db',
  338. 'mediumpurple1' => 'ab82ff',
  339. 'mediumpurple2' => '9f79ee',
  340. 'mediumpurple3' => '8968cd',
  341. 'mediumpurple4' => '5d478b',
  342. 'mediumseagreen' => '3cb371',
  343. 'mediumslateblue' => '7b68ee',
  344. 'mediumspringgreen' => '00fa9a',
  345. 'mediumturquoise' => '48d1cc',
  346. 'mediumvioletred' => 'c71585',
  347. 'midnightblue' => '191970',
  348. 'mintcream' => 'f5fffa',
  349. 'mistyrose1' => 'ffe4e1',
  350. 'mistyrose2' => 'eed5d2',
  351. 'mistyrose3' => 'cdb7b5',
  352. 'mistyrose4' => '8b7d7b',
  353. 'moccasin' => 'ffe4b5',
  354. 'navajowhite1' => 'ffdead',
  355. 'navajowhite2' => 'eecfa1',
  356. 'navajowhite3' => 'cdb38b',
  357. 'navajowhite4' => '8b795e',
  358. 'navy' => '000080',
  359. 'navyblue' => '000080',
  360. 'oldlace' => 'fdf5e6',
  361. 'olive' => '808000',
  362. 'olivedrab' => '6b8e23',
  363. 'olivedrab1' => 'c0ff3e',
  364. 'olivedrab2' => 'b3ee3a',
  365. 'olivedrab4' => '698b22',
  366. 'orange' => 'ffa500',
  367. 'orange1' => 'ffa500',
  368. 'orange2' => 'ee9a00',
  369. 'orange3' => 'cd8500',
  370. 'orange4' => '8b5a00',
  371. 'orangered1' => 'ff4500',
  372. 'orangered2' => 'ee4000',
  373. 'orangered3' => 'cd3700',
  374. 'orangered4' => '8b2500',
  375. 'orchid' => 'da70d6',
  376. 'orchid1' => 'ff83fa',
  377. 'orchid2' => 'ee7ae9',
  378. 'orchid3' => 'cd69c9',
  379. 'orchid4' => '8b4789',
  380. 'pale' => 'db7093',
  381. 'palegoldenrod' => 'eee8aa',
  382. 'palegreen' => '98fb98',
  383. 'palegreen1' => '9aff9a',
  384. 'palegreen2' => '90ee90',
  385. 'palegreen3' => '7ccd7c',
  386. 'palegreen4' => '548b54',
  387. 'paleturquoise' => 'afeeee',
  388. 'paleturquoise1' => 'bbffff',
  389. 'paleturquoise2' => 'aeeeee',
  390. 'paleturquoise3' => '96cdcd',
  391. 'paleturquoise4' => '668b8b',
  392. 'palevioletred' => 'db7093',
  393. 'palevioletred1' => 'ff82ab',
  394. 'palevioletred2' => 'ee799f',
  395. 'palevioletred3' => 'cd6889',
  396. 'palevioletred4' => '8b475d',
  397. 'papayawhip' => 'ffefd5',
  398. 'peachpuff1' => 'ffdab9',
  399. 'peachpuff2' => 'eecbad',
  400. 'peachpuff3' => 'cdaf95',
  401. 'peachpuff4' => '8b7765',
  402. 'pink' => 'ffc0cb',
  403. 'pink1' => 'ffb5c5',
  404. 'pink2' => 'eea9b8',
  405. 'pink3' => 'cd919e',
  406. 'pink4' => '8b636c',
  407. 'plum' => 'dda0dd',
  408. 'plum1' => 'ffbbff',
  409. 'plum2' => 'eeaeee',
  410. 'plum3' => 'cd96cd',
  411. 'plum4' => '8b668b',
  412. 'powderblue' => 'b0e0e6',
  413. 'purple' => 'a020f0',
  414. 'rebeccapurple' => '663399',
  415. 'purple1' => '9b30ff',
  416. 'purple2' => '912cee',
  417. 'purple3' => '7d26cd',
  418. 'purple4' => '551a8b',
  419. 'red' => 'ff0000',
  420. 'red1' => 'ff0000',
  421. 'red2' => 'ee0000',
  422. 'red3' => 'cd0000',
  423. 'red4' => '8b0000',
  424. 'rosybrown' => 'bc8f8f',
  425. 'rosybrown1' => 'ffc1c1',
  426. 'rosybrown2' => 'eeb4b4',
  427. 'rosybrown3' => 'cd9b9b',
  428. 'rosybrown4' => '8b6969',
  429. 'royalblue' => '4169e1',
  430. 'royalblue1' => '4876ff',
  431. 'royalblue2' => '436eee',
  432. 'royalblue3' => '3a5fcd',
  433. 'royalblue4' => '27408b',
  434. 'saddlebrown' => '8b4513',
  435. 'salmon' => 'fa8072',
  436. 'salmon1' => 'ff8c69',
  437. 'salmon2' => 'ee8262',
  438. 'salmon3' => 'cd7054',
  439. 'salmon4' => '8b4c39',
  440. 'sandybrown' => 'f4a460',
  441. 'seagreen1' => '54ff9f',
  442. 'seagreen2' => '4eee94',
  443. 'seagreen3' => '43cd80',
  444. 'seagreen4' => '2e8b57',
  445. 'seashell1' => 'fff5ee',
  446. 'seashell2' => 'eee5de',
  447. 'seashell3' => 'cdc5bf',
  448. 'seashell4' => '8b8682',
  449. 'sienna' => 'a0522d',
  450. 'sienna1' => 'ff8247',
  451. 'sienna2' => 'ee7942',
  452. 'sienna3' => 'cd6839',
  453. 'sienna4' => '8b4726',
  454. 'silver' => 'c0c0c0',
  455. 'skyblue' => '87ceeb',
  456. 'skyblue1' => '87ceff',
  457. 'skyblue2' => '7ec0ee',
  458. 'skyblue3' => '6ca6cd',
  459. 'skyblue4' => '4a708b',
  460. 'slateblue' => '6a5acd',
  461. 'slateblue1' => '836fff',
  462. 'slateblue2' => '7a67ee',
  463. 'slateblue3' => '6959cd',
  464. 'slateblue4' => '473c8b',
  465. 'slategray' => '708090',
  466. 'slategray1' => 'c6e2ff',
  467. 'slategray2' => 'b9d3ee',
  468. 'slategray3' => '9fb6cd',
  469. 'slategray4' => '6c7b8b',
  470. 'snow1' => 'fffafa',
  471. 'snow2' => 'eee9e9',
  472. 'snow3' => 'cdc9c9',
  473. 'snow4' => '8b8989',
  474. 'springgreen1' => '00ff7f',
  475. 'springgreen2' => '00ee76',
  476. 'springgreen3' => '00cd66',
  477. 'springgreen4' => '008b45',
  478. 'steelblue' => '4682b4',
  479. 'steelblue1' => '63b8ff',
  480. 'steelblue2' => '5cacee',
  481. 'steelblue3' => '4f94cd',
  482. 'steelblue4' => '36648b',
  483. 'tan' => 'd2b48c',
  484. 'tan1' => 'ffa54f',
  485. 'tan2' => 'ee9a49',
  486. 'tan3' => 'cd853f',
  487. 'tan4' => '8b5a2b',
  488. 'teal' => '008080',
  489. 'thistle' => 'd8bfd8',
  490. 'thistle1' => 'ffe1ff',
  491. 'thistle2' => 'eed2ee',
  492. 'thistle3' => 'cdb5cd',
  493. 'thistle4' => '8b7b8b',
  494. 'tomato1' => 'ff6347',
  495. 'tomato2' => 'ee5c42',
  496. 'tomato3' => 'cd4f39',
  497. 'tomato4' => '8b3626',
  498. 'turquoise' => '40e0d0',
  499. 'turquoise1' => '00f5ff',
  500. 'turquoise2' => '00e5ee',
  501. 'turquoise3' => '00c5cd',
  502. 'turquoise4' => '00868b',
  503. 'violet' => 'ee82ee',
  504. 'violetred' => 'd02090',
  505. 'violetred1' => 'ff3e96',
  506. 'violetred2' => 'ee3a8c',
  507. 'violetred3' => 'cd3278',
  508. 'violetred4' => '8b2252',
  509. 'wheat' => 'f5deb3',
  510. 'wheat1' => 'ffe7ba',
  511. 'wheat2' => 'eed8ae',
  512. 'wheat3' => 'cdba96',
  513. 'wheat4' => '8b7e66',
  514. 'white' => 'ffffff',
  515. 'whitesmoke' => 'f5f5f5',
  516. 'yellow' => 'ffff00',
  517. 'yellow1' => 'ffff00',
  518. 'yellow2' => 'eeee00',
  519. 'yellow3' => 'cdcd00',
  520. 'yellow4' => '8b8b00',
  521. 'yellowgreen' => '9acd32',
  522. );
  523. protected $face;
  524. protected $size;
  525. protected $color;
  526. protected $bold = false;
  527. protected $italic = false;
  528. protected $underline = false;
  529. protected $superscript = false;
  530. protected $subscript = false;
  531. protected $strikethrough = false;
  532. protected $startTagCallbacks = array(
  533. 'font' => 'startFontTag',
  534. 'b' => 'startBoldTag',
  535. 'strong' => 'startBoldTag',
  536. 'i' => 'startItalicTag',
  537. 'em' => 'startItalicTag',
  538. 'u' => 'startUnderlineTag',
  539. 'ins' => 'startUnderlineTag',
  540. 'del' => 'startStrikethruTag',
  541. 'sup' => 'startSuperscriptTag',
  542. 'sub' => 'startSubscriptTag',
  543. );
  544. protected $endTagCallbacks = array(
  545. 'font' => 'endFontTag',
  546. 'b' => 'endBoldTag',
  547. 'strong' => 'endBoldTag',
  548. 'i' => 'endItalicTag',
  549. 'em' => 'endItalicTag',
  550. 'u' => 'endUnderlineTag',
  551. 'ins' => 'endUnderlineTag',
  552. 'del' => 'endStrikethruTag',
  553. 'sup' => 'endSuperscriptTag',
  554. 'sub' => 'endSubscriptTag',
  555. 'br' => 'breakTag',
  556. 'p' => 'breakTag',
  557. 'h1' => 'breakTag',
  558. 'h2' => 'breakTag',
  559. 'h3' => 'breakTag',
  560. 'h4' => 'breakTag',
  561. 'h5' => 'breakTag',
  562. 'h6' => 'breakTag',
  563. );
  564. protected $stack = array();
  565. protected $stringData = '';
  566. protected $richTextObject;
  567. protected function initialise() {
  568. $this->face = $this->size = $this->color = null;
  569. $this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false;
  570. $this->stack = array();
  571. $this->stringData = '';
  572. }
  573. public function toRichTextObject($html) {
  574. $this->initialise();
  575. // Create a new DOM object
  576. $dom = new domDocument;
  577. // Load the HTML file into the DOM object
  578. // Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup
  579. $loaded = @$dom->loadHTML($html);
  580. // Discard excess white space
  581. $dom->preserveWhiteSpace = false;
  582. $this->richTextObject = new PHPExcel_RichText();;
  583. $this->parseElements($dom);
  584. return $this->richTextObject;
  585. }
  586. protected function buildTextRun() {
  587. $text = $this->stringData;
  588. if (trim($text) === '')
  589. return;
  590. $richtextRun = $this->richTextObject->createTextRun($this->stringData);
  591. if ($this->face) {
  592. $richtextRun->getFont()->setName($this->face);
  593. }
  594. if ($this->size) {
  595. $richtextRun->getFont()->setSize($this->size);
  596. }
  597. if ($this->color) {
  598. $richtextRun->getFont()->setColor( new PHPExcel_Style_Color( 'ff' . $this->color ) );
  599. }
  600. if ($this->bold) {
  601. $richtextRun->getFont()->setBold(true);
  602. }
  603. if ($this->italic) {
  604. $richtextRun->getFont()->setItalic(true);
  605. }
  606. if ($this->underline) {
  607. $richtextRun->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
  608. }
  609. if ($this->superscript) {
  610. $richtextRun->getFont()->setSuperScript(true);
  611. }
  612. if ($this->subscript) {
  613. $richtextRun->getFont()->setSubScript(true);
  614. }
  615. if ($this->strikethrough) {
  616. $richtextRun->getFont()->setStrikethrough(true);
  617. }
  618. $this->stringData = '';
  619. }
  620. protected function rgbToColour($rgb) {
  621. preg_match_all('/\d+/', $rgb, $values);
  622. foreach($values[0] as &$value) {
  623. $value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
  624. }
  625. return implode($values[0]);
  626. }
  627. protected function colourNameLookup($rgb) {
  628. return self::$colourMap[$rgb];
  629. }
  630. protected function startFontTag($tag) {
  631. foreach ($tag->attributes as $attribute) {
  632. $attributeName = strtolower($attribute->name);
  633. $attributeValue = $attribute->value;
  634. if ($attributeName == 'color') {
  635. if (preg_match('/rgb\s*\(/', $attributeValue)) {
  636. $this->$attributeName = $this->rgbToColour($attributeValue);
  637. } elseif(strpos(trim($attributeValue), '#') === 0) {
  638. $this->$attributeName = ltrim($attributeValue, '#');
  639. } else {
  640. $this->$attributeName = $this->colourNameLookup($attributeValue);
  641. }
  642. } else {
  643. $this->$attributeName = $attributeValue;
  644. }
  645. }
  646. }
  647. protected function endFontTag() {
  648. $this->face = $this->size = $this->color = null;
  649. }
  650. protected function startBoldTag() {
  651. $this->bold = true;
  652. }
  653. protected function endBoldTag() {
  654. $this->bold = false;
  655. }
  656. protected function startItalicTag() {
  657. $this->italic = true;
  658. }
  659. protected function endItalicTag() {
  660. $this->italic = false;
  661. }
  662. protected function startUnderlineTag() {
  663. $this->underline = true;
  664. }
  665. protected function endUnderlineTag() {
  666. $this->underline = false;
  667. }
  668. protected function startSubscriptTag() {
  669. $this->subscript = true;
  670. }
  671. protected function endSubscriptTag() {
  672. $this->subscript = false;
  673. }
  674. protected function startSuperscriptTag() {
  675. $this->superscript = true;
  676. }
  677. protected function endSuperscriptTag() {
  678. $this->superscript = false;
  679. }
  680. protected function startStrikethruTag() {
  681. $this->strikethrough = true;
  682. }
  683. protected function endStrikethruTag() {
  684. $this->strikethrough = false;
  685. }
  686. protected function breakTag() {
  687. $this->stringData .= PHP_EOL;
  688. }
  689. protected function parseTextNode(DOMText $textNode) {
  690. $domText = preg_replace('/\s+/u', ' ', ltrim($textNode->nodeValue));
  691. $this->stringData .= $domText;
  692. $this->buildTextRun();
  693. }
  694. protected function handleCallback($element, $callbackTag, $callbacks) {
  695. if (isset($callbacks[$callbackTag])) {
  696. $elementHandler = $callbacks[$callbackTag];
  697. if (method_exists($this, $elementHandler)) {
  698. call_user_func(array($this, $elementHandler), $element);
  699. }
  700. }
  701. }
  702. protected function parseElementNode(DOMElement $element) {
  703. $callbackTag = strtolower($element->nodeName);
  704. $this->stack[] = $callbackTag;
  705. $this->handleCallback($element, $callbackTag, $this->startTagCallbacks);
  706. $this->parseElements($element);
  707. $this->stringData .= ' ';
  708. array_pop($this->stack);
  709. $this->handleCallback($element, $callbackTag, $this->endTagCallbacks);
  710. }
  711. protected function parseElements(DOMNode $element) {
  712. foreach ($element->childNodes as $child) {
  713. if ($child instanceof DOMText) {
  714. $this->parseTextNode($child);
  715. } elseif ($child instanceof DOMElement) {
  716. $this->parseElementNode($child);
  717. }
  718. }
  719. }
  720. }