excelopput.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  1. function exportSheetExcel(luckysheet, images, name = "file") { // 参数为luckysheet.getluckysheetfile()获取的对象
  2. // 1.创建工作簿,可以为工作簿添加属性
  3. let workbook = new ExcelJS.Workbook();
  4. // 2.创建表格,第二个参数可以配置创建什么样的工作表
  5. luckysheet.every(function(table) {
  6. if (table.data.length === 0) return true;
  7. let worksheet = workbook.addWorksheet(name);
  8. // 3.设置单元格合并,设置单元格边框,设置单元格样式,设置值
  9. setStyleAndValue(table.data, worksheet);
  10. setMerge(table.config.merge, worksheet);
  11. setBorder(table, worksheet);
  12. setImages(table, images, worksheet, workbook);
  13. return true;
  14. })
  15. // 4.写入 buffer
  16. const buffer = workbook.xlsx.writeBuffer()
  17. // 5.保存为文件
  18. buffer.then(function(buf) {
  19. saveFile(buf, name);
  20. uploadExcel(buf,'http://192.168.0.11:8084/api/uploadExcel')
  21. })
  22. }
  23. function uploadExcel(buffer, url) {
  24. const formData = new FormData();
  25. const randomId = GetQueryString('randomid')
  26. formData.append('file', new Blob([buffer], {
  27. type: 'application/octet-stream'
  28. }));
  29. formData.append("randomId", randomId);
  30. $.ajax({
  31. url: url,
  32. type: 'POST',
  33. data: formData,
  34. processData: false, // 告诉jQuery不要处理发送的数据
  35. contentType: false, // 告诉jQuery不要设置Content-Type请求头
  36. success: function(response) {
  37. // 上传成功
  38. console.log('上传成功');
  39. },
  40. error: function(xhr, status, error) {
  41. // 上传失败
  42. console.error('上传失败');
  43. }
  44. })
  45. }
  46. function arrayBufferToBase64(array) {
  47. array = new Uint8Array(array);
  48. var length = array.byteLength;
  49. var table = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  50. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
  51. 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
  52. 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
  53. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
  54. 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  55. 'w', 'x', 'y', 'z', '0', '1', '2', '3',
  56. '4', '5', '6', '7', '8', '9', '+', '/'
  57. ];
  58. var base64Str = '';
  59. for (var i = 0; length - i >= 3; i += 3) {
  60. var num1 = array[i];
  61. var num2 = array[i + 1];
  62. var num3 = array[i + 2];
  63. base64Str += table[num1 >>> 2] +
  64. table[((num1 & 0b11) << 4) | (num2 >>> 4)] +
  65. table[((num2 & 0b1111) << 2) | (num3 >>> 6)] +
  66. table[num3 & 0b111111];
  67. }
  68. var lastByte = length - i;
  69. if (lastByte === 1) {
  70. var lastNum1 = array[i];
  71. base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4)] + '==';
  72. } else if (lastByte === 2) {
  73. var lastNum1 = array[i];
  74. var lastNum2 = array[i + 1];
  75. base64Str += table[lastNum1 >>> 2] +
  76. table[((lastNum1 & 0b11) << 4) | (lastNum2 >>> 4)] +
  77. table[(lastNum2 & 0b1111) << 2] +
  78. '=';
  79. }
  80. return base64Str;
  81. }
  82. var saveFile = function(buf, name) {
  83. let blob = new Blob([buf], {
  84. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
  85. });
  86. const downloadElement = document.createElement('a');
  87. let href = window.URL.createObjectURL(blob);
  88. downloadElement.href = href;
  89. downloadElement.download = name + ".xlsx"; // 文件名字
  90. document.body.appendChild(downloadElement);
  91. downloadElement.click();
  92. document.body.removeChild(downloadElement); // 下载完成移除元素
  93. window.URL.revokeObjectURL(href); // 释放掉blob对象
  94. }
  95. var setMerge = function(luckyMerge = {}, worksheet) {
  96. const mergearr = Object.values(luckyMerge);
  97. mergearr.forEach(function(elem) { // elem格式:{r: 0, c: 0, rs: 1, cs: 2}
  98. // 按开始行,开始列,结束行,结束列合并(相当于 K10:M12)
  99. worksheet.mergeCells(elem.r + 1, elem.c + 1, elem.r + elem.rs, elem.c + elem.cs);
  100. });
  101. }
  102. //获取图片在单元格的位置
  103. var getImagePosition = function(num, arr) {
  104. let index = 0;
  105. let minIndex;
  106. let maxIndex;
  107. for (let i = 0; i < arr.length; i++) {
  108. if (num < arr[i]) {
  109. index = i;
  110. break;
  111. }
  112. }
  113. if (index == 0) {
  114. minIndex = 0;
  115. maxIndex = 1;
  116. return Math.abs((num - 0) / (arr[maxIndex] - arr[minIndex])) + index;
  117. } else if (index == arr.length - 1) {
  118. minIndex = arr.length - 2;
  119. maxIndex = arr.length - 1;
  120. } else {
  121. minIndex = index - 1;
  122. maxIndex = index;
  123. }
  124. let min = arr[minIndex];
  125. let max = arr[maxIndex];
  126. let radio = Math.abs((num - min) / (max - min)) + index
  127. return radio;
  128. }
  129. var setImages = function(table, images, worksheet, workbook) {
  130. let {
  131. visibledatacolumn, //所有行的位置
  132. visibledatarow //所有列的位置
  133. } = {
  134. ...table
  135. }
  136. // if (typeof images != 'object') return;
  137. for (let key in images) {
  138. // 通过 base64 将图像添加到工作簿
  139. let myBase64Image = images[key].src;
  140. //开始行 开始列 结束行 结束列
  141. const item = images[key];
  142. const imageId = workbook.addImage({
  143. base64: myBase64Image,
  144. extension: 'png'
  145. });
  146. //console.log(myBase64Image)
  147. const col_st = getImagePosition(item.default.left, visibledatacolumn);
  148. const row_st = getImagePosition(item.default.top, visibledatarow);
  149. //模式1,图片左侧与luckysheet位置一样,像素比例保持不变,但是,右侧位置可能与原图所在单元格不一致
  150. // worksheet.addImage(imageId, {
  151. // tl: { col: col_st, row: row_st},
  152. // ext: { width: item.default.width, height: item.default.height },
  153. // });
  154. //模式2,图片四个角位置没有变动,但是图片像素比例可能和原图不一样
  155. const w_ed = item.default.left + item.default.width;
  156. const h_ed = item.default.top + item.default.height;
  157. const col_ed = Number(getImagePosition(w_ed, visibledatacolumn).toFixed(0));
  158. const row_ed = Number(getImagePosition(h_ed, visibledatarow).toFixed(0));
  159. let result = `${cellPos(col_st,row_st)}:${cellPos(col_ed,row_ed)}`
  160. // worksheet.addImage(imageId, 'B7:G20');
  161. worksheet.addImage(imageId, result);
  162. }
  163. };
  164. //单元格数字转字母
  165. function cellPos(c, r, n) {
  166. let ordA = 'A'.charCodeAt(0);
  167. let ordZ = 'Z'.charCodeAt(0);
  168. let len = ordZ - ordA + 1;
  169. let s = "";
  170. while (c >= 0) {
  171. s = String.fromCharCode(c % len + ordA) + s;
  172. c = Math.floor(c / len) - 1;
  173. }
  174. if (n) {
  175. return s + (r + 1) + ":" + s + (r + n);
  176. } else {
  177. return s + (r + 1);
  178. }
  179. }
  180. var setBorder = function(lucksheetfile, worksheet) {
  181. if (!lucksheetfile) return;
  182. const luckyToExcel = {
  183. style: {
  184. 0: 'none',
  185. 1: 'thin',
  186. 2: 'hair',
  187. 3: 'dotted',
  188. 4: 'dashDot', // 'Dashed',
  189. 5: 'dashDot',
  190. 6: 'dashDotDot',
  191. 7: 'double',
  192. 8: 'medium',
  193. 9: 'mediumDashed',
  194. 10: 'mediumDashDot',
  195. 11: 'mediumDashDotDot',
  196. 12: 'slantDashDot',
  197. 13: 'thick'
  198. }
  199. }
  200. //获取所有的单元格边框的信息
  201. const borderInfoCompute = getBorderInfo(lucksheetfile);
  202. for (let x in borderInfoCompute) {
  203. let border = {};
  204. let info = borderInfoCompute[x];
  205. let row = parseInt(x.substr(0, x.indexOf('_')));
  206. let column = parseInt(x.substr(x.indexOf('_') + 1));
  207. if (info.t != undefined) {
  208. const tcolor = info.t.color.indexOf('rgb') > -1 ? rgb2hex(info.t.color) : info.t.color;
  209. border['top'] = {
  210. style: luckyToExcel.style[info.t.style],
  211. color: {
  212. argb: tcolor.replace('#', '')
  213. }
  214. };
  215. }
  216. if (info.r != undefined) {
  217. const rcolor = info.r.color.indexOf('rgb') > -1 ? rgb2hex(info.r.color) : info.r.color;
  218. border['right'] = {
  219. style: luckyToExcel.style[info.r.style],
  220. color: {
  221. argb: rcolor.replace('#', '')
  222. }
  223. };
  224. }
  225. if (info.b != undefined) {
  226. const bcolor = info.b.color.indexOf('rgb') > -1 ? rgb2hex(info.b.color) : info.b.color;
  227. border['bottom'] = {
  228. style: luckyToExcel.style[info.b.style],
  229. color: {
  230. argb: bcolor.replace('#', '')
  231. }
  232. };
  233. }
  234. if (info.l != undefined) {
  235. const lcolor = info.l.color.indexOf('rgb') > -1 ? rgb2hex(info.l.color) : info.l.color;
  236. border['left'] = {
  237. style: luckyToExcel.style[info.l.style],
  238. color: {
  239. argb: lcolor.replace('#', '')
  240. }
  241. };
  242. }
  243. worksheet.getCell(row + 1, column + 1).border = border;
  244. }
  245. }
  246. var getBorderInfo = function(luckysheetfile) {
  247. let borderInfoCompute = {};
  248. let cfg = luckysheetfile.config;
  249. let data = luckysheetfile.data;
  250. let borderInfo = cfg["borderInfo"];
  251. //设置需要计算边框的区域
  252. let dataset_row_st = 0,
  253. dataset_row_ed = data.length,
  254. dataset_col_st = 0,
  255. dataset_col_ed = data[0].length;
  256. if (borderInfo != null && borderInfo.length > 0) {
  257. for (let i = 0; i < borderInfo.length; i++) {
  258. let rangeType = borderInfo[i].rangeType;
  259. if (rangeType == "range") {
  260. let borderType = borderInfo[i].borderType;
  261. let borderColor = borderInfo[i].color;
  262. let borderStyle = borderInfo[i].style;
  263. let borderRange = borderInfo[i].range;
  264. for (let j = 0; j < borderRange.length; j++) {
  265. let bd_r1 = borderRange[j].row[0],
  266. bd_r2 = borderRange[j].row[1];
  267. let bd_c1 = borderRange[j].column[0],
  268. bd_c2 = borderRange[j].column[1];
  269. if (bd_r1 < dataset_row_st) {
  270. bd_r1 = dataset_row_st;
  271. }
  272. if (bd_r2 > dataset_row_ed) {
  273. bd_r2 = dataset_row_ed;
  274. }
  275. if (bd_c1 < dataset_col_st) {
  276. bd_c1 = dataset_col_st;
  277. }
  278. if (bd_c2 > dataset_col_ed) {
  279. bd_c2 = dataset_col_ed;
  280. }
  281. if (borderType == "border-left") {
  282. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  283. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  284. continue;
  285. }
  286. if (borderInfoCompute[bd_r + "_" + bd_c1] == null) {
  287. borderInfoCompute[bd_r + "_" + bd_c1] = {};
  288. }
  289. borderInfoCompute[bd_r + "_" + bd_c1].l = {
  290. "color": borderColor,
  291. "style": borderStyle
  292. };
  293. let bd_c_left = bd_c1 - 1;
  294. if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
  295. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[
  296. bd_r][bd_c_left].mc != null) {
  297. let cell_left = data[bd_r][bd_c_left];
  298. let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  299. if (mc.c + mc.cs - 1 == bd_c_left) {
  300. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  301. "color": borderColor,
  302. "style": borderStyle
  303. };
  304. }
  305. } else {
  306. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  307. "color": borderColor,
  308. "style": borderStyle
  309. };
  310. }
  311. }
  312. let mc = cfg["merge"] || {};
  313. for (const key in mc) {
  314. let {
  315. c,
  316. r,
  317. cs,
  318. rs
  319. } = mc[key];
  320. if (bd_c1 <= c + cs - 1 && bd_c1 > c && bd_r >= r && bd_r <= r + rs - 1) {
  321. borderInfoCompute[bd_r + "_" + bd_c1].l = null;
  322. }
  323. }
  324. }
  325. } else if (borderType == "border-right") {
  326. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  327. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  328. continue;
  329. }
  330. if (borderInfoCompute[bd_r + "_" + bd_c2] == null) {
  331. borderInfoCompute[bd_r + "_" + bd_c2] = {};
  332. }
  333. borderInfoCompute[bd_r + "_" + bd_c2].r = {
  334. "color": borderColor,
  335. "style": borderStyle
  336. };
  337. let bd_c_right = bd_c2 + 1;
  338. if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
  339. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[
  340. bd_r][bd_c_right].mc != null) {
  341. let cell_right = data[bd_r][bd_c_right];
  342. let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  343. if (mc.c == bd_c_right) {
  344. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  345. "color": borderColor,
  346. "style": borderStyle
  347. };
  348. }
  349. } else {
  350. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  351. "color": borderColor,
  352. "style": borderStyle
  353. };
  354. }
  355. }
  356. let mc = cfg["merge"] || {};
  357. for (const key in mc) {
  358. let {
  359. c,
  360. r,
  361. cs,
  362. rs
  363. } = mc[key];
  364. if (bd_c2 < c + cs - 1 && bd_c2 >= c && bd_r >= r && bd_r <= r + rs - 1) {
  365. borderInfoCompute[bd_r + "_" + bd_c2].r = null;
  366. }
  367. }
  368. }
  369. } else if (borderType == "border-top") {
  370. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r1] != null) {
  371. continue;
  372. }
  373. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  374. if (borderInfoCompute[bd_r1 + "_" + bd_c] == null) {
  375. borderInfoCompute[bd_r1 + "_" + bd_c] = {};
  376. }
  377. borderInfoCompute[bd_r1 + "_" + bd_c].t = {
  378. "color": borderColor,
  379. "style": borderStyle
  380. };
  381. let bd_r_top = bd_r1 - 1;
  382. if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
  383. if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[
  384. bd_r_top][bd_c].mc != null) {
  385. let cell_top = data[bd_r_top][bd_c];
  386. let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  387. if (mc.r + mc.rs - 1 == bd_r_top) {
  388. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  389. "color": borderColor,
  390. "style": borderStyle
  391. };
  392. }
  393. } else {
  394. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  395. "color": borderColor,
  396. "style": borderStyle
  397. };
  398. }
  399. }
  400. let mc = cfg["merge"] || {};
  401. for (const key in mc) {
  402. let {
  403. c,
  404. r,
  405. cs,
  406. rs
  407. } = mc[key];
  408. if (bd_r1 <= r + rs - 1 && bd_r1 > r && bd_c >= c && bd_c <= c + cs - 1) {
  409. borderInfoCompute[bd_r1 + "_" + bd_c].t = null;
  410. }
  411. }
  412. }
  413. } else if (borderType == "border-bottom") {
  414. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r2] != null) {
  415. continue;
  416. }
  417. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  418. if (borderInfoCompute[bd_r2 + "_" + bd_c] == null) {
  419. borderInfoCompute[bd_r2 + "_" + bd_c] = {};
  420. }
  421. borderInfoCompute[bd_r2 + "_" + bd_c].b = {
  422. "color": borderColor,
  423. "style": borderStyle
  424. };
  425. let bd_r_bottom = bd_r2 + 1;
  426. if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
  427. if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" &&
  428. data[bd_r_bottom][bd_c].mc != null) {
  429. let cell_bottom = data[bd_r_bottom][bd_c];
  430. let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  431. if (mc.r == bd_r_bottom) {
  432. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  433. "color": borderColor,
  434. "style": borderStyle
  435. };
  436. }
  437. } else {
  438. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  439. "color": borderColor,
  440. "style": borderStyle
  441. };
  442. }
  443. }
  444. let mc = cfg["merge"] || {};
  445. for (const key in mc) {
  446. let {
  447. c,
  448. r,
  449. cs,
  450. rs
  451. } = mc[key];
  452. if (bd_r2 < r + rs - 1 && bd_r2 >= r && bd_c >= c && bd_c <= c + cs - 1) {
  453. borderInfoCompute[bd_r2 + "_" + bd_c].b = null;
  454. }
  455. }
  456. }
  457. } else if (borderType == "border-all") {
  458. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  459. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  460. continue;
  461. }
  462. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  463. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][
  464. bd_c
  465. ].mc != null) {
  466. let cell = data[bd_r][bd_c];
  467. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  468. if (mc == undefined || mc == null) {
  469. continue
  470. };
  471. if (mc.r == bd_r) {
  472. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  473. borderInfoCompute[bd_r + "_" + bd_c] = {};
  474. }
  475. borderInfoCompute[bd_r + "_" + bd_c].t = {
  476. "color": borderColor,
  477. "style": borderStyle
  478. };
  479. }
  480. if (mc.r + mc.rs - 1 == bd_r) {
  481. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  482. borderInfoCompute[bd_r + "_" + bd_c] = {};
  483. }
  484. borderInfoCompute[bd_r + "_" + bd_c].b = {
  485. "color": borderColor,
  486. "style": borderStyle
  487. };
  488. }
  489. if (mc.c == bd_c) {
  490. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  491. borderInfoCompute[bd_r + "_" + bd_c] = {};
  492. }
  493. borderInfoCompute[bd_r + "_" + bd_c].l = {
  494. "color": borderColor,
  495. "style": borderStyle
  496. };
  497. }
  498. if (mc.c + mc.cs - 1 == bd_c) {
  499. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  500. borderInfoCompute[bd_r + "_" + bd_c] = {};
  501. }
  502. borderInfoCompute[bd_r + "_" + bd_c].r = {
  503. "color": borderColor,
  504. "style": borderStyle
  505. };
  506. }
  507. } else {
  508. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  509. borderInfoCompute[bd_r + "_" + bd_c] = {};
  510. }
  511. borderInfoCompute[bd_r + "_" + bd_c].l = {
  512. "color": borderColor,
  513. "style": borderStyle
  514. };
  515. borderInfoCompute[bd_r + "_" + bd_c].r = {
  516. "color": borderColor,
  517. "style": borderStyle
  518. };
  519. borderInfoCompute[bd_r + "_" + bd_c].t = {
  520. "color": borderColor,
  521. "style": borderStyle
  522. };
  523. borderInfoCompute[bd_r + "_" + bd_c].b = {
  524. "color": borderColor,
  525. "style": borderStyle
  526. };
  527. }
  528. if (bd_r == bd_r1) {
  529. let bd_r_top = bd_r1 - 1;
  530. if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
  531. if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) ==
  532. "object" && data[bd_r_top][bd_c].mc != null) {
  533. let cell_top = data[bd_r_top][bd_c];
  534. let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  535. if (mc.r + mc.rs - 1 == bd_r_top) {
  536. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  537. "color": borderColor,
  538. "style": borderStyle
  539. };
  540. }
  541. } else {
  542. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  543. "color": borderColor,
  544. "style": borderStyle
  545. };
  546. }
  547. }
  548. }
  549. if (bd_r == bd_r2) {
  550. let bd_r_bottom = bd_r2 + 1;
  551. if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
  552. if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) ==
  553. "object" && data[bd_r_bottom][bd_c].mc != null) {
  554. let cell_bottom = data[bd_r_bottom][bd_c];
  555. let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  556. if (mc.r == bd_r_bottom) {
  557. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  558. "color": borderColor,
  559. "style": borderStyle
  560. };
  561. }
  562. } else {
  563. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  564. "color": borderColor,
  565. "style": borderStyle
  566. };
  567. }
  568. }
  569. }
  570. if (bd_c == bd_c1) {
  571. let bd_c_left = bd_c1 - 1;
  572. if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
  573. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" &&
  574. data[bd_r][bd_c_left].mc != null) {
  575. let cell_left = data[bd_r][bd_c_left];
  576. let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  577. if (mc.c + mc.cs - 1 == bd_c_left) {
  578. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  579. "color": borderColor,
  580. "style": borderStyle
  581. };
  582. }
  583. } else {
  584. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  585. "color": borderColor,
  586. "style": borderStyle
  587. };
  588. }
  589. }
  590. }
  591. if (bd_c == bd_c2) {
  592. let bd_c_right = bd_c2 + 1;
  593. if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
  594. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" &&
  595. data[bd_r][bd_c_right].mc != null) {
  596. let cell_right = data[bd_r][bd_c_right];
  597. let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  598. if (mc.c == bd_c_right) {
  599. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  600. "color": borderColor,
  601. "style": borderStyle
  602. };
  603. }
  604. } else {
  605. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  606. "color": borderColor,
  607. "style": borderStyle
  608. };
  609. }
  610. }
  611. }
  612. }
  613. }
  614. } else if (borderType == "border-outside") {
  615. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  616. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  617. continue;
  618. }
  619. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  620. if (!(bd_r == bd_r1 || bd_r == bd_r2 || bd_c == bd_c1 || bd_c == bd_c2)) {
  621. continue;
  622. }
  623. if (bd_r == bd_r1) {
  624. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  625. borderInfoCompute[bd_r + "_" + bd_c] = {};
  626. }
  627. borderInfoCompute[bd_r + "_" + bd_c].t = {
  628. "color": borderColor,
  629. "style": borderStyle
  630. };
  631. let bd_r_top = bd_r1 - 1;
  632. if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
  633. if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) ==
  634. "object" && data[bd_r_top][bd_c].mc != null) {
  635. let cell_top = data[bd_r_top][bd_c];
  636. let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  637. if (mc.r + mc.rs - 1 == bd_r_top) {
  638. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  639. "color": borderColor,
  640. "style": borderStyle
  641. };
  642. }
  643. } else {
  644. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  645. "color": borderColor,
  646. "style": borderStyle
  647. };
  648. }
  649. }
  650. }
  651. if (bd_r == bd_r2) {
  652. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  653. borderInfoCompute[bd_r + "_" + bd_c] = {};
  654. }
  655. borderInfoCompute[bd_r + "_" + bd_c].b = {
  656. "color": borderColor,
  657. "style": borderStyle
  658. };
  659. let bd_r_bottom = bd_r2 + 1;
  660. if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
  661. if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) ==
  662. "object" && data[bd_r_bottom][bd_c].mc != null) {
  663. let cell_bottom = data[bd_r_bottom][bd_c];
  664. let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  665. if (mc.r == bd_r_bottom) {
  666. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  667. "color": borderColor,
  668. "style": borderStyle
  669. };
  670. }
  671. } else {
  672. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  673. "color": borderColor,
  674. "style": borderStyle
  675. };
  676. }
  677. }
  678. }
  679. if (bd_c == bd_c1) {
  680. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  681. borderInfoCompute[bd_r + "_" + bd_c] = {};
  682. }
  683. borderInfoCompute[bd_r + "_" + bd_c].l = {
  684. "color": borderColor,
  685. "style": borderStyle
  686. };
  687. let bd_c_left = bd_c1 - 1;
  688. if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
  689. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" &&
  690. data[bd_r][bd_c_left].mc != null) {
  691. let cell_left = data[bd_r][bd_c_left];
  692. let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  693. if (mc.c + mc.cs - 1 == bd_c_left) {
  694. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  695. "color": borderColor,
  696. "style": borderStyle
  697. };
  698. }
  699. } else {
  700. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  701. "color": borderColor,
  702. "style": borderStyle
  703. };
  704. }
  705. }
  706. }
  707. if (bd_c == bd_c2) {
  708. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  709. borderInfoCompute[bd_r + "_" + bd_c] = {};
  710. }
  711. borderInfoCompute[bd_r + "_" + bd_c].r = {
  712. "color": borderColor,
  713. "style": borderStyle
  714. };
  715. let bd_c_right = bd_c2 + 1;
  716. if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
  717. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" &&
  718. data[bd_r][bd_c_right].mc != null) {
  719. let cell_right = data[bd_r][bd_c_right];
  720. let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  721. if (mc.c == bd_c_right) {
  722. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  723. "color": borderColor,
  724. "style": borderStyle
  725. };
  726. }
  727. } else {
  728. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  729. "color": borderColor,
  730. "style": borderStyle
  731. };
  732. }
  733. }
  734. }
  735. }
  736. }
  737. } else if (borderType == "border-inside") {
  738. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  739. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  740. continue;
  741. }
  742. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  743. if (bd_r == bd_r1 && bd_c == bd_c1) {
  744. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  745. [bd_c].mc != null) {
  746. } else {
  747. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  748. borderInfoCompute[bd_r + "_" + bd_c] = {};
  749. }
  750. borderInfoCompute[bd_r + "_" + bd_c].r = {
  751. "color": borderColor,
  752. "style": borderStyle
  753. };
  754. borderInfoCompute[bd_r + "_" + bd_c].b = {
  755. "color": borderColor,
  756. "style": borderStyle
  757. };
  758. }
  759. } else if (bd_r == bd_r2 && bd_c == bd_c1) {
  760. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  761. [bd_c].mc != null) {
  762. } else {
  763. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  764. borderInfoCompute[bd_r + "_" + bd_c] = {};
  765. }
  766. borderInfoCompute[bd_r + "_" + bd_c].r = {
  767. "color": borderColor,
  768. "style": borderStyle
  769. };
  770. borderInfoCompute[bd_r + "_" + bd_c].t = {
  771. "color": borderColor,
  772. "style": borderStyle
  773. };
  774. }
  775. } else if (bd_r == bd_r1 && bd_c == bd_c2) {
  776. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  777. [bd_c].mc != null) {
  778. } else {
  779. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  780. borderInfoCompute[bd_r + "_" + bd_c] = {};
  781. }
  782. borderInfoCompute[bd_r + "_" + bd_c].l = {
  783. "color": borderColor,
  784. "style": borderStyle
  785. };
  786. borderInfoCompute[bd_r + "_" + bd_c].b = {
  787. "color": borderColor,
  788. "style": borderStyle
  789. };
  790. }
  791. } else if (bd_r == bd_r2 && bd_c == bd_c2) {
  792. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  793. [bd_c].mc != null) {
  794. } else {
  795. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  796. borderInfoCompute[bd_r + "_" + bd_c] = {};
  797. }
  798. borderInfoCompute[bd_r + "_" + bd_c].l = {
  799. "color": borderColor,
  800. "style": borderStyle
  801. };
  802. borderInfoCompute[bd_r + "_" + bd_c].t = {
  803. "color": borderColor,
  804. "style": borderStyle
  805. };
  806. }
  807. } else if (bd_r == bd_r1) {
  808. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  809. [bd_c].mc != null) {
  810. let cell = data[bd_r][bd_c];
  811. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  812. if (mc.c == bd_c) {
  813. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  814. borderInfoCompute[bd_r + "_" + bd_c] = {};
  815. }
  816. borderInfoCompute[bd_r + "_" + bd_c].l = {
  817. "color": borderColor,
  818. "style": borderStyle
  819. };
  820. } else if (mc.c + mc.cs - 1 == bd_c) {
  821. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  822. borderInfoCompute[bd_r + "_" + bd_c] = {};
  823. }
  824. borderInfoCompute[bd_r + "_" + bd_c].r = {
  825. "color": borderColor,
  826. "style": borderStyle
  827. };
  828. }
  829. } else {
  830. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  831. borderInfoCompute[bd_r + "_" + bd_c] = {};
  832. }
  833. borderInfoCompute[bd_r + "_" + bd_c].l = {
  834. "color": borderColor,
  835. "style": borderStyle
  836. };
  837. borderInfoCompute[bd_r + "_" + bd_c].r = {
  838. "color": borderColor,
  839. "style": borderStyle
  840. };
  841. borderInfoCompute[bd_r + "_" + bd_c].b = {
  842. "color": borderColor,
  843. "style": borderStyle
  844. };
  845. }
  846. } else if (bd_r == bd_r2) {
  847. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  848. [bd_c].mc != null) {
  849. let cell = data[bd_r][bd_c];
  850. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  851. if (mc.c == bd_c) {
  852. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  853. borderInfoCompute[bd_r + "_" + bd_c] = {};
  854. }
  855. borderInfoCompute[bd_r + "_" + bd_c].l = {
  856. "color": borderColor,
  857. "style": borderStyle
  858. };
  859. } else if (mc.c + mc.cs - 1 == bd_c) {
  860. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  861. borderInfoCompute[bd_r + "_" + bd_c] = {};
  862. }
  863. borderInfoCompute[bd_r + "_" + bd_c].r = {
  864. "color": borderColor,
  865. "style": borderStyle
  866. };
  867. }
  868. } else {
  869. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  870. borderInfoCompute[bd_r + "_" + bd_c] = {};
  871. }
  872. borderInfoCompute[bd_r + "_" + bd_c].l = {
  873. "color": borderColor,
  874. "style": borderStyle
  875. };
  876. borderInfoCompute[bd_r + "_" + bd_c].r = {
  877. "color": borderColor,
  878. "style": borderStyle
  879. };
  880. borderInfoCompute[bd_r + "_" + bd_c].t = {
  881. "color": borderColor,
  882. "style": borderStyle
  883. };
  884. }
  885. } else if (bd_c == bd_c1) {
  886. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  887. [bd_c].mc != null) {
  888. let cell = data[bd_r][bd_c];
  889. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  890. if (mc.r == bd_r) {
  891. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  892. borderInfoCompute[bd_r + "_" + bd_c] = {};
  893. }
  894. borderInfoCompute[bd_r + "_" + bd_c].t = {
  895. "color": borderColor,
  896. "style": borderStyle
  897. };
  898. } else if (mc.r + mc.rs - 1 == bd_r) {
  899. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  900. borderInfoCompute[bd_r + "_" + bd_c] = {};
  901. }
  902. borderInfoCompute[bd_r + "_" + bd_c].b = {
  903. "color": borderColor,
  904. "style": borderStyle
  905. };
  906. }
  907. } else {
  908. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  909. borderInfoCompute[bd_r + "_" + bd_c] = {};
  910. }
  911. borderInfoCompute[bd_r + "_" + bd_c].r = {
  912. "color": borderColor,
  913. "style": borderStyle
  914. };
  915. borderInfoCompute[bd_r + "_" + bd_c].t = {
  916. "color": borderColor,
  917. "style": borderStyle
  918. };
  919. borderInfoCompute[bd_r + "_" + bd_c].b = {
  920. "color": borderColor,
  921. "style": borderStyle
  922. };
  923. }
  924. } else if (bd_c == bd_c2) {
  925. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  926. [bd_c].mc != null) {
  927. let cell = data[bd_r][bd_c];
  928. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  929. if (mc.r == bd_r) {
  930. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  931. borderInfoCompute[bd_r + "_" + bd_c] = {};
  932. }
  933. borderInfoCompute[bd_r + "_" + bd_c].t = {
  934. "color": borderColor,
  935. "style": borderStyle
  936. };
  937. } else if (mc.r + mc.rs - 1 == bd_r) {
  938. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  939. borderInfoCompute[bd_r + "_" + bd_c] = {};
  940. }
  941. borderInfoCompute[bd_r + "_" + bd_c].b = {
  942. "color": borderColor,
  943. "style": borderStyle
  944. };
  945. }
  946. } else {
  947. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  948. borderInfoCompute[bd_r + "_" + bd_c] = {};
  949. }
  950. borderInfoCompute[bd_r + "_" + bd_c].l = {
  951. "color": borderColor,
  952. "style": borderStyle
  953. };
  954. borderInfoCompute[bd_r + "_" + bd_c].t = {
  955. "color": borderColor,
  956. "style": borderStyle
  957. };
  958. borderInfoCompute[bd_r + "_" + bd_c].b = {
  959. "color": borderColor,
  960. "style": borderStyle
  961. };
  962. }
  963. } else {
  964. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  965. [bd_c].mc != null) {
  966. let cell = data[bd_r][bd_c];
  967. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  968. if (mc.r == bd_r) {
  969. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  970. borderInfoCompute[bd_r + "_" + bd_c] = {};
  971. }
  972. borderInfoCompute[bd_r + "_" + bd_c].t = {
  973. "color": borderColor,
  974. "style": borderStyle
  975. };
  976. } else if (mc.r + mc.rs - 1 == bd_r) {
  977. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  978. borderInfoCompute[bd_r + "_" + bd_c] = {};
  979. }
  980. borderInfoCompute[bd_r + "_" + bd_c].b = {
  981. "color": borderColor,
  982. "style": borderStyle
  983. };
  984. }
  985. if (mc.c == bd_c) {
  986. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  987. borderInfoCompute[bd_r + "_" + bd_c] = {};
  988. }
  989. borderInfoCompute[bd_r + "_" + bd_c].l = {
  990. "color": borderColor,
  991. "style": borderStyle
  992. };
  993. } else if (mc.c + mc.cs - 1 == bd_c) {
  994. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  995. borderInfoCompute[bd_r + "_" + bd_c] = {};
  996. }
  997. borderInfoCompute[bd_r + "_" + bd_c].r = {
  998. "color": borderColor,
  999. "style": borderStyle
  1000. };
  1001. }
  1002. } else {
  1003. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1004. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1005. }
  1006. borderInfoCompute[bd_r + "_" + bd_c].l = {
  1007. "color": borderColor,
  1008. "style": borderStyle
  1009. };
  1010. borderInfoCompute[bd_r + "_" + bd_c].r = {
  1011. "color": borderColor,
  1012. "style": borderStyle
  1013. };
  1014. borderInfoCompute[bd_r + "_" + bd_c].t = {
  1015. "color": borderColor,
  1016. "style": borderStyle
  1017. };
  1018. borderInfoCompute[bd_r + "_" + bd_c].b = {
  1019. "color": borderColor,
  1020. "style": borderStyle
  1021. };
  1022. }
  1023. }
  1024. }
  1025. }
  1026. } else if (borderType == "border-horizontal") {
  1027. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  1028. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  1029. continue;
  1030. }
  1031. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  1032. if (bd_r == bd_r1) {
  1033. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  1034. [bd_c].mc != null) {
  1035. } else {
  1036. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1037. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1038. }
  1039. borderInfoCompute[bd_r + "_" + bd_c].b = {
  1040. "color": borderColor,
  1041. "style": borderStyle
  1042. };
  1043. }
  1044. } else if (bd_r == bd_r2) {
  1045. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  1046. [bd_c].mc != null) {
  1047. } else {
  1048. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1049. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1050. }
  1051. borderInfoCompute[bd_r + "_" + bd_c].t = {
  1052. "color": borderColor,
  1053. "style": borderStyle
  1054. };
  1055. }
  1056. } else {
  1057. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  1058. [bd_c].mc != null) {
  1059. let cell = data[bd_r][bd_c];
  1060. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  1061. if (mc.r == bd_r) {
  1062. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1063. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1064. }
  1065. borderInfoCompute[bd_r + "_" + bd_c].t = {
  1066. "color": borderColor,
  1067. "style": borderStyle
  1068. };
  1069. } else if (mc.r + mc.rs - 1 == bd_r) {
  1070. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1071. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1072. }
  1073. borderInfoCompute[bd_r + "_" + bd_c].b = {
  1074. "color": borderColor,
  1075. "style": borderStyle
  1076. };
  1077. }
  1078. } else {
  1079. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1080. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1081. }
  1082. borderInfoCompute[bd_r + "_" + bd_c].t = {
  1083. "color": borderColor,
  1084. "style": borderStyle
  1085. };
  1086. borderInfoCompute[bd_r + "_" + bd_c].b = {
  1087. "color": borderColor,
  1088. "style": borderStyle
  1089. };
  1090. }
  1091. }
  1092. }
  1093. }
  1094. } else if (borderType == "border-vertical") {
  1095. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  1096. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  1097. continue;
  1098. }
  1099. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  1100. if (bd_c == bd_c1) {
  1101. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  1102. [bd_c].mc != null) {
  1103. } else {
  1104. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1105. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1106. }
  1107. borderInfoCompute[bd_r + "_" + bd_c].r = {
  1108. "color": borderColor,
  1109. "style": borderStyle
  1110. };
  1111. }
  1112. } else if (bd_c == bd_c2) {
  1113. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  1114. [bd_c].mc != null) {
  1115. } else {
  1116. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1117. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1118. }
  1119. borderInfoCompute[bd_r + "_" + bd_c].l = {
  1120. "color": borderColor,
  1121. "style": borderStyle
  1122. };
  1123. }
  1124. } else {
  1125. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r]
  1126. [bd_c].mc != null) {
  1127. let cell = data[bd_r][bd_c];
  1128. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {};
  1129. if (mc.c == bd_c) {
  1130. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1131. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1132. }
  1133. borderInfoCompute[bd_r + "_" + bd_c].l = {
  1134. "color": borderColor,
  1135. "style": borderStyle
  1136. };
  1137. } else if (mc.c + mc.cs - 1 == bd_c) {
  1138. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1139. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1140. }
  1141. borderInfoCompute[bd_r + "_" + bd_c].r = {
  1142. "color": borderColor,
  1143. "style": borderStyle
  1144. };
  1145. }
  1146. } else {
  1147. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1148. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1149. }
  1150. borderInfoCompute[bd_r + "_" + bd_c].l = {
  1151. "color": borderColor,
  1152. "style": borderStyle
  1153. };
  1154. borderInfoCompute[bd_r + "_" + bd_c].r = {
  1155. "color": borderColor,
  1156. "style": borderStyle
  1157. };
  1158. }
  1159. }
  1160. }
  1161. }
  1162. } else if (borderType == "border-none") {
  1163. for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
  1164. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  1165. continue;
  1166. }
  1167. for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
  1168. if (borderInfoCompute[bd_r + "_" + bd_c] != null) {
  1169. delete borderInfoCompute[bd_r + "_" + bd_c];
  1170. }
  1171. if (bd_r == bd_r1) {
  1172. let bd_r_top = bd_r1 - 1;
  1173. if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
  1174. delete borderInfoCompute[bd_r_top + "_" + bd_c].b;
  1175. }
  1176. }
  1177. if (bd_r == bd_r2) {
  1178. let bd_r_bottom = bd_r2 + 1;
  1179. if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
  1180. delete borderInfoCompute[bd_r_bottom + "_" + bd_c].t;
  1181. }
  1182. }
  1183. if (bd_c == bd_c1) {
  1184. let bd_c_left = bd_c1 - 1;
  1185. if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
  1186. delete borderInfoCompute[bd_r + "_" + bd_c_left].r;
  1187. }
  1188. }
  1189. if (bd_c == bd_c2) {
  1190. let bd_c_right = bd_c2 + 1;
  1191. if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
  1192. delete borderInfoCompute[bd_r + "_" + bd_c_right].l;
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. } else if (rangeType == "cell") {
  1200. let value = borderInfo[i].value;
  1201. let bd_r = value.row_index,
  1202. bd_c = value.col_index;
  1203. if (bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c >
  1204. dataset_col_ed) {
  1205. continue;
  1206. }
  1207. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  1208. continue;
  1209. }
  1210. if (value.l != null || value.r != null || value.t != null || value.b != null) {
  1211. if (borderInfoCompute[bd_r + "_" + bd_c] == null) {
  1212. borderInfoCompute[bd_r + "_" + bd_c] = {};
  1213. }
  1214. if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc !=
  1215. null) {
  1216. let cell = data[bd_r][bd_c];
  1217. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {};
  1218. if (value.l != null && bd_c == mc.c) { //左边框
  1219. borderInfoCompute[bd_r + "_" + bd_c].l = {
  1220. "color": value.l.color,
  1221. "style": value.l.style
  1222. };
  1223. let bd_c_left = bd_c - 1;
  1224. if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
  1225. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[
  1226. bd_r][bd_c_left].mc != null) {
  1227. let cell_left = data[bd_r][bd_c_left];
  1228. let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  1229. if (mc_l.c + mc_l.cs - 1 == bd_c_left) {
  1230. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  1231. "color": value.l.color,
  1232. "style": value.l.style
  1233. };
  1234. }
  1235. } else {
  1236. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  1237. "color": value.l.color,
  1238. "style": value.l.style
  1239. };
  1240. }
  1241. }
  1242. } else {
  1243. borderInfoCompute[bd_r + "_" + bd_c].l = null;
  1244. }
  1245. if (value.r != null && bd_c == mc.c + mc.cs - 1) { //右边框
  1246. borderInfoCompute[bd_r + "_" + bd_c].r = {
  1247. "color": value.r.color,
  1248. "style": value.r.style
  1249. };
  1250. let bd_c_right = bd_c + 1;
  1251. if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
  1252. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[
  1253. bd_r][bd_c_right].mc != null) {
  1254. let cell_right = data[bd_r][bd_c_right];
  1255. let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  1256. if (mc_r.c == bd_c_right) {
  1257. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  1258. "color": value.r.color,
  1259. "style": value.r.style
  1260. };
  1261. }
  1262. } else {
  1263. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  1264. "color": value.r.color,
  1265. "style": value.r.style
  1266. };
  1267. }
  1268. }
  1269. } else {
  1270. borderInfoCompute[bd_r + "_" + bd_c].r = null;
  1271. }
  1272. if (value.t != null && bd_r == mc.r) { //上边框
  1273. borderInfoCompute[bd_r + "_" + bd_c].t = {
  1274. "color": value.t.color,
  1275. "style": value.t.style
  1276. };
  1277. let bd_r_top = bd_r - 1;
  1278. if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
  1279. if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[
  1280. bd_r_top][bd_c].mc != null) {
  1281. let cell_top = data[bd_r_top][bd_c];
  1282. let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  1283. if (mc_t.r + mc_t.rs - 1 == bd_r_top) {
  1284. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  1285. "color": value.t.color,
  1286. "style": value.t.style
  1287. };
  1288. }
  1289. } else {
  1290. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  1291. "color": value.t.color,
  1292. "style": value.t.style
  1293. };
  1294. }
  1295. }
  1296. } else {
  1297. borderInfoCompute[bd_r + "_" + bd_c].t = null;
  1298. }
  1299. if (value.b != null && bd_r == mc.r + mc.rs - 1) { //下边框
  1300. borderInfoCompute[bd_r + "_" + bd_c].b = {
  1301. "color": value.b.color,
  1302. "style": value.b.style
  1303. };
  1304. let bd_r_bottom = bd_r + 1;
  1305. if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
  1306. if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" &&
  1307. data[bd_r_bottom][bd_c].mc != null) {
  1308. let cell_bottom = data[bd_r_bottom][bd_c];
  1309. let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  1310. if (mc_b.r == bd_r_bottom) {
  1311. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  1312. "color": value.b.color,
  1313. "style": value.b.style
  1314. };
  1315. }
  1316. } else {
  1317. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  1318. "color": value.b.color,
  1319. "style": value.b.style
  1320. };
  1321. }
  1322. }
  1323. } else {
  1324. borderInfoCompute[bd_r + "_" + bd_c].b = null;
  1325. }
  1326. } else {
  1327. if (value.l != null) { //左边框
  1328. borderInfoCompute[bd_r + "_" + bd_c].l = {
  1329. "color": value.l.color,
  1330. "style": value.l.style
  1331. };
  1332. let bd_c_left = bd_c - 1;
  1333. if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) {
  1334. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[
  1335. bd_r][bd_c_left].mc != null) {
  1336. let cell_left = data[bd_r][bd_c_left];
  1337. let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  1338. if (mc_l.c + mc_l.cs - 1 == bd_c_left) {
  1339. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  1340. "color": value.l.color,
  1341. "style": value.l.style
  1342. };
  1343. }
  1344. } else {
  1345. borderInfoCompute[bd_r + "_" + bd_c_left].r = {
  1346. "color": value.l.color,
  1347. "style": value.l.style
  1348. };
  1349. }
  1350. }
  1351. } else {
  1352. borderInfoCompute[bd_r + "_" + bd_c].l = null;
  1353. }
  1354. if (value.r != null) { //右边框
  1355. borderInfoCompute[bd_r + "_" + bd_c].r = {
  1356. "color": value.r.color,
  1357. "style": value.r.style
  1358. };
  1359. let bd_c_right = bd_c + 1;
  1360. if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) {
  1361. if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[
  1362. bd_r][bd_c_right].mc != null) {
  1363. let cell_right = data[bd_r][bd_c_right];
  1364. let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  1365. if (mc_r.c == bd_c_right) {
  1366. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  1367. "color": value.r.color,
  1368. "style": value.r.style
  1369. };
  1370. }
  1371. } else {
  1372. borderInfoCompute[bd_r + "_" + bd_c_right].l = {
  1373. "color": value.r.color,
  1374. "style": value.r.style
  1375. };
  1376. }
  1377. }
  1378. } else {
  1379. borderInfoCompute[bd_r + "_" + bd_c].r = null;
  1380. }
  1381. if (value.t != null) { //上边框
  1382. borderInfoCompute[bd_r + "_" + bd_c].t = {
  1383. "color": value.t.color,
  1384. "style": value.t.style
  1385. };
  1386. let bd_r_top = bd_r - 1;
  1387. if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) {
  1388. if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[
  1389. bd_r_top][bd_c].mc != null) {
  1390. let cell_top = data[bd_r_top][bd_c];
  1391. let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  1392. if (mc_t.r + mc_t.rs - 1 == bd_r_top) {
  1393. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  1394. "color": value.t.color,
  1395. "style": value.t.style
  1396. };
  1397. }
  1398. } else {
  1399. borderInfoCompute[bd_r_top + "_" + bd_c].b = {
  1400. "color": value.t.color,
  1401. "style": value.t.style
  1402. };
  1403. }
  1404. }
  1405. } else {
  1406. borderInfoCompute[bd_r + "_" + bd_c].t = null;
  1407. }
  1408. if (value.b != null) { //下边框
  1409. borderInfoCompute[bd_r + "_" + bd_c].b = {
  1410. "color": value.b.color,
  1411. "style": value.b.style
  1412. };
  1413. let bd_r_bottom = bd_r + 1;
  1414. if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) {
  1415. if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" &&
  1416. data[bd_r_bottom][bd_c].mc != null) {
  1417. let cell_bottom = data[bd_r_bottom][bd_c];
  1418. let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  1419. if (mc_b.r == bd_r_bottom) {
  1420. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  1421. "color": value.b.color,
  1422. "style": value.b.style
  1423. };
  1424. }
  1425. } else {
  1426. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = {
  1427. "color": value.b.color,
  1428. "style": value.b.style
  1429. };
  1430. }
  1431. }
  1432. } else {
  1433. borderInfoCompute[bd_r + "_" + bd_c].b = null;
  1434. }
  1435. }
  1436. } else {
  1437. delete borderInfoCompute[bd_r + "_" + bd_c];
  1438. }
  1439. }
  1440. }
  1441. }
  1442. return borderInfoCompute;
  1443. }
  1444. //获取数据类型
  1445. var getObjType = function(obj) {
  1446. let toString = Object.prototype.toString;
  1447. let map = {
  1448. '[object Boolean]': 'boolean',
  1449. '[object Number]': 'number',
  1450. '[object String]': 'string',
  1451. '[object Function]': 'function',
  1452. '[object Array]': 'array',
  1453. '[object Date]': 'date',
  1454. '[object RegExp]': 'regExp',
  1455. '[object Undefined]': 'undefined',
  1456. '[object Null]': 'null',
  1457. '[object Object]': 'object'
  1458. }
  1459. return map[toString.call(obj)];
  1460. }
  1461. var setStyleAndValue = function(cellArr, worksheet) {
  1462. if (!Array.isArray(cellArr)) return;
  1463. cellArr.forEach(function(row, rowid) {
  1464. const dbrow = worksheet.getRow(rowid + 1);
  1465. //设置单元格行高,默认乘以1.2倍
  1466. dbrow.height = luckysheet.getRowHeight([rowid])[rowid] * 1.2;
  1467. row.every(function(cell, columnid) {
  1468. if (!cell) return true;
  1469. if (rowid == 0) {
  1470. const dobCol = worksheet.getColumn(columnid + 1);
  1471. //设置单元格列宽除以8
  1472. dobCol.width = luckysheet.getColumnWidth([columnid])[columnid] / 8;
  1473. }
  1474. let fill = fillConvert(cell.bg);
  1475. let font = fontConvert(cell.ff, cell.fc, cell.bl, cell.it, cell.fs, cell.cl, cell.ul);
  1476. let alignment = alignmentConvert(cell.vt, cell.ht, cell.tb, cell.tr);
  1477. let value;
  1478. var v = '';
  1479. if (cell.ct && cell.ct.t == 'inlineStr') {
  1480. var s = cell.ct.s;
  1481. s.forEach(function(val, num) {
  1482. v += val.v;
  1483. })
  1484. } else {
  1485. v = cell.v;
  1486. }
  1487. if (cell.f) {
  1488. value = {
  1489. formula: cell.f,
  1490. result: v
  1491. };
  1492. } else {
  1493. value = v;
  1494. }
  1495. let target = worksheet.getCell(rowid + 1, columnid + 1);
  1496. target.fill = fill;
  1497. target.font = font;
  1498. target.alignment = alignment;
  1499. target.value = value;
  1500. return true;
  1501. })
  1502. })
  1503. }
  1504. //转换颜色
  1505. var rgb2hex = function(rgb) {
  1506. if (rgb.charAt(0) == '#') {
  1507. return rgb;
  1508. }
  1509. var ds = rgb.split(/\D+/);
  1510. var decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]);
  1511. return "#" + zero_fill_hex(decimal, 6);
  1512. function zero_fill_hex(num, digits) {
  1513. var s = num.toString(16);
  1514. while (s.length < digits)
  1515. s = "0" + s;
  1516. return s;
  1517. }
  1518. }
  1519. var fillConvert = function(bg) {
  1520. if (!bg) {
  1521. return null;
  1522. // return {
  1523. // type: 'pattern',
  1524. // pattern: 'solid',
  1525. // fgColor:{argb:'#ffffff'.replace('#','')}
  1526. // }
  1527. }
  1528. bg = bg.indexOf('rgb') > -1 ? rgb2hex(bg) : bg;
  1529. let fill = {
  1530. type: 'pattern',
  1531. pattern: 'solid',
  1532. fgColor: {
  1533. argb: bg.replace('#', '')
  1534. }
  1535. }
  1536. return fill
  1537. }
  1538. var fontConvert = function(ff = 0, fc = '#000000', bl = 0, it = 0, fs = 10, cl = 0, ul =
  1539. 0) { // luckysheet:ff(样式), fc(颜色), bl(粗体), it(斜体), fs(大小), cl(删除线), ul(下划线)
  1540. const luckyToExcel = {
  1541. 0: '微软雅黑',
  1542. 1: '宋体(Song)',
  1543. 2: '黑体(ST Heiti)',
  1544. 3: '楷体(ST Kaiti)',
  1545. 4: '仿宋(ST FangSong)',
  1546. 5: '新宋体(ST Song)',
  1547. 6: '华文新魏',
  1548. 7: '华文行楷',
  1549. 8: '华文隶书',
  1550. 9: 'Arial',
  1551. 10: 'Times New Roman ',
  1552. 11: 'Tahoma ',
  1553. 12: 'Verdana',
  1554. num2bl: function(num) {
  1555. return num === 0 ? false : true
  1556. }
  1557. }
  1558. let color = fc ? '' : (fc + "").indexOf('rgb') > -1 ? util.rgb2hex(fc) : fc;
  1559. let font = {
  1560. name: ff,
  1561. family: 1,
  1562. size: fs,
  1563. color: {
  1564. argb: color.replace('#', '')
  1565. },
  1566. bold: luckyToExcel.num2bl(bl),
  1567. italic: luckyToExcel.num2bl(it),
  1568. underline: luckyToExcel.num2bl(ul),
  1569. strike: luckyToExcel.num2bl(cl)
  1570. }
  1571. return font;
  1572. }
  1573. var alignmentConvert = function(vt = 'default', ht = 'default', tb = 'default', tr =
  1574. 'default') { // luckysheet:vt(垂直), ht(水平), tb(换行), tr(旋转)
  1575. const luckyToExcel = {
  1576. vertical: {
  1577. 0: 'middle',
  1578. 1: 'top',
  1579. 2: 'bottom',
  1580. default: 'top'
  1581. },
  1582. horizontal: {
  1583. 0: 'center',
  1584. 1: 'left',
  1585. 2: 'right',
  1586. default: 'left'
  1587. },
  1588. wrapText: {
  1589. 0: false,
  1590. 1: false,
  1591. 2: true,
  1592. default: false
  1593. },
  1594. textRotation: {
  1595. 0: 0,
  1596. 1: 45,
  1597. 2: -45,
  1598. 3: 'vertical',
  1599. 4: 90,
  1600. 5: -90,
  1601. default: 0
  1602. }
  1603. }
  1604. let alignment = {
  1605. vertical: luckyToExcel.vertical[vt],
  1606. horizontal: luckyToExcel.horizontal[ht],
  1607. wrapText: luckyToExcel.wrapText[tb],
  1608. textRotation: luckyToExcel.textRotation[tr]
  1609. }
  1610. return alignment;
  1611. }