Commit 36eeaaf5 authored by 宁天庆's avatar 宁天庆

修改代码

parent 7182b0e5
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -6912,3 +6912,319 @@ export function checkTheStatusOfTheSelectedCells(type, status) { ...@@ -6912,3 +6912,319 @@ export function checkTheStatusOfTheSelectedCells(type, status) {
return flag; return flag;
} }
/**
* 获取当前屏幕dpi
* @returns dpi
*/
function getDPI() {
var tempDiv = document.createElement("div");
tempDiv.style.width = "1in";
tempDiv.style.visibility = "hidden";
document.body.appendChild(tempDiv);
var dpi = tempDiv.offsetWidth;
document.body.removeChild(tempDiv);
return dpi;
}
/**
* 毫米转像素
* @param {int} mm 毫米
* @param {int} dpi dpi
* @returns
*/
function mmToPixel(mm, dpi) {
// 1 inch = 25.4 mm
var inches = mm / 25.4;
var pixels = inches * dpi;
return Math.round(pixels);
}
function calculateA4PaperSize() {
var dpi = getDPI();
var width_mm = 210; // A4纸宽度,单位:毫米
var height_mm = 297; // A4纸高度,单位:毫米
var width_px = mmToPixel(width_mm, dpi);
var height_px = mmToPixel(height_mm, dpi);
return { width: width_px, height: height_px };
}
/**
* 补上左边框和上边框
*/
const addLeftAndTopBorders = (ctx, rowIndexs, columnIndexs, borderInfo) => {
let visibledatarow = Store.visibledatarow;
let visibledatacolumn = Store.visibledatacolumn;
function drawBorder(r, c, pos, border) {
ctx.beginPath();
const startTop = visibledatarow[r - 1] || 0;
const startLeft = visibledatacolumn[c - 1] || 0;
const cellheight = visibledatarow[r] - startTop;
const cellWidth = visibledatacolumn[c] - startLeft;
const devicePixelRatio = Store.devicePixelRatio;
ctx.moveTo(startTop, startLeft);
if (pos === 'left') {
menuButton.setLineDash(ctx, border.style, 'v',
startLeft * devicePixelRatio,
startTop * devicePixelRatio,
(startLeft + cellWidth) * devicePixelRatio,
startTop * devicePixelRatio,
true
);
}
if (pos === 'top') {
menuButton.setLineDash(ctx, border.style, 'h',
startLeft * devicePixelRatio,
startTop * devicePixelRatio,
startLeft * devicePixelRatio,
(startTop + cellheight) * devicePixelRatio,
true
);
}
ctx.strokeStyle = border.color;
ctx.stroke();
ctx.closePath();
}
function getCellBorderInfo(r, c, pos, filters) {
let res = {};
[...borderInfo || []].reverse().find(e => {
if (e.rangeType === 'range') {
const { row, column } = e.range[0];
if (!filters.includes(e.borderType)) {
if (row[0] <= r && row[1] >= r && column[0] <= c && column[1] >= c) {
res = { color: e.color, style: e.style, borderType: e.borderType };
return true;
}
}
return false;
}
if (e.rangeType === 'cell') {
const { col_index, row_index, l, t } = e.value || {};
if (col_index === c && row_index === r) {
if (pos === 'top') {
if (t) {
res = t;
return true;
}
}
if (pos === 'left') {
if (l) {
res = t;
return true;
}
}
}
}
return null;
});
return res;
}
for (let r = rowIndexs[0]; r <= rowIndexs[1]; r++) {
for (let c = columnIndexs[0]; c <= columnIndexs[1]; c++) {
if (c === 0) {
const border = getCellBorderInfo(r, c, 'top',
['border-left', 'border-right', 'border-bottom', 'border-inside', 'border-horizontal', 'border-vertical']);
border && border.borderType !== 'border-none' && console.log(r, c, 'top', border)
border && border.borderType !== 'border-none' && drawBorder(r, c, 'top', border);
}
if (r === 0) {
const border = getCellBorderInfo(r, c, 'left',
['border-top', 'border-right', 'border-bottom', 'border-inside', 'border-horizontal', 'border-vertical']);
border && border.borderType !== 'border-none' && console.log(r, c, 'left', border)
border && border.borderType !== 'border-none' && drawBorder(r, c, 'left', border);
}
}
}
};
/**
* 将选中区域进行截图,截图完成后调用指定委托函数,(修复支持插入的图片及图表截图):ALAN-JI
* @param {Object} options 可选参数
* @param {Object | String} options.range 选区范围,只能为单个选区;默认为当前选区
* @param {function} action 委托执行函数,当所有绘图完成后,执行此委托函数(委托函数中可用于触发图片打印,或图片显示)
*/
export function getScreenshotWithImg(action, options = {}) {
let {
range = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1],
} = { ...options }
if (getObjType(range) == 'string') {
if (!formula.iscelldata(range)) {
return tooltip.info("The range parameter is invalid.", "");
}
let cellrange = formula.getcellrange(range);
range = {
"row": cellrange.row,
"column": cellrange.column
};
}
if (getObjType(range) != 'object' || range.row == null || range.column == null) {
return tooltip.info("The range parameter is invalid.", "");
}
let str = range.row[0],
edr = range.row[1],
stc = range.column[0],
edc = range.column[1];
let has_PartMC = hasPartMC(Store.config, str, edr, stc, edc);
if (has_PartMC) {
return tooltip.info('Cannot perform this operation on partially merged cells', '');
}
let visibledatarow = Store.visibledatarow;
let visibledatacolumn = Store.visibledatacolumn;
let scrollHeight, rh_height;
if (str - 1 < 0) {
scrollHeight = 0;
rh_height = visibledatarow[edr];
}
else {
scrollHeight = visibledatarow[str - 1];
rh_height = visibledatarow[edr] - visibledatarow[str - 1];
}
//根据当前分辨率计算出A4纸宽度,高度(高度不用限制,默认会自动分页)
let a4Size = calculateA4PaperSize();
let scrollWidth, ch_width = a4Size.width;
if (stc - 1 < 0) {
scrollWidth = 0;
// ch_width = visibledatacolumn[edc] < a4Size.width ? visibledatacolumn[edc] : a4Size.width;
ch_width = visibledatacolumn[edc];
}
else {
scrollWidth = visibledatacolumn[stc - 1];
// ch_width = visibledatacolumn[edc] - visibledatacolumn[stc - 1] < a4Size.width ? visibledatacolumn[edc] - visibledatacolumn[stc - 1] : a4Size.width;
ch_width = visibledatacolumn[edc] - visibledatacolumn[stc - 1];
}
let newCanvas = $("<canvas>").attr({
width: Math.ceil(ch_width * Store.devicePixelRatio),
height: Math.ceil(rh_height * Store.devicePixelRatio)
}).css({ width: ch_width, height: rh_height });
luckysheetDrawMain(scrollWidth, scrollHeight, ch_width, rh_height, 1, 1, null, null, newCanvas);
//补上 左边框和上边框
let ctx_newCanvas = newCanvas.get(0).getContext("2d");
addLeftAndTopBorders(ctx_newCanvas, range.row, range.column, Store.config.borderInfo);
// ctx_newCanvas.beginPath();
// ctx_newCanvas.moveTo(
// 0,
// 0
// );
// ctx_newCanvas.lineTo(
// 0,
// Store.devicePixelRatio * rh_height
// );
// ctx_newCanvas.lineWidth = Store.devicePixelRatio * 2;
// ctx_newCanvas.strokeStyle = luckysheetdefaultstyle.strokeStyle;
// ctx_newCanvas.stroke();
// ctx_newCanvas.closePath();
// ctx_newCanvas.beginPath();
// ctx_newCanvas.moveTo(
// 0,
// 0
// );
// ctx_newCanvas.lineTo(
// Store.devicePixelRatio * ch_width,
// 0
// );
// ctx_newCanvas.lineWidth = Store.devicePixelRatio * 2;
// ctx_newCanvas.strokeStyle = luckysheetdefaultstyle.strokeStyle;
// ctx_newCanvas.stroke();
// ctx_newCanvas.closePath();
//获取插入图片的元素,并在canvas上进行绘制
if ($('#luckysheet-image-showBoxs')) {
var imgs = $('#luckysheet-image-showBoxs img');
imgs.each(function(i) {
var parent = $(this).parent().parent();
var left = parent.css("left").replace('px', '');
var top = parent.css("top").replace('px', '');
var width = parent.css("width").replace('px', '');
var height = parent.css("height").replace('px', '');
var img = new Image()
img.src = $(this).attr("src");
ctx_newCanvas.drawImage(img, left, top, width, height);
});
}
//获取统计图元素,并在canvas上进行绘制
let targetDoms = document.querySelectorAll('.luckysheet-modal-dialog.luckysheet-modal-dialog-chart.luckysheet-data-visualization-chart');
var chartCount = 0;
if (targetDoms && targetDoms.length > 0) {
repaintChartScreenshot(newCanvas, ctx_newCanvas, targetDoms, action, 0, targetDoms.length);
}
if (!targetDoms || targetDoms.length == 0) {
if (action) {
action(newCanvas.get(0).toDataURL("image/png", 1));
}
}
}
/**
* 递归获取所有统计图,并重绘chart到截屏图上:ALAN-JI
* @param {object} newCanvas canvas画布元素对象
* @param {object} ctx_newCanvas 当前画布用于绘制新图的对象
* @param {NodeListOf} targetDoms 所有统计图Nodes集合
* @param {function} action 委托函数,当所有绘图完成后,执行此委托函数(委托函数中可用于触发图片打印,或图片显示)
* @param {int} index 当前统计图下标
* @param {int} length 统计图总集合长度
*/
export function repaintChartScreenshot(newCanvas, ctx_newCanvas, targetDoms, action, index, length) {
let targetDom = targetDoms[index];
var left = targetDom.style.left.replace('px', '');
var top = targetDom.style.top.replace('px', '');
var width = targetDom.style.width.replace('px', '');
var height = targetDom.style.height.replace('px', '');
// 此处是实现滚动元素长截图的关键 start
let copyDom = targetDom.cloneNode(true)
copyDom.setAttribute('id', 'copyDom') // 更改id 避免与targetDom id重复
copyDom.style.width = targetDom.scrollWidth + 'px'
copyDom.style.height = targetDom.scrollHeight + 'px'
var chartCanvas = targetDom.getElementsByTagName("canvas")[0];
var canvasToImg = new Image();
canvasToImg.src = chartCanvas.toDataURL('image/png', 1);
canvasToImg.style = chartCanvas.style;
copyDom.innerHTML = copyDom.innerHTML.replace(chartCanvas.outerHTML, canvasToImg.outerHTML)
copyDom.style.zIndex = -50
document.querySelector('body').appendChild(copyDom);
// 此处是实现滚动元素长截图的关键 end
/*
*如不需要长截图,或者要截取的元素无滚动即完全显示。
*下方要截取的元素改为targetDom,并把copyDom相关代码删除即可
*/
// html2canvas截屏,屏幕有滚动条时截图为空
html2canvas(copyDom, {
backgroundColor: "transparent",
allowTaint: true,
useCORS: true,
scale: window.devicePixelRatio * 3,
logging: false,
imageTimeout: 15000,
removeContainer: true,
}).then(canvas => {
var chartImg = new Image()
chartImg.src = canvas.toDataURL('image/png', 1);
document.querySelector('body').removeChild(copyDom)
chartImg.onload = function() {
index++;
ctx_newCanvas.drawImage(chartImg, left, top, width, height);
if (index >= length && action) {
action(newCanvas.get(0).toDataURL("image/png", 1));
}
else {
//递归调用重绘图片
repaintChartScreenshot(newCanvas, ctx_newCanvas, targetDoms, action, index, length);
}
}
});
}
import Excel from 'exceljs'; import Excel from 'exceljs';
async function exportSheetExcel(luckysheet, name = "file") { // 参数为luckysheet.getluckysheetfile()获取的对象
async function exportSheetExcel(luckysheet, name = 'file') { // 参数为luckysheet.getluckysheetfile()获取的对象
// 1.创建工作簿,可以为工作簿添加属性 // 1.创建工作簿,可以为工作簿添加属性
const workbook = new Excel.Workbook(); const workbook = new Excel.Workbook();
// 2.创建表格,第二个参数可以配置创建什么样的工作表 // 2.创建表格,第二个参数可以配置创建什么样的工作表
[luckysheet[0]].map(function(table) { const promiseArray = [luckysheet[0]].map(async (table) => {
if (table.data.length === 0) return true; if (table.data.length === 0) { return true; }
const worksheet = workbook.addWorksheet(name); const worksheet = workbook.addWorksheet(name);
// 3.设置单元格合并,设置单元格边框,设置单元格样式,设置值 // 3.设置单元格合并,设置单元格边框,设置单元格样式,设置值
setStyleAndValue(table.data, worksheet); setStyleAndValue(table.data, worksheet);
setMerge(table.config.merge, worksheet); setMerge(table.config.merge, worksheet);
setBorder(table, worksheet); setBorder(table, worksheet);
setImages(table, worksheet, workbook); setHyperlink(table.hyperlink, worksheet, table.data);
await setImages(table, worksheet, workbook);
return true; return true;
}) });
await Promise.all(promiseArray);
// 4.写入 buffer // 4.写入 buffer
const buffer = await workbook.xlsx.writeBuffer(); const buffer = await workbook.xlsx.writeBuffer();
// 5.保存为文件 // 5.保存为文件
saveFile(buffer, name); saveFile(buffer, name);
} }
var saveFile = function(buf, name) { const saveFile = function(buf, name) {
let blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }); let blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' });
const downloadElement = document.createElement('a'); const downloadElement = document.createElement('a');
let href = window.URL.createObjectURL(blob); let href = window.URL.createObjectURL(blob);
downloadElement.href = href; downloadElement.href = href;
downloadElement.download = name + ".xlsx"; // 文件名字 downloadElement.download = `${name}.xlsx`; // 文件名字
document.body.appendChild(downloadElement); document.body.appendChild(downloadElement);
downloadElement.click(); downloadElement.click();
document.body.removeChild(downloadElement); // 下载完成移除元素 document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(href); // 释放掉blob对象 window.URL.revokeObjectURL(href); // 释放掉blob对象
} };
function setHyperlink(hyperlink, worksheet, data) {
if (!hyperlink) {
return;
}
for (const key in hyperlink) {
// key 的格式通常是 "行号_列号",例如 "0_0" 表示 A1 单元格
const [rowIndex, colIndex] = key.split('_').map(Number);
const cell = worksheet.getCell(rowIndex + 1, colIndex + 1); // ExcelJS 行列索引从1开始
const linkInfo = hyperlink[key];
// 设置单元格值为超链接对象
if (linkInfo.linkType === 'external') {
// 外部链接
cell.value = {
text: cell.value || linkInfo.linkTooltip || '链接', // 显示的文本
hyperlink: linkInfo.linkAddress, // 链接地址
tooltip: linkInfo.linkTooltip // 鼠标悬停提示(可选)
};
} else {
// 内部链接(指向本工作簿的其他位置)
// 注意:ExcelJS 可能需要特定的内部链接格式,如 `'Sheet2!A1'`
cell.value = {
text: cell.value || '内部链接',
hyperlink: `'${linkInfo.linkAddress}'` // 例如处理为 "'SheetName!A1'"
};
}
const celldata = data[rowIndex][colIndex];
let color = !celldata.fc ? '' : `${celldata.fc}`.indexOf('rgb') > -1 ? rgb2hex(celldata.fc) : celldata.fc;
// (可选)为超链接设置特定字体样式,如蓝色和下划线
console.log('color', color, celldata);
cell.font = {
...cell.font, // 保留原有字体属性
color: { argb: color.replace('#', '') || 'FF000000' }, // 蓝色
underline: true
};
}
}
var setMerge = function(luckyMerge = {}, worksheet) { const setMerge = function(luckyMerge = {}, worksheet) {
const mergearr = Object.values(luckyMerge); const mergearr = Object.values(luckyMerge);
mergearr.forEach(function(elem) { // elem格式:{r: 0, c: 0, rs: 1, cs: 2} mergearr.forEach((elem) => { // elem格式:{r: 0, c: 0, rs: 1, cs: 2}
// 按开始行,开始列,结束行,结束列合并(相当于 K10:M12) // 按开始行,开始列,结束行,结束列合并(相当于 K10:M12)
worksheet.mergeCells(elem.r + 1, elem.c + 1, elem.r + elem.rs, elem.c + elem.cs); worksheet.mergeCells(elem.r + 1, elem.c + 1, elem.r + elem.rs, elem.c + elem.cs);
}); });
} };
let getImagePosition = (num, arr) => {
//获取图片在单元格的位置
var getImagePosition = function(num, arr) {
let index = 0; let index = 0;
let minIndex; let total = 0;
let maxIndex;
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
if (num < arr[i]) { total = arr[i];
if (num < total) {
index = i; index = i;
break; break;
} }
}
if (index == 0) {
minIndex = 0;
maxIndex = 1;
return Math.abs((num - 0) / (arr[maxIndex] - arr[minIndex])) + index;
} }
else if (index == arr.length - 1) { if (index === 0) {
minIndex = arr.length - 2; return [0, num];
maxIndex = arr.length - 1; } else {
return [index, num - arr[index - 1]];
} }
else { };
minIndex = index - 1; function getDPIWithCSS() {
maxIndex = index; // 创建一个隐藏的div元素并设置其宽度为1英寸
} const div = document.createElement('div');
let min = arr[minIndex]; div.style.width = '1in';
let max = arr[maxIndex]; div.style.height = '1in';
let radio = Math.abs((num - min) / (max - min)) + index div.style.position = 'absolute';
return radio; div.style.left = '-100%';
div.style.top = '-100%';
div.style.visibility = 'hidden'; // 隐藏元素避免影响布局[6](@ref)
// 将元素添加到文档中
document.body.appendChild(div);
// 获取元素的像素宽度,这直接对应于1英寸包含的像素数,即DPI[6](@ref)
const dpi = div.offsetWidth;
// 清理:从文档中移除该元素
document.body.removeChild(div);
return dpi;
} }
/**
var setImages = function(table, worksheet, workbook) { * 将像素值转换为EMU
* @param {number} px - 像素值
* @returns {number} EMU值
*/
function pxToEMU(px) {
const EMU_PER_INCH = 914400;
return Math.round(px * EMU_PER_INCH / getDPIWithCSS());
}
const setImages = async function(table, worksheet, workbook) {
let { let {
images, images,
visibledatacolumn,//所有行的位置 visibledatacolumn,// 所有行的位置
visibledatarow //所有列的位置 visibledatarow // 所有列的位置
} = { ...table } } = { ...table };
if (typeof images != 'object') return; if (typeof images != 'object') {
return;
}
for (let key in images) { for (let key in images) {
// 通过 base64 将图像添加到工作簿 // 通过 base64 将图像添加到工作簿
const myBase64Image = images[key].src; const myBase64Image = await urlToBase64HighPerformance(images[key].src);
//开始行 开始列 结束行 结束列 // 开始行 开始列 结束行 结束列
const item = images[key]; const item = images[key];
const imageId = workbook.addImage({ const imageId = workbook.addImage({
base64: myBase64Image, base64: myBase64Image,
extension: 'png' extension: 'png'
}); });
const [nativeCol, nativeColOffPx] = getImagePosition(item.default.left, visibledatacolumn);
const col_st = getImagePosition(item.default.left, visibledatacolumn); const [nativeRow, nativeRowOffPx] = getImagePosition(item.default.top, visibledatarow);
const row_st = getImagePosition(item.default.top, visibledatarow); // 模式1,图片左侧与luckysheet位置一样,像素比例保持不变,但是,右侧位置可能与原图所在单元格不一致
//模式1,图片左侧与luckysheet位置一样,像素比例保持不变,但是,右侧位置可能与原图所在单元格不一致
worksheet.addImage(imageId, { worksheet.addImage(imageId, {
tl: { col: col_st, row: row_st }, // tl: { col: col_st, row: row_st },
ext: { width: item.default.width, height: item.default.height }, tl: {
nativeCol, // 第2列(B列),从0开始索引
nativeColOff: pxToEMU(nativeColOffPx), // 水平偏移量(EMU)
nativeRow, // 第3行
nativeRowOff: pxToEMU(nativeRowOffPx) // 垂直偏移量(EMU)
},
// br: { col: 3.5, row: 5.5 },
ext: { width: item.default.width, height: item.default.height }
}); });
//模式2,图片四个角位置没有变动,但是图片像素比例可能和原图不一样 // 模式2,图片四个角位置没有变动,但是图片像素比例可能和原图不一样
// const w_ed = item.default.left+item.default.width; // const w_ed = item.default.left+item.default.width;
// const h_ed = item.default.top+item.default.height; // const h_ed = item.default.top+item.default.height;
// const col_ed = getImagePosition(w_ed,visibledatacolumn); // const col_ed = getImagePosition(w_ed,visibledatacolumn);
...@@ -108,8 +173,8 @@ var setImages = function(table, worksheet, workbook) { ...@@ -108,8 +173,8 @@ var setImages = function(table, worksheet, workbook) {
} }
}; };
var setBorder = function(lucksheetfile, worksheet) { const setBorder = function(lucksheetfile, worksheet) {
if (!lucksheetfile) return; if (!lucksheetfile) { return; }
const luckyToExcel = { const luckyToExcel = {
style: { style: {
0: 'none', 0: 'none',
...@@ -127,8 +192,8 @@ var setBorder = function(lucksheetfile, worksheet) { ...@@ -127,8 +192,8 @@ var setBorder = function(lucksheetfile, worksheet) {
12: 'slantDashDot', 12: 'slantDashDot',
13: 'thick' 13: 'thick'
} }
} };
//获取所有的单元格边框的信息 // 获取所有的单元格边框的信息
const borderInfoCompute = getBorderInfo(lucksheetfile); const borderInfoCompute = getBorderInfo(lucksheetfile);
for (let x in borderInfoCompute) { for (let x in borderInfoCompute) {
let border = {}; let border = {};
...@@ -137,36 +202,36 @@ var setBorder = function(lucksheetfile, worksheet) { ...@@ -137,36 +202,36 @@ var setBorder = function(lucksheetfile, worksheet) {
let column = parseInt(x.substr(x.indexOf('_') + 1)); let column = parseInt(x.substr(x.indexOf('_') + 1));
if (info.t != undefined) { if (info.t != undefined) {
const tcolor = info.t.color.indexOf('rgb') > -1 ? rgb2hex(info.t.color) : info.t.color; const tcolor = info.t.color.indexOf('rgb') > -1 ? rgb2hex(info.t.color) : info.t.color;
border['top'] = { style: luckyToExcel.style[info.t.style], color: { argb: tcolor.replace('#', '') } }; border.top = { style: luckyToExcel.style[info.t.style], color: { argb: tcolor.replace('#', '') } };
} }
if (info.r != undefined) { if (info.r != undefined) {
const rcolor = info.r.color.indexOf('rgb') > -1 ? rgb2hex(info.r.color) : info.r.color; const rcolor = info.r.color.indexOf('rgb') > -1 ? rgb2hex(info.r.color) : info.r.color;
border['right'] = { style: luckyToExcel.style[info.r.style], color: { argb: rcolor.replace('#', '') } }; border.right = { style: luckyToExcel.style[info.r.style], color: { argb: rcolor.replace('#', '') } };
} }
if (info.b != undefined) { if (info.b != undefined) {
const bcolor = info.b.color.indexOf('rgb') > -1 ? rgb2hex(info.b.color) : info.b.color; const bcolor = info.b.color.indexOf('rgb') > -1 ? rgb2hex(info.b.color) : info.b.color;
border['bottom'] = { style: luckyToExcel.style[info.b.style], color: { argb: bcolor.replace('#', '') } }; border.bottom = { style: luckyToExcel.style[info.b.style], color: { argb: bcolor.replace('#', '') } };
} }
if (info.l != undefined) { if (info.l != undefined) {
const lcolor = info.l.color.indexOf('rgb') > -1 ? rgb2hex(info.l.color) : info.l.color; const lcolor = info.l.color.indexOf('rgb') > -1 ? rgb2hex(info.l.color) : info.l.color;
border['left'] = { style: luckyToExcel.style[info.l.style], color: { argb: lcolor.replace('#', '') } }; border.left = { style: luckyToExcel.style[info.l.style], color: { argb: lcolor.replace('#', '') } };
} }
worksheet.getCell(row + 1, column + 1).border = border; worksheet.getCell(row + 1, column + 1).border = border;
} }
} };
var getBorderInfo = function(luckysheetfile) { const getBorderInfo = function(luckysheetfile) {
let borderInfoCompute = {}; let borderInfoCompute = {};
let cfg = luckysheetfile.config; let cfg = luckysheetfile.config;
let data = luckysheetfile.data; let data = luckysheetfile.data;
let borderInfo = cfg["borderInfo"]; let borderInfo = cfg.borderInfo;
//设置需要计算边框的区域 // 设置需要计算边框的区域
let dataset_row_st = 0, dataset_row_ed = data.length, dataset_col_st = 0, dataset_col_ed = data[0].length; let dataset_row_st = 0; let dataset_row_ed = data.length; let dataset_col_st = 0; let dataset_col_ed = data[0].length;
if (borderInfo != null && borderInfo.length > 0) { if (borderInfo != null && borderInfo.length > 0) {
for (let i = 0; i < borderInfo.length; i++) { for (let i = 0; i < borderInfo.length; i++) {
let rangeType = borderInfo[i].rangeType; let rangeType = borderInfo[i].rangeType;
if (rangeType == "range") { if (rangeType == 'range') {
let borderType = borderInfo[i].borderType; let borderType = borderInfo[i].borderType;
let borderColor = borderInfo[i].color; let borderColor = borderInfo[i].color;
let borderStyle = borderInfo[i].style; let borderStyle = borderInfo[i].style;
...@@ -174,8 +239,8 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -174,8 +239,8 @@ var getBorderInfo = function(luckysheetfile) {
let borderRange = borderInfo[i].range; let borderRange = borderInfo[i].range;
for (let j = 0; j < borderRange.length; j++) { for (let j = 0; j < borderRange.length; j++) {
let bd_r1 = borderRange[j].row[0], bd_r2 = borderRange[j].row[1]; let bd_r1 = borderRange[j].row[0]; let bd_r2 = borderRange[j].row[1];
let bd_c1 = borderRange[j].column[0], bd_c2 = borderRange[j].column[1]; let bd_c1 = borderRange[j].column[0]; let bd_c2 = borderRange[j].column[1];
if (bd_r1 < dataset_row_st) { if (bd_r1 < dataset_row_st) {
bd_r1 = dataset_row_st; bd_r1 = dataset_row_st;
...@@ -193,229 +258,229 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -193,229 +258,229 @@ var getBorderInfo = function(luckysheetfile) {
bd_c2 = dataset_col_ed; bd_c2 = dataset_col_ed;
} }
if (borderType == "border-left") { if (borderType == 'border-left') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
if (borderInfoCompute[bd_r + "_" + bd_c1] == null) { if (borderInfoCompute[`${bd_r}_${bd_c1}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c1] = {}; borderInfoCompute[`${bd_r}_${bd_c1}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c1].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c1}`].l = { 'color': borderColor, 'style': borderStyle };
let bd_c_left = bd_c1 - 1; let bd_c_left = bd_c1 - 1;
if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) { if (bd_c_left >= 0 && borderInfoCompute[`${bd_r}_${bd_c_left}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == 'object' && data[bd_r][bd_c_left].mc != null) {
let cell_left = data[bd_r][bd_c_left]; let cell_left = data[bd_r][bd_c_left];
let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c]; let mc = cfg.merge[`${cell_left.mc.r}_${cell_left.mc.c}`];
if (mc.c + mc.cs - 1 == bd_c_left) { if (mc.c + mc.cs - 1 == bd_c_left) {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
let mc = cfg["merge"] || {}; let mc = cfg.merge || {};
for (const key in mc) { for (const key in mc) {
let { c, r, cs, rs } = mc[key]; let { c, r, cs, rs } = mc[key];
if (bd_c1 <= c + cs - 1 && bd_c1 > c && bd_r >= r && bd_r <= r + rs - 1) { if (bd_c1 <= c + cs - 1 && bd_c1 > c && bd_r >= r && bd_r <= r + rs - 1) {
borderInfoCompute[bd_r + "_" + bd_c1].l = null; borderInfoCompute[`${bd_r}_${bd_c1}`].l = null;
} }
} }
} }
} }
else if (borderType == "border-right") { else if (borderType == 'border-right') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
if (borderInfoCompute[bd_r + "_" + bd_c2] == null) { if (borderInfoCompute[`${bd_r}_${bd_c2}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c2] = {}; borderInfoCompute[`${bd_r}_${bd_c2}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c2].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c2}`].r = { 'color': borderColor, 'style': borderStyle };
let bd_c_right = bd_c2 + 1; let bd_c_right = bd_c2 + 1;
if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) { if (bd_c_right < data[0].length && borderInfoCompute[`${bd_r}_${bd_c_right}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == 'object' && data[bd_r][bd_c_right].mc != null) {
let cell_right = data[bd_r][bd_c_right]; let cell_right = data[bd_r][bd_c_right];
let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c]; let mc = cfg.merge[`${cell_right.mc.r}_${cell_right.mc.c}`];
if (mc.c == bd_c_right) { if (mc.c == bd_c_right) {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
let mc = cfg["merge"] || {}; let mc = cfg.merge || {};
for (const key in mc) { for (const key in mc) {
let { c, r, cs, rs } = mc[key]; let { c, r, cs, rs } = mc[key];
if (bd_c2 < c + cs - 1 && bd_c2 >= c && bd_r >= r && bd_r <= r + rs - 1) { if (bd_c2 < c + cs - 1 && bd_c2 >= c && bd_r >= r && bd_r <= r + rs - 1) {
borderInfoCompute[bd_r + "_" + bd_c2].r = null; borderInfoCompute[`${bd_r}_${bd_c2}`].r = null;
} }
} }
} }
} }
else if (borderType == "border-top") { else if (borderType == 'border-top') {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r1] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r1] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (borderInfoCompute[bd_r1 + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r1}_${bd_c}`] == null) {
borderInfoCompute[bd_r1 + "_" + bd_c] = {}; borderInfoCompute[`${bd_r1}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r1 + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r1}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
let bd_r_top = bd_r1 - 1; let bd_r_top = bd_r1 - 1;
if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) { if (bd_r_top >= 0 && borderInfoCompute[`${bd_r_top}_${bd_c}`]) {
if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) { if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == 'object' && data[bd_r_top][bd_c].mc != null) {
let cell_top = data[bd_r_top][bd_c]; let cell_top = data[bd_r_top][bd_c];
let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c]; let mc = cfg.merge[`${cell_top.mc.r}_${cell_top.mc.c}`];
if (mc.r + mc.rs - 1 == bd_r_top) { if (mc.r + mc.rs - 1 == bd_r_top) {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
let mc = cfg["merge"] || {}; let mc = cfg.merge || {};
for (const key in mc) { for (const key in mc) {
let { c, r, cs, rs } = mc[key]; let { c, r, cs, rs } = mc[key];
if (bd_r1 <= r + rs - 1 && bd_r1 > r && bd_c >= c && bd_c <= c + cs - 1) { if (bd_r1 <= r + rs - 1 && bd_r1 > r && bd_c >= c && bd_c <= c + cs - 1) {
borderInfoCompute[bd_r1 + "_" + bd_c].t = null; borderInfoCompute[`${bd_r1}_${bd_c}`].t = null;
} }
} }
} }
} }
else if (borderType == "border-bottom") { else if (borderType == 'border-bottom') {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r2] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r2] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (borderInfoCompute[bd_r2 + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r2}_${bd_c}`] == null) {
borderInfoCompute[bd_r2 + "_" + bd_c] = {}; borderInfoCompute[`${bd_r2}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r2 + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r2}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
let bd_r_bottom = bd_r2 + 1; let bd_r_bottom = bd_r2 + 1;
if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) { if (bd_r_bottom < data.length && borderInfoCompute[`${bd_r_bottom}_${bd_c}`]) {
if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) { if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == 'object' && data[bd_r_bottom][bd_c].mc != null) {
let cell_bottom = data[bd_r_bottom][bd_c]; let cell_bottom = data[bd_r_bottom][bd_c];
let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c]; let mc = cfg.merge[`${cell_bottom.mc.r}_${cell_bottom.mc.c}`];
if (mc.r == bd_r_bottom) { if (mc.r == bd_r_bottom) {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
let mc = cfg["merge"] || {}; let mc = cfg.merge || {};
for (const key in mc) { for (const key in mc) {
let { c, r, cs, rs } = mc[key]; let { c, r, cs, rs } = mc[key];
if (bd_r2 < r + rs - 1 && bd_r2 >= r && bd_c >= c && bd_c <= c + cs - 1) { if (bd_r2 < r + rs - 1 && bd_r2 >= r && bd_c >= c && bd_c <= c + cs - 1) {
borderInfoCompute[bd_r2 + "_" + bd_c].b = null; borderInfoCompute[`${bd_r2}_${bd_c}`].b = null;
} }
} }
} }
} }
else if (borderType == "border-all") { else if (borderType == 'border-all') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc == undefined || mc == null) { if (mc == undefined || mc == null) {
continue continue;
}; }
if (mc.r == bd_r) { if (mc.r == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
if (mc.r + mc.rs - 1 == bd_r) { if (mc.r + mc.rs - 1 == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
if (mc.c == bd_c) { if (mc.c == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
} }
if (mc.c + mc.cs - 1 == bd_c) { if (mc.c + mc.cs - 1 == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
if (bd_r == bd_r1) { if (bd_r == bd_r1) {
let bd_r_top = bd_r1 - 1; let bd_r_top = bd_r1 - 1;
if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) { if (bd_r_top >= 0 && borderInfoCompute[`${bd_r_top}_${bd_c}`]) {
if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) { if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == 'object' && data[bd_r_top][bd_c].mc != null) {
let cell_top = data[bd_r_top][bd_c]; let cell_top = data[bd_r_top][bd_c];
let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c]; let mc = cfg.merge[`${cell_top.mc.r}_${cell_top.mc.c}`];
if (mc.r + mc.rs - 1 == bd_r_top) { if (mc.r + mc.rs - 1 == bd_r_top) {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
...@@ -423,18 +488,18 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -423,18 +488,18 @@ var getBorderInfo = function(luckysheetfile) {
if (bd_r == bd_r2) { if (bd_r == bd_r2) {
let bd_r_bottom = bd_r2 + 1; let bd_r_bottom = bd_r2 + 1;
if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) { if (bd_r_bottom < data.length && borderInfoCompute[`${bd_r_bottom}_${bd_c}`]) {
if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) { if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == 'object' && data[bd_r_bottom][bd_c].mc != null) {
let cell_bottom = data[bd_r_bottom][bd_c]; let cell_bottom = data[bd_r_bottom][bd_c];
let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c]; let mc = cfg.merge[`${cell_bottom.mc.r}_${cell_bottom.mc.c}`];
if (mc.r == bd_r_bottom) { if (mc.r == bd_r_bottom) {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
...@@ -442,18 +507,18 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -442,18 +507,18 @@ var getBorderInfo = function(luckysheetfile) {
if (bd_c == bd_c1) { if (bd_c == bd_c1) {
let bd_c_left = bd_c1 - 1; let bd_c_left = bd_c1 - 1;
if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) { if (bd_c_left >= 0 && borderInfoCompute[`${bd_r}_${bd_c_left}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == 'object' && data[bd_r][bd_c_left].mc != null) {
let cell_left = data[bd_r][bd_c_left]; let cell_left = data[bd_r][bd_c_left];
let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c]; let mc = cfg.merge[`${cell_left.mc.r}_${cell_left.mc.c}`];
if (mc.c + mc.cs - 1 == bd_c_left) { if (mc.c + mc.cs - 1 == bd_c_left) {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
...@@ -461,27 +526,27 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -461,27 +526,27 @@ var getBorderInfo = function(luckysheetfile) {
if (bd_c == bd_c2) { if (bd_c == bd_c2) {
let bd_c_right = bd_c2 + 1; let bd_c_right = bd_c2 + 1;
if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) { if (bd_c_right < data[0].length && borderInfoCompute[`${bd_r}_${bd_c_right}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == 'object' && data[bd_r][bd_c_right].mc != null) {
let cell_right = data[bd_r][bd_c_right]; let cell_right = data[bd_r][bd_c_right];
let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c]; let mc = cfg.merge[`${cell_right.mc.r}_${cell_right.mc.c}`];
if (mc.c == bd_c_right) { if (mc.c == bd_c_right) {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
} }
} }
} }
else if (borderType == "border-outside") { else if (borderType == 'border-outside') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
...@@ -491,508 +556,508 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -491,508 +556,508 @@ var getBorderInfo = function(luckysheetfile) {
} }
if (bd_r == bd_r1) { if (bd_r == bd_r1) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
let bd_r_top = bd_r1 - 1; let bd_r_top = bd_r1 - 1;
if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) { if (bd_r_top >= 0 && borderInfoCompute[`${bd_r_top}_${bd_c}`]) {
if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) { if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == 'object' && data[bd_r_top][bd_c].mc != null) {
let cell_top = data[bd_r_top][bd_c]; let cell_top = data[bd_r_top][bd_c];
let mc = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c]; let mc = cfg.merge[`${cell_top.mc.r}_${cell_top.mc.c}`];
if (mc.r + mc.rs - 1 == bd_r_top) { if (mc.r + mc.rs - 1 == bd_r_top) {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
if (bd_r == bd_r2) { if (bd_r == bd_r2) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
let bd_r_bottom = bd_r2 + 1; let bd_r_bottom = bd_r2 + 1;
if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) { if (bd_r_bottom < data.length && borderInfoCompute[`${bd_r_bottom}_${bd_c}`]) {
if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) { if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == 'object' && data[bd_r_bottom][bd_c].mc != null) {
let cell_bottom = data[bd_r_bottom][bd_c]; let cell_bottom = data[bd_r_bottom][bd_c];
let mc = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c]; let mc = cfg.merge[`${cell_bottom.mc.r}_${cell_bottom.mc.c}`];
if (mc.r == bd_r_bottom) { if (mc.r == bd_r_bottom) {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
if (bd_c == bd_c1) { if (bd_c == bd_c1) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
let bd_c_left = bd_c1 - 1; let bd_c_left = bd_c1 - 1;
if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) { if (bd_c_left >= 0 && borderInfoCompute[`${bd_r}_${bd_c_left}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == 'object' && data[bd_r][bd_c_left].mc != null) {
let cell_left = data[bd_r][bd_c_left]; let cell_left = data[bd_r][bd_c_left];
let mc = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c]; let mc = cfg.merge[`${cell_left.mc.r}_${cell_left.mc.c}`];
if (mc.c + mc.cs - 1 == bd_c_left) { if (mc.c + mc.cs - 1 == bd_c_left) {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
if (bd_c == bd_c2) { if (bd_c == bd_c2) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
let bd_c_right = bd_c2 + 1; let bd_c_right = bd_c2 + 1;
if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) { if (bd_c_right < data[0].length && borderInfoCompute[`${bd_r}_${bd_c_right}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == 'object' && data[bd_r][bd_c_right].mc != null) {
let cell_right = data[bd_r][bd_c_right]; let cell_right = data[bd_r][bd_c_right];
let mc = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c]; let mc = cfg.merge[`${cell_right.mc.r}_${cell_right.mc.c}`];
if (mc.c == bd_c_right) { if (mc.c == bd_c_right) {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
} }
} }
} }
else if (borderType == "border-inside") { else if (borderType == 'border-inside') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (bd_r == bd_r1 && bd_c == bd_c1) { if (bd_r == bd_r1 && bd_c == bd_c1) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_r == bd_r2 && bd_c == bd_c1) { else if (bd_r == bd_r2 && bd_c == bd_c1) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_r == bd_r1 && bd_c == bd_c2) { else if (bd_r == bd_r1 && bd_c == bd_c2) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_r == bd_r2 && bd_c == bd_c2) { else if (bd_r == bd_r2 && bd_c == bd_c2) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_r == bd_r1) { else if (bd_r == bd_r1) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc.c == bd_c) { if (mc.c == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.c + mc.cs - 1 == bd_c) { else if (mc.c + mc.cs - 1 == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_r == bd_r2) { else if (bd_r == bd_r2) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc.c == bd_c) { if (mc.c == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.c + mc.cs - 1 == bd_c) { else if (mc.c + mc.cs - 1 == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_c == bd_c1) { else if (bd_c == bd_c1) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc.r == bd_r) { if (mc.r == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.r + mc.rs - 1 == bd_r) { else if (mc.r + mc.rs - 1 == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_c == bd_c2) { else if (bd_c == bd_c2) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc.r == bd_r) { if (mc.r == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.r + mc.rs - 1 == bd_r) { else if (mc.r + mc.rs - 1 == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc.r == bd_r) { if (mc.r == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.r + mc.rs - 1 == bd_r) { else if (mc.r + mc.rs - 1 == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
if (mc.c == bd_c) { if (mc.c == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.c + mc.cs - 1 == bd_c) { else if (mc.c + mc.cs - 1 == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
} }
} }
else if (borderType == "border-horizontal") { else if (borderType == 'border-horizontal') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (bd_r == bd_r1) { if (bd_r == bd_r1) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_r == bd_r2) { else if (bd_r == bd_r2) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c]; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`];
if (mc.r == bd_r) { if (mc.r == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.r + mc.rs - 1 == bd_r) { else if (mc.r + mc.rs - 1 == bd_r) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
} }
} }
else if (borderType == "border-vertical") { else if (borderType == 'border-vertical') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (bd_c == bd_c1) { if (bd_c == bd_c1) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else if (bd_c == bd_c2) { else if (bd_c == bd_c2) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {}; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`] || {};
if (mc.c == bd_c) { if (mc.c == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
} }
else if (mc.c + mc.cs - 1 == bd_c) { else if (mc.c + mc.cs - 1 == bd_c) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
else { else {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': borderColor, 'style': borderStyle };
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": borderColor, "style": borderStyle }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': borderColor, 'style': borderStyle };
} }
} }
} }
} }
} }
else if (borderType == "border-none") { else if (borderType == 'border-none') {
for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) { for (let bd_r = bd_r1; bd_r <= bd_r2; bd_r++) {
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) { for (let bd_c = bd_c1; bd_c <= bd_c2; bd_c++) {
if (borderInfoCompute[bd_r + "_" + bd_c] != null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] != null) {
delete borderInfoCompute[bd_r + "_" + bd_c]; delete borderInfoCompute[`${bd_r}_${bd_c}`];
} }
if (bd_r == bd_r1) { if (bd_r == bd_r1) {
let bd_r_top = bd_r1 - 1; let bd_r_top = bd_r1 - 1;
if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) { if (bd_r_top >= 0 && borderInfoCompute[`${bd_r_top}_${bd_c}`]) {
delete borderInfoCompute[bd_r_top + "_" + bd_c].b; delete borderInfoCompute[`${bd_r_top}_${bd_c}`].b;
} }
} }
if (bd_r == bd_r2) { if (bd_r == bd_r2) {
let bd_r_bottom = bd_r2 + 1; let bd_r_bottom = bd_r2 + 1;
if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) { if (bd_r_bottom < data.length && borderInfoCompute[`${bd_r_bottom}_${bd_c}`]) {
delete borderInfoCompute[bd_r_bottom + "_" + bd_c].t; delete borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t;
} }
} }
if (bd_c == bd_c1) { if (bd_c == bd_c1) {
let bd_c_left = bd_c1 - 1; let bd_c_left = bd_c1 - 1;
if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) { if (bd_c_left >= 0 && borderInfoCompute[`${bd_r}_${bd_c_left}`]) {
delete borderInfoCompute[bd_r + "_" + bd_c_left].r; delete borderInfoCompute[`${bd_r}_${bd_c_left}`].r;
} }
} }
if (bd_c == bd_c2) { if (bd_c == bd_c2) {
let bd_c_right = bd_c2 + 1; let bd_c_right = bd_c2 + 1;
if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) { if (bd_c_right < data[0].length && borderInfoCompute[`${bd_r}_${bd_c_right}`]) {
delete borderInfoCompute[bd_r + "_" + bd_c_right].l; delete borderInfoCompute[`${bd_r}_${bd_c_right}`].l;
} }
} }
} }
...@@ -1000,233 +1065,233 @@ var getBorderInfo = function(luckysheetfile) { ...@@ -1000,233 +1065,233 @@ var getBorderInfo = function(luckysheetfile) {
} }
} }
} }
else if (rangeType == "cell") { else if (rangeType == 'cell') {
let value = borderInfo[i].value; let value = borderInfo[i].value;
let bd_r = value.row_index, bd_c = value.col_index; let bd_r = value.row_index; let bd_c = value.col_index;
if (bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed) { if (bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed) {
continue; continue;
} }
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg.rowhidden != null && cfg.rowhidden[bd_r] != null) {
continue; continue;
} }
if (value.l != null || value.r != null || value.t != null || value.b != null) { if (value.l != null || value.r != null || value.t != null || value.b != null) {
if (borderInfoCompute[bd_r + "_" + bd_c] == null) { if (borderInfoCompute[`${bd_r}_${bd_c}`] == null) {
borderInfoCompute[bd_r + "_" + bd_c] = {}; borderInfoCompute[`${bd_r}_${bd_c}`] = {};
} }
if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == "object" && data[bd_r][bd_c].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c]) == 'object' && data[bd_r][bd_c].mc != null) {
let cell = data[bd_r][bd_c]; let cell = data[bd_r][bd_c];
let mc = cfg["merge"][cell.mc.r + "_" + cell.mc.c] || {}; let mc = cfg.merge[`${cell.mc.r}_${cell.mc.c}`] || {};
if (value.l != null && bd_c == mc.c) { //左边框 if (value.l != null && bd_c == mc.c) { // 左边框
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": value.l.color, "style": value.l.style }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': value.l.color, 'style': value.l.style };
let bd_c_left = bd_c - 1; let bd_c_left = bd_c - 1;
if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) { if (bd_c_left >= 0 && borderInfoCompute[`${bd_r}_${bd_c_left}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == 'object' && data[bd_r][bd_c_left].mc != null) {
let cell_left = data[bd_r][bd_c_left]; let cell_left = data[bd_r][bd_c_left];
let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c]; let mc_l = cfg.merge[`${cell_left.mc.r}_${cell_left.mc.c}`];
if (mc_l.c + mc_l.cs - 1 == bd_c_left) { if (mc_l.c + mc_l.cs - 1 == bd_c_left) {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': value.l.color, 'style': value.l.style };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': value.l.color, 'style': value.l.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].l = null; borderInfoCompute[`${bd_r}_${bd_c}`].l = null;
} }
if (value.r != null && bd_c == mc.c + mc.cs - 1) { //右边框 if (value.r != null && bd_c == mc.c + mc.cs - 1) { // 右边框
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": value.r.color, "style": value.r.style }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': value.r.color, 'style': value.r.style };
let bd_c_right = bd_c + 1; let bd_c_right = bd_c + 1;
if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) { if (bd_c_right < data[0].length && borderInfoCompute[`${bd_r}_${bd_c_right}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == 'object' && data[bd_r][bd_c_right].mc != null) {
let cell_right = data[bd_r][bd_c_right]; let cell_right = data[bd_r][bd_c_right];
let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c]; let mc_r = cfg.merge[`${cell_right.mc.r}_${cell_right.mc.c}`];
if (mc_r.c == bd_c_right) { if (mc_r.c == bd_c_right) {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': value.r.color, 'style': value.r.style };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': value.r.color, 'style': value.r.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].r = null; borderInfoCompute[`${bd_r}_${bd_c}`].r = null;
} }
if (value.t != null && bd_r == mc.r) { //上边框 if (value.t != null && bd_r == mc.r) { // 上边框
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": value.t.color, "style": value.t.style }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': value.t.color, 'style': value.t.style };
let bd_r_top = bd_r - 1; let bd_r_top = bd_r - 1;
if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) { if (bd_r_top >= 0 && borderInfoCompute[`${bd_r_top}_${bd_c}`]) {
if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) { if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == 'object' && data[bd_r_top][bd_c].mc != null) {
let cell_top = data[bd_r_top][bd_c]; let cell_top = data[bd_r_top][bd_c];
let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c]; let mc_t = cfg.merge[`${cell_top.mc.r}_${cell_top.mc.c}`];
if (mc_t.r + mc_t.rs - 1 == bd_r_top) { if (mc_t.r + mc_t.rs - 1 == bd_r_top) {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': value.t.color, 'style': value.t.style };
} }
} }
else { else {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': value.t.color, 'style': value.t.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].t = null; borderInfoCompute[`${bd_r}_${bd_c}`].t = null;
} }
if (value.b != null && bd_r == mc.r + mc.rs - 1) { //下边框 if (value.b != null && bd_r == mc.r + mc.rs - 1) { // 下边框
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": value.b.color, "style": value.b.style }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': value.b.color, 'style': value.b.style };
let bd_r_bottom = bd_r + 1; let bd_r_bottom = bd_r + 1;
if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) { if (bd_r_bottom < data.length && borderInfoCompute[`${bd_r_bottom}_${bd_c}`]) {
if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) { if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == 'object' && data[bd_r_bottom][bd_c].mc != null) {
let cell_bottom = data[bd_r_bottom][bd_c]; let cell_bottom = data[bd_r_bottom][bd_c];
let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c]; let mc_b = cfg.merge[`${cell_bottom.mc.r}_${cell_bottom.mc.c}`];
if (mc_b.r == bd_r_bottom) { if (mc_b.r == bd_r_bottom) {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': value.b.color, 'style': value.b.style };
} }
} }
else { else {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': value.b.color, 'style': value.b.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].b = null; borderInfoCompute[`${bd_r}_${bd_c}`].b = null;
} }
} }
else { else {
if (value.l != null) { //左边框 if (value.l != null) { // 左边框
borderInfoCompute[bd_r + "_" + bd_c].l = { "color": value.l.color, "style": value.l.style }; borderInfoCompute[`${bd_r}_${bd_c}`].l = { 'color': value.l.color, 'style': value.l.style };
let bd_c_left = bd_c - 1; let bd_c_left = bd_c - 1;
if (bd_c_left >= 0 && borderInfoCompute[bd_r + "_" + bd_c_left]) { if (bd_c_left >= 0 && borderInfoCompute[`${bd_r}_${bd_c_left}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == "object" && data[bd_r][bd_c_left].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_left]) == 'object' && data[bd_r][bd_c_left].mc != null) {
let cell_left = data[bd_r][bd_c_left]; let cell_left = data[bd_r][bd_c_left];
let mc_l = cfg["merge"][cell_left.mc.r + "_" + cell_left.mc.c]; let mc_l = cfg.merge[`${cell_left.mc.r}_${cell_left.mc.c}`];
if (mc_l.c + mc_l.cs - 1 == bd_c_left) { if (mc_l.c + mc_l.cs - 1 == bd_c_left) {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': value.l.color, 'style': value.l.style };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_left].r = { "color": value.l.color, "style": value.l.style }; borderInfoCompute[`${bd_r}_${bd_c_left}`].r = { 'color': value.l.color, 'style': value.l.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].l = null; borderInfoCompute[`${bd_r}_${bd_c}`].l = null;
} }
if (value.r != null) { //右边框 if (value.r != null) { // 右边框
borderInfoCompute[bd_r + "_" + bd_c].r = { "color": value.r.color, "style": value.r.style }; borderInfoCompute[`${bd_r}_${bd_c}`].r = { 'color': value.r.color, 'style': value.r.style };
let bd_c_right = bd_c + 1; let bd_c_right = bd_c + 1;
if (bd_c_right < data[0].length && borderInfoCompute[bd_r + "_" + bd_c_right]) { if (bd_c_right < data[0].length && borderInfoCompute[`${bd_r}_${bd_c_right}`]) {
if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == "object" && data[bd_r][bd_c_right].mc != null) { if (data[bd_r] != null && getObjType(data[bd_r][bd_c_right]) == 'object' && data[bd_r][bd_c_right].mc != null) {
let cell_right = data[bd_r][bd_c_right]; let cell_right = data[bd_r][bd_c_right];
let mc_r = cfg["merge"][cell_right.mc.r + "_" + cell_right.mc.c]; let mc_r = cfg.merge[`${cell_right.mc.r}_${cell_right.mc.c}`];
if (mc_r.c == bd_c_right) { if (mc_r.c == bd_c_right) {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': value.r.color, 'style': value.r.style };
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c_right].l = { "color": value.r.color, "style": value.r.style }; borderInfoCompute[`${bd_r}_${bd_c_right}`].l = { 'color': value.r.color, 'style': value.r.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].r = null; borderInfoCompute[`${bd_r}_${bd_c}`].r = null;
} }
if (value.t != null) { //上边框 if (value.t != null) { // 上边框
borderInfoCompute[bd_r + "_" + bd_c].t = { "color": value.t.color, "style": value.t.style }; borderInfoCompute[`${bd_r}_${bd_c}`].t = { 'color': value.t.color, 'style': value.t.style };
let bd_r_top = bd_r - 1; let bd_r_top = bd_r - 1;
if (bd_r_top >= 0 && borderInfoCompute[bd_r_top + "_" + bd_c]) { if (bd_r_top >= 0 && borderInfoCompute[`${bd_r_top}_${bd_c}`]) {
if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == "object" && data[bd_r_top][bd_c].mc != null) { if (data[bd_r_top] != null && getObjType(data[bd_r_top][bd_c]) == 'object' && data[bd_r_top][bd_c].mc != null) {
let cell_top = data[bd_r_top][bd_c]; let cell_top = data[bd_r_top][bd_c];
let mc_t = cfg["merge"][cell_top.mc.r + "_" + cell_top.mc.c]; let mc_t = cfg.merge[`${cell_top.mc.r}_${cell_top.mc.c}`];
if (mc_t.r + mc_t.rs - 1 == bd_r_top) { if (mc_t.r + mc_t.rs - 1 == bd_r_top) {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': value.t.color, 'style': value.t.style };
} }
} }
else { else {
borderInfoCompute[bd_r_top + "_" + bd_c].b = { "color": value.t.color, "style": value.t.style }; borderInfoCompute[`${bd_r_top}_${bd_c}`].b = { 'color': value.t.color, 'style': value.t.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].t = null; borderInfoCompute[`${bd_r}_${bd_c}`].t = null;
} }
if (value.b != null) { //下边框 if (value.b != null) { // 下边框
borderInfoCompute[bd_r + "_" + bd_c].b = { "color": value.b.color, "style": value.b.style }; borderInfoCompute[`${bd_r}_${bd_c}`].b = { 'color': value.b.color, 'style': value.b.style };
let bd_r_bottom = bd_r + 1; let bd_r_bottom = bd_r + 1;
if (bd_r_bottom < data.length && borderInfoCompute[bd_r_bottom + "_" + bd_c]) { if (bd_r_bottom < data.length && borderInfoCompute[`${bd_r_bottom}_${bd_c}`]) {
if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == "object" && data[bd_r_bottom][bd_c].mc != null) { if (data[bd_r_bottom] != null && getObjType(data[bd_r_bottom][bd_c]) == 'object' && data[bd_r_bottom][bd_c].mc != null) {
let cell_bottom = data[bd_r_bottom][bd_c]; let cell_bottom = data[bd_r_bottom][bd_c];
let mc_b = cfg["merge"][cell_bottom.mc.r + "_" + cell_bottom.mc.c]; let mc_b = cfg.merge[`${cell_bottom.mc.r}_${cell_bottom.mc.c}`];
if (mc_b.r == bd_r_bottom) { if (mc_b.r == bd_r_bottom) {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': value.b.color, 'style': value.b.style };
} }
} }
else { else {
borderInfoCompute[bd_r_bottom + "_" + bd_c].t = { "color": value.b.color, "style": value.b.style }; borderInfoCompute[`${bd_r_bottom}_${bd_c}`].t = { 'color': value.b.color, 'style': value.b.style };
} }
} }
} }
else { else {
borderInfoCompute[bd_r + "_" + bd_c].b = null; borderInfoCompute[`${bd_r}_${bd_c}`].b = null;
} }
} }
} }
else { else {
delete borderInfoCompute[bd_r + "_" + bd_c]; delete borderInfoCompute[`${bd_r}_${bd_c}`];
} }
} }
} }
} }
return borderInfoCompute; return borderInfoCompute;
} };
//获取数据类型 // 获取数据类型
var getObjType = function(obj) { const getObjType = function(obj) {
let toString = Object.prototype.toString; let toString = Object.prototype.toString;
let map = { let map = {
...@@ -1240,23 +1305,23 @@ var getObjType = function(obj) { ...@@ -1240,23 +1305,23 @@ var getObjType = function(obj) {
'[object Undefined]': 'undefined', '[object Undefined]': 'undefined',
'[object Null]': 'null', '[object Null]': 'null',
'[object Object]': 'object' '[object Object]': 'object'
} };
return map[toString.call(obj)]; return map[toString.call(obj)];
} };
var setStyleAndValue = function(cellArr, worksheet) { const setStyleAndValue = function(cellArr, worksheet) {
if (!Array.isArray(cellArr)) return; if (!Array.isArray(cellArr)) { return; }
cellArr.forEach(function(row, rowid) { cellArr.forEach((row, rowid) => {
const dbrow = worksheet.getRow(rowid + 1); const dbrow = worksheet.getRow(rowid + 1);
//设置单元格行高,默认乘以1.2倍 // 设置单元格行高,默认乘以1.2倍
dbrow.height = luckysheet.getRowHeight([rowid])[rowid] * 1.2; dbrow.height = luckysheet.getRowHeight([rowid])[rowid] * 0.78;
row.every(function(cell, columnid) { row.every((cell, columnid) => {
if (!cell) return true; if (!cell) { return true; }
if (rowid == 0) { if (rowid == 0) {
const dobCol = worksheet.getColumn(columnid + 1); const dobCol = worksheet.getColumn(columnid + 1);
//设置单元格列宽除以8 // 设置单元格列宽除以8
dobCol.width = luckysheet.getColumnWidth([columnid])[columnid] / 8; dobCol.width = luckysheet.getColumnWidth([columnid])[columnid] / 8;
} }
let fill = fillConvert(cell.bg); let fill = fillConvert(cell.bg);
...@@ -1264,12 +1329,12 @@ var setStyleAndValue = function(cellArr, worksheet) { ...@@ -1264,12 +1329,12 @@ var setStyleAndValue = function(cellArr, worksheet) {
let alignment = alignmentConvert(cell.vt, cell.ht, cell.tb, cell.tr); let alignment = alignmentConvert(cell.vt, cell.ht, cell.tb, cell.tr);
let value; let value;
var v = ''; let v = '';
if (cell.ct && cell.ct.t == 'inlineStr') { if (cell.ct && cell.ct.t == 'inlineStr') {
var s = cell.ct.s; let s = cell.ct.s;
s.forEach(function(val, num) { s.forEach((val, num) => {
v += val.v; v += val.v;
}) });
} else { } else {
v = cell.v; v = cell.v;
} }
...@@ -1284,29 +1349,28 @@ var setStyleAndValue = function(cellArr, worksheet) { ...@@ -1284,29 +1349,28 @@ var setStyleAndValue = function(cellArr, worksheet) {
target.alignment = alignment; target.alignment = alignment;
target.value = value; target.value = value;
return true; return true;
}) });
}) });
} };
//转换颜色 // 转换颜色
var rgb2hex = function(rgb) { const rgb2hex = function(rgb) {
if (rgb.charAt(0) == '#') { if (rgb.charAt(0) == '#') {
return rgb; return rgb;
} }
var ds = rgb.split(/\D+/); let ds = rgb.split(/\D+/);
var decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]); let decimal = Number(ds[1]) * 65536 + Number(ds[2]) * 256 + Number(ds[3]);
return "#" + zero_fill_hex(decimal, 6); return `#${zero_fill_hex(decimal, 6)}`;
function zero_fill_hex(num, digits) { function zero_fill_hex(num, digits) {
var s = num.toString(16); let s = num.toString(16);
while (s.length < digits) while (s.length < digits) { s = `0${s}`; }
s = "0" + s;
return s; return s;
} }
} };
var fillConvert = function(bg) { const fillConvert = function(bg) {
if (!bg) { if (!bg) {
return null; return null;
// return { // return {
...@@ -1320,33 +1384,36 @@ var fillConvert = function(bg) { ...@@ -1320,33 +1384,36 @@ var fillConvert = function(bg) {
type: 'pattern', type: 'pattern',
pattern: 'solid', pattern: 'solid',
fgColor: { argb: bg.replace('#', '') } fgColor: { argb: bg.replace('#', '') }
} };
return fill return fill;
} };
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(下划线) const fontConvert = function(ff = 0, fc = '#000000', bl = 0, it = 0, fs = 10, cl = 0, ul = 0) { // luckysheet:ff(样式), fc(颜色), bl(粗体), it(斜体), fs(大小), cl(删除线), ul(下划线)
const luckyToExcel = { const luckyToExcel = {
0: '微软雅黑', 0: 'Times New Roman',
1: '宋体(Song)', 1: 'Arial',
2: '黑体(ST Heiti)', 2: 'Tahoma',
3: '楷体(ST Kaiti)', 3: 'Verdana',
4: '仿宋(ST FangSong)', 4: '微软雅黑',
5: '新宋体(ST Song)', // 5: '宋体(Song)',
6: '华文新魏', 5: '宋体',
7: '华文行楷', // 6: '黑体(ST Heiti)',
8: '华文隶书', 6: '黑体',
9: 'Arial', 7: '楷体(ST Kaiti)',
10: 'Times New Roman ', 8: '仿宋(ST FangSong)',
11: 'Tahoma ', 9: '新宋体(ST Song)',
12: 'Verdana', 10: '华文新魏',
num2bl: function(num) { 11: '华文行楷',
return num === 0 ? false : true 12: '华文隶书',
num2bl(num) {
return num === 0 ? false : true;
} }
} };
let color = fc ? '' : (fc + "").indexOf('rgb') > -1 ? util.rgb2hex(fc) : fc;
let color = fc ? '' : `${fc}`.indexOf('rgb') > -1 ? rgb2hex(fc) : fc;
let font = { let font = {
name: ff, name: luckyToExcel[ff] || luckyToExcel[1],
family: 1, family: 1,
size: fs, size: fs,
color: { argb: color.replace('#', '') }, color: { argb: color.replace('#', '') },
...@@ -1354,12 +1421,12 @@ var fontConvert = function(ff = 0, fc = '#000000', bl = 0, it = 0, fs = 10, cl = ...@@ -1354,12 +1421,12 @@ var fontConvert = function(ff = 0, fc = '#000000', bl = 0, it = 0, fs = 10, cl =
italic: luckyToExcel.num2bl(it), italic: luckyToExcel.num2bl(it),
underline: luckyToExcel.num2bl(ul), underline: luckyToExcel.num2bl(ul),
strike: luckyToExcel.num2bl(cl) strike: luckyToExcel.num2bl(cl)
} };
return font; return font;
} };
var alignmentConvert = function(vt = 'default', ht = 'default', tb = 'default', tr = 'default') { // luckysheet:vt(垂直), ht(水平), tb(换行), tr(旋转) const alignmentConvert = function(vt = 'default', ht = 'default', tb = 'default', tr = 'default') { // luckysheet:vt(垂直), ht(水平), tb(换行), tr(旋转)
const luckyToExcel = { const luckyToExcel = {
vertical: { vertical: {
0: 'middle', 0: 'middle',
...@@ -1388,16 +1455,183 @@ var alignmentConvert = function(vt = 'default', ht = 'default', tb = 'default', ...@@ -1388,16 +1455,183 @@ var alignmentConvert = function(vt = 'default', ht = 'default', tb = 'default',
5: -90, 5: -90,
default: 0 default: 0
} }
} };
let alignment = { let alignment = {
vertical: luckyToExcel.vertical[vt], vertical: luckyToExcel.vertical[vt],
horizontal: luckyToExcel.horizontal[ht], horizontal: luckyToExcel.horizontal[ht],
wrapText: luckyToExcel.wrapText[tb], wrapText: luckyToExcel.wrapText[tb],
textRotation: luckyToExcel.textRotation[tr] textRotation: luckyToExcel.textRotation[tr]
} };
return alignment; return alignment;
};
/**
* 批量图片URL转Base64(高性能并行处理)
* @param {string[]} urls - 图片URL数组
* @param {Object} options - 配置选项
* @returns {Promise<Array<{url: string, base64: string, error?: string}>>}
*/
async function batchUrlsToBase64(urls, options = {}) {
if (!Array.isArray(urls) || urls.length === 0) {
throw new Error('URL列表不能为空');
}
// 限制并发数量,避免浏览器资源耗尽
const CONCURRENT_LIMIT = 4;
const results = [];
// 分批处理
for (let i = 0; i < urls.length; i += CONCURRENT_LIMIT) {
const batch = urls.slice(i, i + CONCURRENT_LIMIT);
const batchPromises = batch.map(url =>
urlToBase64HighPerformance(url, options)
.then(base64 => ({ url, base64 }))
.catch(error => ({ url, base64: null, error: error.message }))
);
const batchResults = await Promise.allSettled(batchPromises);
// 处理本批次结果
batchResults.forEach(result => {
if (result.status === 'fulfilled') {
results.push(result.value);
} else {
results.push({
url: 'unknown',
base64: null,
error: result.reason.message
});
}
});
// 批次间短暂延迟,避免阻塞主线程
if (i + CONCURRENT_LIMIT < urls.length) {
await new Promise(resolve => setTimeout(resolve, 100));
}
}
return results;
} }
/**
* 高性能图片URL转Base64方法
* @param {string} url - 图片URL地址
* @param {Object} options - 配置选项
* @param {number} options.timeout - 请求超时时间(毫秒),默认10000
* @param {boolean} options.forceCanvas - 强制使用Canvas进行压缩/格式转换
* @param {string} options.canvasFormat - Canvas输出格式,默认'image/jpeg'
* @param {number} options.canvasQuality - Canvas输出质量(0-1),默认0.8
* @returns {Promise<string>} Base64编码的图片数据
*/
async function urlToBase64HighPerformance(url, options = {}) {
const {
timeout = 10000,
forceCanvas = false,
canvasFormat = 'image/jpeg',
canvasQuality = 0.8
} = options;
// 参数验证
if (!url || typeof url !== 'string') {
return null;
// throw new Error('图片URL不能为空且必须是字符串');
}
export default exportSheetExcel try {
\ No newline at end of file // 创建超时控制器
// const controller = new AbortController();
// const timeoutId = setTimeout(() => controller.abort(), timeout);
// 使用Fetch API获取图片
const response = await fetch(url, {
// signal: controller.signal,
// cache: 'force-cache' // 利用浏览器缓存
});
// clearTimeout(timeoutId);
if (!response.ok) {
return null;
// throw new Error(`HTTP错误! 状态: ${response.status}`);
}
// 获取图片Blob
const blob = await response.blob();
// 性能选择:直接使用Blob转Base64或通过Canvas处理
if (forceCanvas) {
return await convertViaCanvas(blob, canvasFormat, canvasQuality);
} else {
return await convertViaFileReader(blob);
}
} catch (error) {
if (error.name === 'AbortError') {
return null;
// throw new Error(`图片加载超时(${timeout}ms)`);
}
return null;
// throw new Error(`转换失败: ${error.message}`);
}
}
/**
* 通过FileReader直接转换(最高性能)
*/
function convertViaFileReader(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => {
resolve(reader.result);
};
reader.onerror = () => {
reject(new Error('文件读取失败'));
};
reader.readAsDataURL(blob);
});
}
/**
* 通过Canvas转换(用于格式转换或压缩)
*/
function convertViaCanvas(blob, format = 'image/jpeg', quality = 0.8) {
return new Promise((resolve, reject) => {
const img = new Image();
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// 处理跨域图片
img.crossOrigin = 'anonymous';
img.onload = () => {
try {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
// 绘制图片到Canvas
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
// 转换为Base64(可控制格式和质量)
const base64 = canvas.toDataURL(format, quality);
resolve(base64);
} catch (error) {
reject(new Error(`Canvas转换失败: ${error.message}`));
}
};
img.onerror = () => reject(new Error('图片加载失败'));
// 通过Object URL加载图片
img.src = URL.createObjectURL(blob);
// 清理Object URL
img.onload = () => {
URL.revokeObjectURL(img.src);
};
});
}
export default exportSheetExcel;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment