export.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. import ExcelJS from 'exceljs'
  2. import FileSaver from 'file-saver'
  3. const exportExcel = function(luckysheet,name) { // 参数为luckysheet.getluckysheetfile()获取的对象
  4. // 1.创建工作簿,可以为工作簿添加属性
  5. const workbook = new ExcelJS.Workbook();
  6. // 2.创建表格,第二个参数可以配置创建什么样的工作表
  7. // 2.创建表格,第二个参数可以配置创建什么样的工作表
  8. if (Object.prototype.toString.call(luckysheet) === '[object Object]') {
  9. luckysheet = [luckysheet]
  10. }
  11. console.log(luckysheet)
  12. //var tableArr=luckysheet.getAllSheets();
  13. luckysheet.forEach(function(table) {
  14. if (table.data.length === 0) return true
  15. // ws.getCell('B2').fill = fills.
  16. const worksheet = workbook.addWorksheet(table.name)
  17. setStyleAndValue(table.data, worksheet);
  18. setMerge(table.config.merge, worksheet);
  19. setBorder(table, worksheet);
  20. setImages(table, worksheet, workbook);
  21. return true
  22. })
  23. // return
  24. // 4.写入 buffer
  25. const buffer = workbook.xlsx.writeBuffer().then(data => {
  26. // console.log('data', data)
  27. const blob = new Blob([data], {
  28. type: 'application/vnd.ms-excel;charset=utf-8'
  29. })
  30. console.log("导出成功!")
  31. saveFile(blob, name)
  32. })
  33. }
  34. var saveFile = function(buf,name) {
  35. let blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' });
  36. const downloadElement = document.createElement('a');
  37. let href = window.URL.createObjectURL(blob);
  38. downloadElement.href = href;
  39. downloadElement.download = name+".xlsx"; // 文件名字
  40. document.body.appendChild(downloadElement);
  41. downloadElement.click();
  42. document.body.removeChild(downloadElement); // 下载完成移除元素
  43. window.URL.revokeObjectURL(href); // 释放掉blob对象
  44. }
  45. var setMerge = function (luckyMerge = {}, worksheet) {
  46. const mergearr = Object.values(luckyMerge);
  47. mergearr.forEach(function (elem) { // elem格式:{r: 0, c: 0, rs: 1, cs: 2}
  48. // 按开始行,开始列,结束行,结束列合并(相当于 K10:M12)
  49. worksheet.mergeCells(elem.r + 1, elem.c + 1, elem.r + elem.rs, elem.c + elem.cs);
  50. });
  51. }
  52. //获取图片在单元格的位置
  53. var getImagePosition =function(num,arr){
  54. let index = 0;
  55. let minIndex;
  56. let maxIndex;
  57. for (let i = 0; i < arr.length; i++) {
  58. if (num < arr[i]) {
  59. index = i;
  60. break;
  61. }
  62. }
  63. if(index==0){
  64. minIndex = 0;
  65. maxIndex = 1;
  66. }
  67. else if(index == arr.length-1){
  68. minIndex = arr.length-2;
  69. maxIndex = arr.length-1;
  70. }
  71. else{
  72. minIndex = index-1;
  73. maxIndex = index;
  74. }
  75. let min = arr[minIndex];
  76. let max = arr[maxIndex];
  77. let radio = Math.abs((num-min)/(max-min))+index
  78. return radio;
  79. }
  80. var setImages = function (table, worksheet, workbook) {
  81. let {
  82. images,
  83. visibledatacolumn,//所有行的位置
  84. visibledatarow //所有列的位置
  85. } = {...table}
  86. if (typeof images != 'object') return;
  87. for (let key in images) {
  88. // 通过 base64 将图像添加到工作簿
  89. const myBase64Image = images[key].src;
  90. //开始行 开始列 结束行 结束列
  91. const item = images[key];
  92. const imageId = workbook.addImage({
  93. base64: myBase64Image,
  94. extension: 'png'
  95. });
  96. const col_st = getImagePosition(item.default.left,visibledatacolumn);
  97. const row_st = getImagePosition(item.default.top,visibledatarow);
  98. //模式1,图片左侧与luckysheet位置一样,像素比例保持不变,但是,右侧位置可能与原图所在单元格不一致
  99. worksheet.addImage(imageId, {
  100. tl: { col: col_st, row: row_st},
  101. ext: { width: item.default.width, height: item.default.height },
  102. });
  103. //模式2,图片四个角位置没有变动,但是图片像素比例可能和原图不一样
  104. // const w_ed = item.default.left+item.default.width;
  105. // const h_ed = item.default.top+item.default.height;
  106. // const col_ed = getImagePosition(w_ed,visibledatacolumn);
  107. // const row_ed = getImagePosition(h_ed,visibledatarow);
  108. // worksheet.addImage(imageId, {
  109. // tl: { col: col_st, row: row_st},
  110. // br: { col: col_ed, row: row_ed},
  111. // });
  112. }
  113. };
  114. var setBorder = function (lucksheetfile, worksheet) {
  115. if (!lucksheetfile) return;
  116. const luckyToExcel = {
  117. style: {
  118. 0: 'none',
  119. 1: 'thin',
  120. 2: 'hair',
  121. 3: 'dotted',
  122. 4: 'dashDot', // 'Dashed',
  123. 5: 'dashDot',
  124. 6: 'dashDotDot',
  125. 7: 'double',
  126. 8: 'medium',
  127. 9: 'mediumDashed',
  128. 10: 'mediumDashDot',
  129. 11: 'mediumDashDotDot',
  130. 12: 'slantDashDot',
  131. 13: 'thick'
  132. }
  133. }
  134. //获取所有的单元格边框的信息
  135. const borderInfoCompute = getBorderInfo(lucksheetfile);
  136. for (let x in borderInfoCompute) {
  137. let border = {};
  138. let info = borderInfoCompute[x];
  139. let row = parseInt(x.substr(0, x.indexOf('_')));
  140. let column = parseInt(x.substr(x.indexOf('_') + 1));
  141. if(info.t!=undefined){
  142. const tcolor = info.t.color.indexOf('rgb')>-1 ?rgb2hex(info.t.color):info.t.color;
  143. border['top'] = {style:luckyToExcel.style[info.t.style],color: {argb: tcolor.replace('#', '')}};
  144. }
  145. if(info.r!=undefined){
  146. const rcolor = info.r.color.indexOf('rgb')>-1 ?rgb2hex(info.r.color):info.r.color;
  147. border['right'] = {style:luckyToExcel.style[info.r.style],color: {argb: rcolor.replace('#', '')}};
  148. }
  149. if(info.b!=undefined){
  150. const bcolor = info.b.color.indexOf('rgb')>-1 ?rgb2hex(info.b.color):info.b.color;
  151. border['bottom'] = {style:luckyToExcel.style[info.b.style],color: {argb: bcolor.replace('#', '')}};
  152. }
  153. if(info.l!=undefined){
  154. const lcolor = info.l.color.indexOf('rgb')>-1 ?rgb2hex(info.l.color):info.l.color;
  155. border['left'] = {style:luckyToExcel.style[info.l.style],color: {argb: lcolor.replace('#', '')}};
  156. }
  157. worksheet.getCell(row + 1, column + 1).border = border;
  158. }
  159. }
  160. var getBorderInfo=function(luckysheetfile){
  161. let borderInfoCompute = {};
  162. let cfg = luckysheetfile.config;
  163. let data = luckysheetfile.data;
  164. let borderInfo = cfg["borderInfo"];
  165. //设置需要计算边框的区域
  166. let dataset_row_st = 0,dataset_row_ed = data.length,dataset_col_st=0,dataset_col_ed=data[0].length;
  167. if(borderInfo != null && borderInfo.length > 0){
  168. for(let i = 0; i < borderInfo.length; i++){
  169. let rangeType = borderInfo[i].rangeType;
  170. if(rangeType == "range"){
  171. let borderType = borderInfo[i].borderType;
  172. let borderColor = borderInfo[i].color;
  173. let borderStyle = borderInfo[i].style;
  174. let borderRange = borderInfo[i].range;
  175. for(let j = 0; j < borderRange.length; j++){
  176. let bd_r1 = borderRange[j].row[0], bd_r2 = borderRange[j].row[1];
  177. let bd_c1 = borderRange[j].column[0], bd_c2 = borderRange[j].column[1];
  178. if(bd_r1<dataset_row_st){
  179. bd_r1 = dataset_row_st;
  180. }
  181. if(bd_r2>dataset_row_ed){
  182. bd_r2 = dataset_row_ed;
  183. }
  184. if(bd_c1<dataset_col_st){
  185. bd_c1 = dataset_col_st;
  186. }
  187. if(bd_c2>dataset_col_ed){
  188. bd_c2 = dataset_col_ed;
  189. }
  190. if(borderType == "border-left"){
  191. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  192. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  193. continue;
  194. }
  195. if(borderInfoCompute[bd_r + "_" + bd_c1] == null){
  196. borderInfoCompute[bd_r + "_" + bd_c1] = {};
  197. }
  198. borderInfoCompute[bd_r + "_" + bd_c1].l = { "color": borderColor, "style": borderStyle };
  199. let bd_c_left = bd_c1 - 1;
  200. if(bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]){
  201. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null){
  202. let cell_left = data[bd_r][bd_c_left];
  203. let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  204. if(mc.c + mc.cs - 1 == bd_c_left){
  205. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle };
  206. }
  207. }
  208. else{
  209. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle };
  210. }
  211. }
  212. let mc = cfg["merge"] || {};
  213. for (const key in mc) {
  214. let {c,r,cs,rs} = mc[key];
  215. if(bd_c1 <= c + cs - 1 && bd_c1 > c && bd_r >= r && bd_r <= r + rs -1){
  216. borderInfoCompute[bd_r + "_" + bd_c1].l = null;
  217. }
  218. }
  219. }
  220. }
  221. else if(borderType == "border-right"){
  222. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  223. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  224. continue;
  225. }
  226. if(borderInfoCompute[bd_r + "_" + bd_c2] == null){
  227. borderInfoCompute[bd_r + "_" + bd_c2] = {};
  228. }
  229. borderInfoCompute[bd_r + "_" + bd_c2].r = { "color": borderColor, "style": borderStyle };
  230. let bd_c_right = bd_c2 + 1;
  231. if(bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]){
  232. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null){
  233. let cell_right = data[bd_r][bd_c_right];
  234. let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  235. if(mc.c == bd_c_right){
  236. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle };
  237. }
  238. }
  239. else{
  240. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle };
  241. }
  242. }
  243. let mc = cfg["merge"] || {};
  244. for (const key in mc) {
  245. let {c,r,cs,rs} = mc[key];
  246. if(bd_c2 < c + cs - 1 && bd_c2 >= c && bd_r >= r && bd_r <= r + rs -1){
  247. borderInfoCompute[bd_r + "_" + bd_c2].r = null;
  248. }
  249. }
  250. }
  251. }
  252. else if(borderType == "border-top"){
  253. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r1] != null) {
  254. continue;
  255. }
  256. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  257. if(borderInfoCompute[bd_r1 + "_" + bd_c] == null){
  258. borderInfoCompute[bd_r1 + "_" + bd_c] = {};
  259. }
  260. borderInfoCompute[bd_r1 + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  261. let bd_r_top = bd_r1 - 1;
  262. if(bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]){
  263. if(data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null){
  264. let cell_top = data[bd_r_top][bd_c];
  265. let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  266. if(mc.r + mc.rs - 1 == bd_r_top){
  267. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  268. }
  269. }
  270. else{
  271. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  272. }
  273. }
  274. let mc = cfg["merge"] || {};
  275. for (const key in mc) {
  276. let {c,r,cs,rs} = mc[key];
  277. if(bd_r1 <= r + rs - 1 && bd_r1 > r && bd_c >= c && bd_c <= c + cs -1){
  278. borderInfoCompute[bd_r1 + "_" + bd_c].t = null;
  279. }
  280. }
  281. }
  282. }
  283. else if(borderType == "border-bottom"){
  284. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r2] != null) {
  285. continue;
  286. }
  287. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  288. if(borderInfoCompute[bd_r2 + "_" + bd_c] == null){
  289. borderInfoCompute[bd_r2 + "_" + bd_c] = {};
  290. }
  291. borderInfoCompute[bd_r2 + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  292. let bd_r_bottom = bd_r2 + 1;
  293. if(bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]){
  294. if(data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null){
  295. let cell_bottom = data[bd_r_bottom][bd_c];
  296. let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  297. if(mc.r == bd_r_bottom){
  298. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  299. }
  300. }
  301. else{
  302. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  303. }
  304. }
  305. let mc = cfg["merge"] || {};
  306. for (const key in mc) {
  307. let {c,r,cs,rs} = mc[key];
  308. if(bd_r2 < r + rs - 1 && bd_r2 >= r && bd_c >= c && bd_c <= c + cs -1){
  309. borderInfoCompute[bd_r2 + "_" + bd_c].b = null;
  310. }
  311. }
  312. }
  313. }
  314. else if(borderType == "border-all"){
  315. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  316. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  317. continue;
  318. }
  319. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  320. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  321. let cell = data[bd_r][bd_c];
  322. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  323. if(mc==undefined || mc==null){
  324. continue
  325. };
  326. if(mc.r == bd_r){
  327. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  328. borderInfoCompute[bd_r + "_" + bd_c] = {};
  329. }
  330. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  331. }
  332. if(mc.r + mc.rs - 1 == bd_r){
  333. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  334. borderInfoCompute[bd_r + "_" + bd_c] = {};
  335. }
  336. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  337. }
  338. if(mc.c == bd_c){
  339. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  340. borderInfoCompute[bd_r + "_" + bd_c] = {};
  341. }
  342. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  343. }
  344. if(mc.c + mc.cs - 1 == bd_c){
  345. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  346. borderInfoCompute[bd_r + "_" + bd_c] = {};
  347. }
  348. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  349. }
  350. }
  351. else{
  352. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  353. borderInfoCompute[bd_r + "_" + bd_c] = {};
  354. }
  355. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  356. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  357. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  358. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  359. }
  360. if(bd_r == bd_r1){
  361. let bd_r_top = bd_r1 - 1;
  362. if(bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]){
  363. if(data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null){
  364. let cell_top = data[bd_r_top][bd_c];
  365. let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  366. if(mc.r + mc.rs - 1 == bd_r_top){
  367. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  368. }
  369. }
  370. else{
  371. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  372. }
  373. }
  374. }
  375. if(bd_r == bd_r2){
  376. let bd_r_bottom = bd_r2 + 1;
  377. if(bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]){
  378. if(data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null){
  379. let cell_bottom = data[bd_r_bottom][bd_c];
  380. let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  381. if(mc.r == bd_r_bottom){
  382. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  383. }
  384. }
  385. else{
  386. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  387. }
  388. }
  389. }
  390. if(bd_c == bd_c1){
  391. let bd_c_left = bd_c1 - 1;
  392. if(bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]){
  393. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null){
  394. let cell_left = data[bd_r][bd_c_left];
  395. let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  396. if(mc.c + mc.cs - 1 == bd_c_left){
  397. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle };
  398. }
  399. }
  400. else{
  401. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle };
  402. }
  403. }
  404. }
  405. if(bd_c == bd_c2){
  406. let bd_c_right = bd_c2 + 1;
  407. if(bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]){
  408. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null){
  409. let cell_right = data[bd_r][bd_c_right];
  410. let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  411. if(mc.c == bd_c_right){
  412. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle };
  413. }
  414. }
  415. else{
  416. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle };
  417. }
  418. }
  419. }
  420. }
  421. }
  422. }
  423. else if(borderType == "border-outside"){
  424. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  425. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  426. continue;
  427. }
  428. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  429. if(!(bd_r == bd_r1 || bd_r == bd_r2 || bd_c == bd_c1 || bd_c == bd_c2)){
  430. continue;
  431. }
  432. if(bd_r == bd_r1){
  433. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  434. borderInfoCompute[bd_r + "_" + bd_c] = {};
  435. }
  436. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  437. let bd_r_top = bd_r1 - 1;
  438. if(bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]){
  439. if(data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null){
  440. let cell_top = data[bd_r_top][bd_c];
  441. let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  442. if(mc.r + mc.rs - 1 == bd_r_top){
  443. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  444. }
  445. }
  446. else{
  447. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  448. }
  449. }
  450. }
  451. if(bd_r == bd_r2){
  452. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  453. borderInfoCompute[bd_r + "_" + bd_c] = {};
  454. }
  455. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  456. let bd_r_bottom = bd_r2 + 1;
  457. if(bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]){
  458. if(data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null){
  459. let cell_bottom = data[bd_r_bottom][bd_c];
  460. let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  461. if(mc.r == bd_r_bottom){
  462. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  463. }
  464. }
  465. else{
  466. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  467. }
  468. }
  469. }
  470. if(bd_c == bd_c1){
  471. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  472. borderInfoCompute[bd_r + "_" + bd_c] = {};
  473. }
  474. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  475. let bd_c_left = bd_c1 - 1;
  476. if(bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]){
  477. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null){
  478. let cell_left = data[bd_r][bd_c_left];
  479. let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  480. if(mc.c + mc.cs - 1 == bd_c_left){
  481. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle };
  482. }
  483. }
  484. else{
  485. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle };
  486. }
  487. }
  488. }
  489. if(bd_c == bd_c2){
  490. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  491. borderInfoCompute[bd_r + "_" + bd_c] = {};
  492. }
  493. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  494. let bd_c_right = bd_c2 + 1;
  495. if(bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]){
  496. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null){
  497. let cell_right = data[bd_r][bd_c_right];
  498. let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  499. if(mc.c == bd_c_right){
  500. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle };
  501. }
  502. }
  503. else{
  504. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle };
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. else if(borderType == "border-inside"){
  512. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  513. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  514. continue;
  515. }
  516. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  517. if(bd_r == bd_r1 && bd_c == bd_c1){
  518. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  519. }
  520. else{
  521. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  522. borderInfoCompute[bd_r + "_" + bd_c] = {};
  523. }
  524. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  525. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  526. }
  527. }
  528. else if(bd_r == bd_r2 && bd_c == bd_c1){
  529. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  530. }
  531. else{
  532. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  533. borderInfoCompute[bd_r + "_" + bd_c] = {};
  534. }
  535. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  536. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  537. }
  538. }
  539. else if(bd_r == bd_r1 && bd_c == bd_c2){
  540. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  541. }
  542. else{
  543. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  544. borderInfoCompute[bd_r + "_" + bd_c] = {};
  545. }
  546. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  547. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  548. }
  549. }
  550. else if(bd_r == bd_r2 && bd_c == bd_c2){
  551. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  552. }
  553. else{
  554. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  555. borderInfoCompute[bd_r + "_" + bd_c] = {};
  556. }
  557. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  558. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  559. }
  560. }
  561. else if(bd_r == bd_r1){
  562. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  563. let cell = data[bd_r][bd_c];
  564. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  565. if(mc.c == bd_c){
  566. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  567. borderInfoCompute[bd_r + "_" + bd_c] = {};
  568. }
  569. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  570. }
  571. else if(mc.c + mc.cs - 1 == bd_c){
  572. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  573. borderInfoCompute[bd_r + "_" + bd_c] = {};
  574. }
  575. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  576. }
  577. }
  578. else{
  579. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  580. borderInfoCompute[bd_r + "_" + bd_c] = {};
  581. }
  582. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  583. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  584. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  585. }
  586. }
  587. else if(bd_r == bd_r2){
  588. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  589. let cell = data[bd_r][bd_c];
  590. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  591. if(mc.c == bd_c){
  592. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  593. borderInfoCompute[bd_r + "_" + bd_c] = {};
  594. }
  595. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  596. }
  597. else if(mc.c + mc.cs - 1 == bd_c){
  598. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  599. borderInfoCompute[bd_r + "_" + bd_c] = {};
  600. }
  601. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  602. }
  603. }
  604. else{
  605. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  606. borderInfoCompute[bd_r + "_" + bd_c] = {};
  607. }
  608. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  609. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  610. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  611. }
  612. }
  613. else if(bd_c == bd_c1){
  614. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  615. let cell = data[bd_r][bd_c];
  616. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  617. if(mc.r == bd_r){
  618. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  619. borderInfoCompute[bd_r + "_" + bd_c] = {};
  620. }
  621. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  622. }
  623. else if(mc.r + mc.rs - 1 == bd_r){
  624. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  625. borderInfoCompute[bd_r + "_" + bd_c] = {};
  626. }
  627. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  628. }
  629. }
  630. else{
  631. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  632. borderInfoCompute[bd_r + "_" + bd_c] = {};
  633. }
  634. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  635. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  636. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  637. }
  638. }
  639. else if(bd_c == bd_c2){
  640. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  641. let cell = data[bd_r][bd_c];
  642. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  643. if(mc.r == bd_r){
  644. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  645. borderInfoCompute[bd_r + "_" + bd_c] = {};
  646. }
  647. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  648. }
  649. else if(mc.r + mc.rs - 1 == bd_r){
  650. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  651. borderInfoCompute[bd_r + "_" + bd_c] = {};
  652. }
  653. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  654. }
  655. }
  656. else{
  657. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  658. borderInfoCompute[bd_r + "_" + bd_c] = {};
  659. }
  660. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  661. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  662. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  663. }
  664. }
  665. else{
  666. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  667. let cell = data[bd_r][bd_c];
  668. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  669. if(mc.r == bd_r){
  670. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  671. borderInfoCompute[bd_r + "_" + bd_c] = {};
  672. }
  673. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  674. }
  675. else if(mc.r + mc.rs - 1 == bd_r){
  676. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  677. borderInfoCompute[bd_r + "_" + bd_c] = {};
  678. }
  679. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  680. }
  681. if(mc.c == bd_c){
  682. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  683. borderInfoCompute[bd_r + "_" + bd_c] = {};
  684. }
  685. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  686. }
  687. else if(mc.c + mc.cs - 1 == bd_c){
  688. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  689. borderInfoCompute[bd_r + "_" + bd_c] = {};
  690. }
  691. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  692. }
  693. }
  694. else{
  695. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  696. borderInfoCompute[bd_r + "_" + bd_c] = {};
  697. }
  698. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  699. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  700. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  701. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  702. }
  703. }
  704. }
  705. }
  706. }
  707. else if(borderType == "border-horizontal"){
  708. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  709. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  710. continue;
  711. }
  712. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  713. if(bd_r == bd_r1){
  714. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  715. }
  716. else{
  717. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  718. borderInfoCompute[bd_r + "_" + bd_c] = {};
  719. }
  720. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  721. }
  722. }
  723. else if(bd_r == bd_r2){
  724. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  725. }
  726. else{
  727. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  728. borderInfoCompute[bd_r + "_" + bd_c] = {};
  729. }
  730. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  731. }
  732. }
  733. else{
  734. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  735. let cell = data[bd_r][bd_c];
  736. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c];
  737. if(mc.r == bd_r){
  738. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  739. borderInfoCompute[bd_r + "_" + bd_c] = {};
  740. }
  741. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  742. }
  743. else if(mc.r + mc.rs - 1 == bd_r){
  744. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  745. borderInfoCompute[bd_r + "_" + bd_c] = {};
  746. }
  747. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  748. }
  749. }
  750. else{
  751. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  752. borderInfoCompute[bd_r + "_" + bd_c] = {};
  753. }
  754. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle };
  755. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle };
  756. }
  757. }
  758. }
  759. }
  760. }
  761. else if(borderType == "border-vertical"){
  762. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  763. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  764. continue;
  765. }
  766. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  767. if(bd_c == bd_c1){
  768. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  769. }
  770. else{
  771. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  772. borderInfoCompute[bd_r + "_" + bd_c] = {};
  773. }
  774. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  775. }
  776. }
  777. else if(bd_c == bd_c2){
  778. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  779. }
  780. else{
  781. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  782. borderInfoCompute[bd_r + "_" + bd_c] = {};
  783. }
  784. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  785. }
  786. }
  787. else{
  788. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  789. let cell = data[bd_r][bd_c];
  790. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {};
  791. if(mc.c == bd_c){
  792. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  793. borderInfoCompute[bd_r + "_" + bd_c] = {};
  794. }
  795. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  796. }
  797. else if(mc.c + mc.cs - 1 == bd_c){
  798. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  799. borderInfoCompute[bd_r + "_" + bd_c] = {};
  800. }
  801. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  802. }
  803. }
  804. else{
  805. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  806. borderInfoCompute[bd_r + "_" + bd_c] = {};
  807. }
  808. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle };
  809. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle };
  810. }
  811. }
  812. }
  813. }
  814. }
  815. else if(borderType == "border-none"){
  816. for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
  817. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  818. continue;
  819. }
  820. for(let bd_c = bd_c1; bd_c <= bd_c2; bd_c++){
  821. if(borderInfoCompute[bd_r + "_" + bd_c] != null){
  822. delete borderInfoCompute[bd_r + "_" + bd_c];
  823. }
  824. if(bd_r == bd_r1){
  825. let bd_r_top = bd_r1 - 1;
  826. if(bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]){
  827. delete borderInfoCompute[bd_r_top + "_" + bd_c].b;
  828. }
  829. }
  830. if(bd_r == bd_r2){
  831. let bd_r_bottom = bd_r2 + 1;
  832. if(bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]){
  833. delete borderInfoCompute[bd_r_bottom + "_" + bd_c].t;
  834. }
  835. }
  836. if(bd_c == bd_c1){
  837. let bd_c_left = bd_c1 - 1;
  838. if(bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]){
  839. delete borderInfoCompute[bd_r + "_" + bd_c_left].r;
  840. }
  841. }
  842. if(bd_c == bd_c2){
  843. let bd_c_right = bd_c2 + 1;
  844. if(bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]){
  845. delete borderInfoCompute[bd_r + "_" + bd_c_right].l;
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }
  852. }
  853. else if(rangeType == "cell"){
  854. let value = borderInfo[i].value;
  855. let bd_r = value.row_index, bd_c = value.col_index;
  856. if(bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed){
  857. continue;
  858. }
  859. if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
  860. continue;
  861. }
  862. if(value.l != null || value.r != null || value.t != null || value.b != null){
  863. if(borderInfoCompute[bd_r + "_" + bd_c] == null){
  864. borderInfoCompute[bd_r + "_" + bd_c] = {};
  865. }
  866. if(data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null){
  867. let cell = data[bd_r][bd_c];
  868. let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {};
  869. if(value.l != null && bd_c == mc.c){ //左边框
  870. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": value.l.color, "style": value.l.style };
  871. let bd_c_left = bd_c - 1;
  872. if(bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]){
  873. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null){
  874. let cell_left = data[bd_r][bd_c_left];
  875. let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  876. if(mc_l.c + mc_l.cs - 1 == bd_c_left){
  877. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style };
  878. }
  879. }
  880. else{
  881. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style };
  882. }
  883. }
  884. }
  885. else{
  886. borderInfoCompute[bd_r + "_" + bd_c].l = null;
  887. }
  888. if(value.r != null && bd_c == mc.c + mc.cs - 1){ //右边框
  889. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": value.r.color, "style": value.r.style };
  890. let bd_c_right = bd_c + 1;
  891. if(bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]){
  892. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null){
  893. let cell_right = data[bd_r][bd_c_right];
  894. let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  895. if(mc_r.c == bd_c_right){
  896. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style };
  897. }
  898. }
  899. else{
  900. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style };
  901. }
  902. }
  903. }
  904. else{
  905. borderInfoCompute[bd_r + "_" + bd_c].r = null;
  906. }
  907. if(value.t != null && bd_r == mc.r){ //上边框
  908. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": value.t.color, "style": value.t.style };
  909. let bd_r_top = bd_r - 1;
  910. if(bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]){
  911. if(data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null){
  912. let cell_top = data[bd_r_top][bd_c];
  913. let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  914. if(mc_t.r + mc_t.rs - 1 == bd_r_top){
  915. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style };
  916. }
  917. }
  918. else{
  919. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style };
  920. }
  921. }
  922. }
  923. else{
  924. borderInfoCompute[bd_r + "_" + bd_c].t = null;
  925. }
  926. if(value.b != null && bd_r == mc.r + mc.rs - 1){ //下边框
  927. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": value.b.color, "style": value.b.style };
  928. let bd_r_bottom = bd_r + 1;
  929. if(bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]){
  930. if(data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null){
  931. let cell_bottom = data[bd_r_bottom][bd_c];
  932. let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  933. if(mc_b.r == bd_r_bottom){
  934. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style };
  935. }
  936. }
  937. else{
  938. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style };
  939. }
  940. }
  941. }
  942. else{
  943. borderInfoCompute[bd_r + "_" + bd_c].b = null;
  944. }
  945. }
  946. else{
  947. if(value.l != null){ //左边框
  948. borderInfoCompute[bd_r + "_" + bd_c].l = { "color": value.l.color, "style": value.l.style };
  949. let bd_c_left = bd_c - 1;
  950. if(bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]){
  951. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null){
  952. let cell_left = data[bd_r][bd_c_left];
  953. let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c];
  954. if(mc_l.c + mc_l.cs - 1 == bd_c_left){
  955. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style };
  956. }
  957. }
  958. else{
  959. borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style };
  960. }
  961. }
  962. }
  963. else{
  964. borderInfoCompute[bd_r + "_" + bd_c].l = null;
  965. }
  966. if(value.r != null){ //右边框
  967. borderInfoCompute[bd_r + "_" + bd_c].r = { "color": value.r.color, "style": value.r.style };
  968. let bd_c_right = bd_c + 1;
  969. if(bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]){
  970. if(data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null){
  971. let cell_right = data[bd_r][bd_c_right];
  972. let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c];
  973. if(mc_r.c == bd_c_right){
  974. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style };
  975. }
  976. }
  977. else{
  978. borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style };
  979. }
  980. }
  981. }
  982. else{
  983. borderInfoCompute[bd_r + "_" + bd_c].r = null;
  984. }
  985. if(value.t != null){ //上边框
  986. borderInfoCompute[bd_r + "_" + bd_c].t = { "color": value.t.color, "style": value.t.style };
  987. let bd_r_top = bd_r - 1;
  988. if(bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]){
  989. if(data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null){
  990. let cell_top = data[bd_r_top][bd_c];
  991. let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c];
  992. if(mc_t.r + mc_t.rs - 1 == bd_r_top){
  993. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style };
  994. }
  995. }
  996. else{
  997. borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style };
  998. }
  999. }
  1000. }
  1001. else{
  1002. borderInfoCompute[bd_r + "_" + bd_c].t = null;
  1003. }
  1004. if(value.b != null){ //下边框
  1005. borderInfoCompute[bd_r + "_" + bd_c].b = { "color": value.b.color, "style": value.b.style };
  1006. let bd_r_bottom = bd_r + 1;
  1007. if(bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]){
  1008. if(data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null){
  1009. let cell_bottom = data[bd_r_bottom][bd_c];
  1010. let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c];
  1011. if(mc_b.r == bd_r_bottom){
  1012. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style };
  1013. }
  1014. }
  1015. else{
  1016. borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style };
  1017. }
  1018. }
  1019. }
  1020. else{
  1021. borderInfoCompute[bd_r + "_" + bd_c].b = null;
  1022. }
  1023. }
  1024. }
  1025. else{
  1026. delete borderInfoCompute[bd_r + "_" + bd_c];
  1027. }
  1028. }
  1029. }
  1030. }
  1031. return borderInfoCompute;
  1032. }
  1033. //获取数据类型
  1034. var getObjType = function (obj) {
  1035. let toString = Object.prototype.toString;
  1036. let map = {
  1037. '[object Boolean]': 'boolean',
  1038. '[object Number]': 'number',
  1039. '[object String]': 'string',
  1040. '[object Function]': 'function',
  1041. '[object Array]': 'array',
  1042. '[object Date]': 'date',
  1043. '[object RegExp]': 'regExp',
  1044. '[object Undefined]': 'undefined',
  1045. '[object Null]': 'null',
  1046. '[object Object]': 'object'
  1047. }
  1048. return map[toString.call(obj)];
  1049. }
  1050. var setStyleAndValue = function (cellArr, worksheet) {
  1051. if (!Array.isArray(cellArr)) return;
  1052. cellArr.forEach(function (row, rowid) {
  1053. const dbrow = worksheet.getRow(rowid+1);
  1054. //设置单元格行高,默认乘以1倍
  1055. dbrow.height=luckysheet.getRowHeight([rowid])[rowid]
  1056. row.every(function (cell, columnid) {
  1057. if (!cell) return true;
  1058. if(rowid==0){
  1059. const dobCol = worksheet.getColumn(columnid+1);
  1060. //设置单元格列宽除以8
  1061. dobCol.width=luckysheet.getColumnWidth([columnid])[columnid]/8
  1062. }
  1063. let fill = fillConvert(cell.bg);
  1064. let font = fontConvert(cell.ff, cell.fc, cell.bl, cell.it, cell.fs, cell.cl, cell.ul);
  1065. let alignment = alignmentConvert(cell.vt, cell.ht, cell.tb, cell.tr);
  1066. let value;
  1067. var v='';
  1068. if(cell.ct&&cell.ct.t=='inlineStr'){
  1069. var s=cell.ct.s;
  1070. s.forEach(function(val,num){
  1071. v+=val.v;
  1072. })
  1073. }else{
  1074. v=cell.v;
  1075. }
  1076. if (cell.f) {
  1077. value = { formula: cell.f, result: v };
  1078. } else {
  1079. value = v;
  1080. }
  1081. let target = worksheet.getCell(rowid + 1, columnid + 1);
  1082. target.fill = fill;
  1083. target.font = font;
  1084. target.alignment = alignment;
  1085. target.value = value;
  1086. return true;
  1087. })
  1088. })
  1089. }
  1090. //转换颜色
  1091. var rgb2hex =function(rgb) {
  1092. if (rgb.charAt(0) == '#'){
  1093. return rgb;
  1094. }
  1095. var ds = rgb.split(/\D+/);
  1096. var decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]);
  1097. return "#" + zero_fill_hex(decimal, 6);
  1098. function zero_fill_hex(num, digits) {
  1099. var s = num.toString(16);
  1100. while (s.length < digits)
  1101. s = "0" + s;
  1102. return s;
  1103. }
  1104. }
  1105. var fillConvert = function (bg) {
  1106. if (!bg) {
  1107. return null;
  1108. // return {
  1109. // type: 'pattern',
  1110. // pattern: 'solid',
  1111. // fgColor:{argb:'#ffffff'.replace('#','')}
  1112. // }
  1113. }
  1114. bg = bg.indexOf('rgb')>-1 ?rgb2hex(bg):bg;
  1115. let fill = {
  1116. type: 'pattern',
  1117. pattern: 'solid',
  1118. fgColor: {argb: bg.replace('#', '')}
  1119. }
  1120. return fill
  1121. }
  1122. var fontConvert = function (ff = 0, fc = '#000000', bl = 0, it = 0, fs = 10, cl = 0, ul = 0) { // luckysheet:ff(样式), fc(颜色), bl(粗体), it(斜体), fs(大小), cl(删除线), ul(下划线)
  1123. const luckyToExcel = {
  1124. 0: '微软雅黑',
  1125. 1: '宋体(Song)',
  1126. 2: '黑体(ST Heiti)',
  1127. 3: '楷体(ST Kaiti)',
  1128. 4: '仿宋(ST FangSong)',
  1129. 5: '新宋体(ST Song)',
  1130. 6: '华文新魏',
  1131. 7: '华文行楷',
  1132. 8: '华文隶书',
  1133. 9: 'Arial',
  1134. 10: 'Times New Roman ',
  1135. 11: 'Tahoma ',
  1136. 12: 'Verdana',
  1137. num2bl: function (num) {
  1138. return num === 0 ? false : true
  1139. }
  1140. }
  1141. let font = {
  1142. name:ff,
  1143. family: 1,
  1144. size: fs,
  1145. color: {argb: fc.replace('#', '')},
  1146. bold: luckyToExcel.num2bl(bl),
  1147. italic: luckyToExcel.num2bl(it),
  1148. underline: luckyToExcel.num2bl(ul),
  1149. strike: luckyToExcel.num2bl(cl)
  1150. }
  1151. return font;
  1152. }
  1153. var alignmentConvert = function (vt = 'default', ht = 'default', tb = 'default', tr = 'default') { // luckysheet:vt(垂直), ht(水平), tb(换行), tr(旋转)
  1154. const luckyToExcel = {
  1155. vertical: {
  1156. 0: 'middle',
  1157. 1: 'top',
  1158. 2: 'bottom',
  1159. default: 'middle'
  1160. },
  1161. horizontal: {
  1162. 0: 'center',
  1163. 1: 'left',
  1164. 2: 'right',
  1165. default: 'left'
  1166. },
  1167. wrapText: {
  1168. 0: false,
  1169. 1: false,
  1170. 2: true,
  1171. default: false
  1172. },
  1173. textRotation: {
  1174. 0: 0,
  1175. 1: 45,
  1176. 2: -45,
  1177. 3: 'vertical',
  1178. 4: 90,
  1179. 5: -90,
  1180. default: 0
  1181. }
  1182. }
  1183. let alignment = {
  1184. vertical: luckyToExcel.vertical[vt],
  1185. horizontal: luckyToExcel.horizontal[ht],
  1186. wrapText: luckyToExcel.wrapText[tb],
  1187. textRotation: luckyToExcel.textRotation[tr]
  1188. }
  1189. return alignment;
  1190. }
  1191. export { exportExcel }