diff --git a/src/controllers/dropCell.js b/src/controllers/dropCell.js index a7aebcecd..5f669529d 100644 --- a/src/controllers/dropCell.js +++ b/src/controllers/dropCell.js @@ -470,7 +470,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "down", j - apply_str_r + 1); - let v = formula.execfunction(f, j, i, true); + let v = formula.execfunction(f, j, i); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; @@ -552,7 +554,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "up", apply_end_r - j + 1); - let v = formula.execfunction(f, j, i, true); + let v = formula.execfunction(f, j, i); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; @@ -644,7 +648,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "right", j - apply_str_c + 1); - let v = formula.execfunction(f, i, j, true); + let v = formula.execfunction(f, i, j); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; @@ -726,7 +732,9 @@ const luckysheetDropCell = { if(cell.f != null){ let f = "=" + formula.functionCopy(cell.f, "left", apply_end_c - j + 1); - let v = formula.execfunction(f, i, j, true); + let v = formula.execfunction(f, i, j); + + formula.execFunctionGroup(j, i, v[1], undefined, d); cell.f = v[2]; cell.v = v[1]; diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index 1d38a16b1..f928cc336 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -753,8 +753,6 @@ const sheetmanage = { Store.flowdata = file["data"]; editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据 - formula.execFunctionGroupData = null; - window.luckysheet_getcelldata_cache = null; luckysheetPostil.buildAllPs(Store.flowdata); diff --git a/src/function/func.js b/src/function/func.js index c027dccba..2511bfa1c 100644 --- a/src/function/func.js +++ b/src/function/func.js @@ -5,7 +5,7 @@ import { isRealNum, valueIsError } from '../global/validate'; import { getdatabyselectionD } from '../global/getdata'; import { genarate } from '../global/format'; import { inverse } from '../function/matrix_methods'; -import { getSheetIndex, getluckysheetfile } from '../methods/get'; +import { getSheetIndex, getluckysheetfile, getRangetxt } from '../methods/get'; import { getObjType, ABCatNum } from '../utils/util'; import Store from '../store'; @@ -1770,10 +1770,112 @@ function luckysheet_getValue() { } } + +function luckysheet_indirect_check() { + let cellTxt = arguments[0]; + if (cellTxt == null || cellTxt.length == 0) { + return null; + } + return cellTxt; +} + +function luckysheet_indirect_check_return(txt) { + return txt; +} + +function luckysheet_offset_check() { + if (!(getObjType(arguments[0]) == "object" && arguments[0].startCell != null)) { + return formula.error.v; + } + + var reference = arguments[0].startCell; + + //要偏移的行数 + var rows = func_methods.getFirstValue(arguments[1]); + if (valueIsError(rows)) { + return rows; + } + + if (!isRealNum(rows)) { + return formula.error.v; + } + + rows = parseInt(rows); + + //要偏移的列数 + var cols = func_methods.getFirstValue(arguments[2]); + if (valueIsError(cols)) { + return cols; + } + + if (!isRealNum(cols)) { + return formula.error.v; + } + + cols = parseInt(cols); + + //要从偏移目标开始返回的范围的高度 + var height = arguments[0].rowl; + if (arguments.length >= 4) { + height = func_methods.getFirstValue(arguments[3]); + if (valueIsError(height)) { + return height; + } + + if (!isRealNum(height)) { + return formula.error.v; + } + + height = parseInt(height); + } + + //要从偏移目标开始返回的范围的宽度 + var width = arguments[0].coll; + if (arguments.length == 5) { + width = func_methods.getFirstValue(arguments[4]); + if (valueIsError(width)) { + return width; + } + + if (!isRealNum(width)) { + return formula.error.v; + } + + width = parseInt(width); + } + + if (height < 1 || width < 1) { + return formula.error.r; + } + + //计算 + var cellrange = formula.getcellrange(reference); + var cellRow0 = cellrange["row"][0]; + var cellCol0 = cellrange["column"][0]; + + cellRow0 += rows; + cellCol0 += cols; + + var cellRow1 = cellRow0 + height - 1; + var cellCol1 = cellCol0 + width - 1; + + if (cellRow0 < 0 || cellRow1 >= Store.flowdata.length || cellCol0 < 0 || cellCol1 >= Store.flowdata[0].length) { + return formula.error.r; + } + + return getRangetxt(Store.currentSheetIndex, { + row: [cellRow0, cellRow1], + column: [cellCol0, cellCol1] + }); +} + export { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, + luckysheet_indirect_check, + luckysheet_indirect_check_return, + luckysheet_offset_check } \ No newline at end of file diff --git a/src/function/functionImplementation.js b/src/function/functionImplementation.js index f9e540a8c..e62054cb3 100644 --- a/src/function/functionImplementation.js +++ b/src/function/functionImplementation.js @@ -10299,21 +10299,27 @@ const functionImplementation = { } } + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //计算 if(A1){ if(formula.iscelldata(ref_text)){ let cellrange = formula.getcellrange(ref_text); let row = cellrange.row[0], col = cellrange.column[0]; - if(row < 0 || row >= Store.flowdata.length || col < 0 || col >= Store.flowdata[0].length){ + if (row < 0 || row >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ return formula.error.r; } - if(Store.flowdata[row][col] == null || isRealNull(Store.flowdata[row][col].v)){ + if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ return 0; } - return Store.flowdata[row][col].v; + return sheetdata[row][col].v; } else{ return formula.error.r; @@ -10324,15 +10330,15 @@ const functionImplementation = { let cellrange = formula.getcellrange(ref_text); let row = cellrange.row[0], col = cellrange.column[0]; - if(row < 0 || row >= Store.flowdata.length || col < 0 || col >= Store.flowdata[0].length){ + if (row < 0 || row >= sheetdata.length || col < 0 || col >= sheetdata[0].length){ return formula.error.r; } - if(Store.flowdata[row][col] == null || isRealNull(Store.flowdata[row][col].v)){ + if (sheetdata[row][col] == null || isRealNull(sheetdata[row][col].v)){ return 0; } - return Store.flowdata[row][col].v; + return sheetdata[row][col].v; } else{ return formula.error.r; @@ -10611,7 +10617,13 @@ const functionImplementation = { var cellRow1 = cellRow0 + height - 1; var cellCol1 = cellCol0 + width - 1; - if(cellRow0 < 0 || cellRow1 >= Store.flowdata.length || cellCol0 < 0 || cellCol1 >= Store.flowdata[0].length){ + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + + if (cellRow0 < 0 || cellRow1 >= sheetdata.length || cellCol0 < 0 || cellCol1 >= sheetdata[0].length){ return formula.error.r; } @@ -10621,8 +10633,8 @@ const functionImplementation = { var rowArr = []; for(var c = cellCol0; c <= cellCol1; c++){ - if(Store.flowdata[r][c] != null && !isRealNull(Store.flowdata[r][c].v)){ - rowArr.push(Store.flowdata[r][c].v); + if (sheetdata[r][c] != null && !isRealNull(sheetdata[r][c].v)){ + rowArr.push(sheetdata[r][c].v); } else{ rowArr.push(0); @@ -23288,6 +23300,12 @@ const functionImplementation = { var row_index = cellrange.row[0]; var col_index = cellrange.column[0]; + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + switch(info_type){ case "address": return reference; @@ -23299,28 +23317,28 @@ const functionImplementation = { return 0; break; case "contents": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return 0; } - return Store.flowdata[row_index][col_index].v; + return sheetdata[row_index][col_index].v; break; case "filename": return file.name; break; case "format": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].ct == null){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].ct == null){ return "G"; } - return Store.flowdata[row_index][col_index].ct.fa; + return sheetdata[row_index][col_index].ct.fa; break; case "parentheses": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return 0; } - if(Store.flowdata[row_index][col_index].v > 0){ + if (sheetdata[row_index][col_index].v > 0){ return 1; } else{ @@ -23328,17 +23346,17 @@ const functionImplementation = { } break; case "prefix": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].ht == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].ht == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return ""; } - if(Store.flowdata[row_index][col_index].ht == 0){//居中对齐 + if (sheetdata[row_index][col_index].ht == 0){//居中对齐 return "^"; } - else if(Store.flowdata[row_index][col_index].ht == 1){//左对齐 + else if (sheetdata[row_index][col_index].ht == 1){//左对齐 return "'"; } - else if(Store.flowdata[row_index][col_index].ht == 2){//右对齐 + else if (sheetdata[row_index][col_index].ht == 2){//右对齐 return '"'; } else{ @@ -23352,7 +23370,7 @@ const functionImplementation = { return row_index + 1; break; case "type": - if(Store.flowdata[row_index][col_index] == null || Store.flowdata[row_index][col_index].v == null || Store.flowdata[row_index][col_index].v ==""){ + if (sheetdata[row_index][col_index] == null || sheetdata[row_index][col_index].v == null || sheetdata[row_index][col_index].v ==""){ return "b"; } @@ -25366,11 +25384,17 @@ const functionImplementation = { var minSpot = arguments[6]; var spotRadius = arguments[7]; + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25506,8 +25530,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25637,8 +25667,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25779,8 +25815,14 @@ const functionImplementation = { } var offsetY = data[0].length; } + + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -25866,8 +25908,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26007,8 +26055,14 @@ const functionImplementation = { } var offsetY = data[0].length; } + + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26094,8 +26148,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26179,8 +26239,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26274,8 +26340,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26363,8 +26435,14 @@ const functionImplementation = { //定义需要格式化data数据 var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; @@ -26449,8 +26527,14 @@ const functionImplementation = { //定义需要格式化data数据 //var dataformat = formula.readCellDataToOneArray(rangeValue); + let sheetdata = null; + sheetdata = Store.flowdata; + if (formula.execFunctionGroupData != null) { + sheetdata = formula.execFunctionGroupData; + } + //在下面获得该单元格的长度和宽度,同时考虑了合并单元格问题 - var cellSize = menuButton.getCellRealSize(Store.flowdata, cell_r, cell_c); + var cellSize = menuButton.getCellRealSize(sheetdata, cell_r, cell_c); var width = cellSize[0]; var height = cellSize[1]; diff --git a/src/global/draw.js b/src/global/draw.js index fa044c085..704366a04 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -1,4 +1,3 @@ -import sheetmanage from '../controllers/sheetmanage'; import pivotTable from '../controllers/pivotTable'; import conditionformat from '../controllers/conditionformat'; import alternateformat from '../controllers/alternateformat'; @@ -12,6 +11,7 @@ import { isRealNull } from './validate'; import { getCellTextSplitArr } from './getRowlen'; import { getcellvalue } from './getdata'; import { getBorderInfoCompute } from './border'; +import { getSheetIndex } from '../methods/get'; import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util'; import Store from '../store'; @@ -20,7 +20,7 @@ function luckysheetDrawgrid(scrollWidth, scrollHeight, drawWidth, drawHeight, of return; } - if(Store.luckysheetfile[sheetmanage.getSheetIndex(Store.currentSheetIndex)]["isPivotTable"]){ + if(Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["isPivotTable"]){ luckysheetDrawMain_back(scrollWidth, scrollHeight, drawWidth, drawHeight, offsetLeft, offsetTop); } else{ @@ -231,15 +231,14 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) { luckysheetTableContent.clearRect(0, 0, Store.rowHeaderWidth * Store.devicePixelRatio, Store.columeHeaderHeight * Store.devicePixelRatio); } -function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, offsetLeft, offsetTop, columnOffsetCell, rowOffsetCell, mycanvas, ctx, ctxdata) { - if(ctxdata != null){ - Store.flowdata = ctxdata; - } +let offlinecanvasElement_cache = {}; +function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, offsetLeft, offsetTop, columnOffsetCell, rowOffsetCell, mycanvas) { if(Store.flowdata == null){ return; } - + + //参数未定义处理 if (scrollWidth == null) { scrollWidth = $("#luckysheet-cell-main").scrollLeft(); } @@ -268,30 +267,23 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of rowOffsetCell = 0; } + //表格canvas let luckysheetTableContent = null; - if(ctx != null){ - let luckysheetTableElement = document.createElement('canvas'); - luckysheetTableElement.width = drawWidth; - luckysheetTableElement.height = drawHeight; - luckysheetTableContent = luckysheetTableElement.getContext("2d"); + if(mycanvas == null){ + luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d"); } - else{ - if(mycanvas == null){ - luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d"); - } - else { - if(getObjType(mycanvas) == "object"){ - try{ - luckysheetTableContent = mycanvas.get(0).getContext("2d"); - } - catch(err){ - luckysheetTableContent = mycanvas; - } + else { + if(getObjType(mycanvas) == "object"){ + try{ + luckysheetTableContent = mycanvas.get(0).getContext("2d"); } - else{ - luckysheetTableContent = $("#" + mycanvas).get(0).getContext("2d"); + catch(err){ + luckysheetTableContent = mycanvas; } } + else{ + luckysheetTableContent = $("#" + mycanvas).get(0).getContext("2d"); + } } luckysheetTableContent.clearRect( @@ -301,30 +293,11 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of Store.luckysheetTableContentHW[1] * Store.devicePixelRatio ); - //离屏canvas - let offlinecanvas = null; - if(ctx != null){ - let offlineElement = document.createElement('canvas'); - offlineElement.width = drawWidth; - offlineElement.height = drawHeight; - offlinecanvas = offlineElement.getContext("2d"); - } - else{ - offlinecanvas = $("#luckysheetTableContentF").get(0).getContext("2d"); - } - offlinecanvas.fillStyle = "#ffffff"; - offlinecanvas.fillRect( - 0, - 0, - Store.luckysheetTableContentHW[0] * Store.devicePixelRatio, - Store.luckysheetTableContentHW[1] * Store.devicePixelRatio - ); - offlinecanvas.font = luckysheetdefaultstyle.font; - offlinecanvas.textBaseline = "top"; - offlinecanvas.fillStyle = luckysheetdefaultstyle.fillStyle; - - // - let dataset_row_st, dataset_row_ed, dataset_col_st, dataset_col_ed; + //表格渲染区域 起止行列下标 + let dataset_row_st, + dataset_row_ed, + dataset_col_st, + dataset_col_ed; dataset_row_st = luckysheet_searcharray(Store.visibledatarow, scrollHeight); dataset_row_ed = luckysheet_searcharray(Store.visibledatarow, scrollHeight + drawHeight); @@ -364,8 +337,12 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of dataset_col_ed = Store.visibledatacolumn.length - 1; } + //表格渲染区域 起止行列坐标 + let fill_row_st, + fill_row_ed, + fill_col_st, + fill_col_ed; - let fill_row_st, fill_row_ed, fill_col_st, fill_col_ed; if(dataset_row_st == 0){ fill_row_st = 0; } @@ -384,6 +361,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of fill_col_ed = Store.visibledatacolumn[dataset_col_ed]; + //表格canvas 初始化处理 luckysheetTableContent.fillStyle = "#ffffff"; luckysheetTableContent.fillRect( (offsetLeft - 1) * Store.devicePixelRatio, @@ -395,14 +373,13 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of luckysheetTableContent.textBaseline = "top"; luckysheetTableContent.fillStyle = luckysheetdefaultstyle.fillStyle; - let end_r, start_r, end_c, start_c; - + //表格渲染区域 非空单元格行列 起止坐标 let cellupdate = []; let mergeCache = {}; - let borderOffset = {}; for (let r = dataset_row_st; r <= dataset_row_ed; r++) { + let start_r; if (r == 0) { start_r = -scrollHeight - 1; } @@ -410,9 +387,10 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of start_r = Store.visibledatarow[r - 1] - scrollHeight - 1; } - end_r = Store.visibledatarow[r] - scrollHeight; + let end_r = Store.visibledatarow[r] - scrollHeight; for (let c = dataset_col_st; c <= dataset_col_ed; c++) { + let start_c; if (c == 0) { start_c = -scrollWidth; } @@ -420,7 +398,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of start_c = Store.visibledatacolumn[c - 1] - scrollWidth; } - end_c = Store.visibledatacolumn[c] - scrollWidth; + let end_c = Store.visibledatacolumn[c] - scrollWidth; //横线 if(c == dataset_col_ed && !Store.luckysheetcurrentisPivotTable){ @@ -529,7 +507,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of luckysheetTableContent.stroke(); } } - + if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) { } @@ -568,13 +546,11 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of "end_r": end_r, "end_c": end_c, "firstcolumlen": firstcolumlen, - startlist: [] }); } else{ if(margeMain.c == c){ margeMain.end_r += (end_r - start_r - 1); - margeMain.startlist.push(start_r); } if(margeMain.r == r){ @@ -596,7 +572,6 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of "end_r": end_r, "end_c": end_c, "firstcolumlen": firstcolumlen, - startlist: [] }); borderOffset[r + "_" + c] = { "start_r": start_r, @@ -609,7 +584,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of } //动态数组公式计算 - let dynamicArray_compute = dynamicArrayCompute(Store.luckysheetfile[sheetmanage.getSheetIndex(Store.currentSheetIndex)]["dynamicArray"]); + let dynamicArray_compute = dynamicArrayCompute(Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray"]); //交替颜色计算 let af_compute = alternateformat.getComputeMap(); @@ -766,594 +741,643 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of //非空白单元格渲染 let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, canvasType){ - let checksAF = alternateformat.checksAF(r, c, af_compute); //交替颜色 - let checksCF = conditionformat.checksCF(r, c, cf_compute); //条件格式 - - let borderfix = menuButton.borderfix(Store.flowdata, r, c); - - //文本宽度和高度 - let fontset = luckysheetfontformat(Store.flowdata[r][c]); - luckysheetTableContent.font = fontset; - - let textMetrics = luckysheetTableContent.measureText(value).width; - // let oneLineTextHeight = menuButton.getTextSize("田", fontset)[1]; - let oneLineTextHeight = menuButton.getTextSize(value, fontset)[1]; - - let textW, textH; - - if(Store.flowdata[r][c].tb == "2"){ - let strValue = value.toString(); - let tbWidth = luckysheetTableContent.measureText(strValue).width; - let cellWidth = end_c - start_c - 8; + let cell = Store.flowdata[r][c]; + let cellWidth = end_c - start_c; + let cellHeight = end_r - start_r; - if(tbWidth > cellWidth){ - let strArr = [];//文本截断数组 - strArr = getCellTextSplitArr(strValue, strArr, cellWidth, luckysheetTableContent); - textH = strArr.length * oneLineTextHeight; - } - else{ - textH = oneLineTextHeight; - } - } - else if(Store.flowdata[r][c].tr != null && Store.flowdata[r][c].tr != "0"){ - let tr = Store.flowdata[r][c].tr; - - if(tr == "1" || tr == "2"){ - textW = 0.707 * (textMetrics + oneLineTextHeight); - textH = 0.707 * (textMetrics + oneLineTextHeight); - } - else if(tr == "3"){ - value = value.toString(); - - let vArr; - if(value.length > 1){ - vArr = value.split(""); - } - else{ - vArr = []; - vArr.push(value); - } - - textW = luckysheetTableContent.measureText(vArr[0]).width; - textH = vArr.length * oneLineTextHeight; - } - else if(tr == "4" || tr == "5"){ - textW = oneLineTextHeight; - textH = textMetrics; - } + //取渲染单元格大小离屏canvas + let offlinecanvasElement = offlinecanvasElement_cache[cellWidth + '_' + cellHeight]; + if(offlinecanvasElement == null){ + offlinecanvasElement = document.createElement('canvas'); + offlinecanvasElement.width = cellWidth * Store.devicePixelRatio; + offlinecanvasElement.height = cellHeight * Store.devicePixelRatio; + offlinecanvasElement_cache[cellWidth + '_' + cellHeight] = offlinecanvasElement; } - else{ - textW = textMetrics; - textH = oneLineTextHeight; - } - - //水平对齐 - let horizonAlign = menuButton.checkstatus(Store.flowdata, r, c , "ht"); - //垂直对齐 - let verticalAlign = menuButton.checkstatus(Store.flowdata, r, c , "vt"); + let offlinecanvas = offlinecanvasElement.getContext("2d"); - //水平对齐方式是 居中或居右对齐 且单元格宽度小于文字宽度 (用离屏canvas渲染) - let canvasName, cellsize; - if(browser.BrowserType() != "Safari" && (canvasType == "offline" || ((horizonAlign == "0" || horizonAlign == "2") && (end_c - start_c) < textW) || ((end_r - start_r) < textH))){ - canvasName = offlinecanvas; - canvasName.font = fontset; + offlinecanvas.clearRect( + 0, + 0, + cellWidth * Store.devicePixelRatio, + cellHeight * Store.devicePixelRatio + ) - cellsize = [ - Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), - Store.devicePixelRatio * (start_r + offsetTop + 0.5 + borderfix[1]), - Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), - Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) - ]; - } - else{ - canvasName = luckysheetTableContent; + let fontset = luckysheetfontformat(cell); + offlinecanvas.font = fontset; + + //文本宽度和高度 + let measureText = luckysheetTableContent.measureText(value); + let textMetrics = measureText.width; + let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent; - cellsize = [ - Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), - Store.devicePixelRatio * (start_r + offsetTop + 1 + borderfix[1]), - Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), - Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) - ]; - } + //交替颜色 + let checksAF = alternateformat.checksAF(r, c, af_compute); + //条件格式 + let checksCF = conditionformat.checksCF(r, c, cf_compute); - //horizonAlign默认为1,左对齐 - let horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; - if(horizonAlign == "0"){ - //居中对齐 - horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textMetrics) / 2; - } - else if(horizonAlign == "2"){ - //右对齐 - horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textMetrics); - } - - //verticalAlign默认为2,下对齐 - let verticalFixed = browser.luckysheetrefreshfixed(); - let verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight; - let verticalAlignPos_text = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio; - canvasName.textBaseline = "bottom"; - - if(verticalAlign == "0"){ - //居中对齐 - verticalAlignPos = (start_r + offsetTop + (end_r - start_r) / 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight / 2; - verticalAlignPos_text = (start_r + offsetTop + (end_r - start_r) / 2 + verticalFixed) * Store.devicePixelRatio; - canvasName.textBaseline = "middle"; - } - else if(verticalAlign == "1"){ - //上对齐 - verticalAlignPos = (start_r + offsetTop + 2 + verticalFixed) * Store.devicePixelRatio; - verticalAlignPos_text = (start_r + offsetTop + 2 + verticalFixed) * Store.devicePixelRatio; - canvasName.textBaseline = "top"; - } - //单元格 背景颜色 - canvasName.fillStyle= menuButton.checkstatus(Store.flowdata, r, c , "bg"); - + offlinecanvas.fillStyle = menuButton.checkstatus(Store.flowdata, r, c, "bg"); + //若单元格有交替颜色 背景颜色 if(checksAF != null && checksAF[1] != null){ - canvasName.fillStyle = checksAF[1]; + offlinecanvas.fillStyle = checksAF[1]; } - //若单元格有条件格式 背景颜色 if(checksCF != null && checksCF["cellColor"] != null){ - canvasName.fillStyle = checksCF["cellColor"]; + offlinecanvas.fillStyle = checksCF["cellColor"]; } - //若单元格有标题色 - if(Store.flowdata[r][c] != null && Store.flowdata[r][c].tc != null){ - luckysheetTableContent.fillStyle = Store.flowdata[r][c].tc; + offlinecanvas.fillRect( + 0, + 0, + cellWidth * Store.devicePixelRatio, + cellHeight * Store.devicePixelRatio + ) + + //若单元格有批注(单元格右上角红色小三角标示) + if(cell.ps != null){ + let ps_w = 5, ps_h = 5; //红色小三角宽高 + + offlinecanvas.beginPath(); + offlinecanvas.moveTo( + Store.devicePixelRatio * (cellWidth - ps_w), + 0 + ); + offlinecanvas.lineTo( + Store.devicePixelRatio * cellWidth, + 0 + ); + offlinecanvas.lineTo( + Store.devicePixelRatio * cellWidth, + Store.devicePixelRatio * ps_h + ); + offlinecanvas.fillStyle = "#FC6666"; + offlinecanvas.fill(); + offlinecanvas.closePath(); } - - canvasName.fillRect(cellsize[0], cellsize[1], cellsize[2], cellsize[3]); - //若单元格有批注 - if(Store.flowdata[r][c].ps != null){ - canvasName.beginPath(); - canvasName.moveTo(Store.devicePixelRatio * (end_c + offsetLeft - 6), Store.devicePixelRatio * (start_r + offsetTop)); - canvasName.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 1), Store.devicePixelRatio * (start_r + offsetTop)); - canvasName.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 1), Store.devicePixelRatio * (start_r + offsetTop + 5)); - canvasName.fillStyle = "#FC6666"; - canvasName.fill(); - canvasName.closePath(); - } + let space_width = 2, space_height = 2; //宽高方向 间隙 //若单元格有条件格式数据条 if(checksCF != null && checksCF["dataBar"] != null){ - let x = Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0] + 2); - let y = Store.devicePixelRatio * (start_r + offsetTop + 0.5 + borderfix[1] + 2); - let w = Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2] - 4); - let h = Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3] - 4); + let x = Store.devicePixelRatio * space_width; + let y = Store.devicePixelRatio * space_height; + let w = Store.devicePixelRatio * (cellWidth - space_width * 2); + let h = Store.devicePixelRatio * (cellHeight - space_height * 2); let valueType = checksCF["dataBar"]["valueType"]; let valueLen = checksCF["dataBar"]["valueLen"]; let format = checksCF["dataBar"]["format"]; - if(format.length > 1){ //渐变 - if(valueType == "minus"){ - //负数 - let minusLen = checksCF["dataBar"]["minusLen"]; - - let my_gradient = canvasName.createLinearGradient(x + w * minusLen * (1 - valueLen), y, x + w * minusLen, y); + if(valueType == 'minus'){ + //负数 + let minusLen = checksCF["dataBar"]["minusLen"]; + + if(format.length > 1){ + //渐变 + let my_gradient = offlinecanvas.createLinearGradient( + x + w * minusLen * (1 - valueLen), + y, + x + w * minusLen, + y + ); my_gradient.addColorStop(0, "#ffffff"); my_gradient.addColorStop(1, "#ff0000"); - canvasName.fillStyle = my_gradient; - canvasName.fillRect(x + w * minusLen * (1 - valueLen), y, w * minusLen * valueLen, h); - - canvasName.beginPath(); - canvasName.moveTo(x + w * minusLen * (1 - valueLen), y); - canvasName.lineTo(x + w * minusLen * (1 - valueLen), y + h); - canvasName.lineTo(x + w * minusLen, y + h); - canvasName.lineTo(x + w * minusLen, y); - canvasName.lineTo(x + w * minusLen * (1 - valueLen), y); - canvasName.lineWidth = Store.devicePixelRatio; - canvasName.strokeStyle = "#ff0000"; - canvasName.stroke(); - canvasName.closePath(); - } - else if(valueType == "plus"){ - //正数 - let plusLen = checksCF["dataBar"]["plusLen"]; - - if(plusLen == 1){ - let my_gradient = canvasName.createLinearGradient(x, y, x + w * valueLen, y); + + offlinecanvas.fillStyle = my_gradient; + } + else{ + //单色 + offlinecanvas.fillStyle = "#ff0000"; + } + + offlinecanvas.fillRect( + x + w * minusLen * (1 - valueLen), + y, + w * minusLen * valueLen, + h + ); + + offlinecanvas.beginPath(); + offlinecanvas.moveTo( + x + w * minusLen * (1 - valueLen), + y + ); + offlinecanvas.lineTo( + x + w * minusLen * (1 - valueLen), + y + h + ); + offlinecanvas.lineTo( + x + w * minusLen, + y + h + ); + offlinecanvas.lineTo( + x + w * minusLen, + y + ); + offlinecanvas.lineTo( + x + w * minusLen * (1 - valueLen), + y + ); + offlinecanvas.lineWidth = Store.devicePixelRatio; + offlinecanvas.strokeStyle = "#ff0000"; + offlinecanvas.stroke(); + offlinecanvas.closePath(); + } + else if(valueType == 'plus'){ + //正数 + let plusLen = checksCF["dataBar"]["plusLen"]; + + if(plusLen == 1){ + if(format.length > 1){ + //渐变 + let my_gradient = offlinecanvas.createLinearGradient( + x, + y, + x + w * valueLen, + y + ); my_gradient.addColorStop(0, format[0]); my_gradient.addColorStop(1, format[1]); - canvasName.fillStyle = my_gradient; - canvasName.fillRect(x, y, w * valueLen, h); - - canvasName.beginPath(); - canvasName.moveTo(x, y); - canvasName.lineTo(x, y + h); - canvasName.lineTo(x + w * valueLen, y + h); - canvasName.lineTo(x + w * valueLen, y); - canvasName.lineTo(x, y); - canvasName.lineWidth = Store.devicePixelRatio; - canvasName.strokeStyle = format[0]; - canvasName.stroke(); - canvasName.closePath(); + + offlinecanvas.fillStyle = my_gradient; } else{ - let minusLen = checksCF["dataBar"]["minusLen"]; - - let my_gradient = canvasName.createLinearGradient(x + w * minusLen, y, x + w * minusLen + w * plusLen * valueLen, y); - my_gradient.addColorStop(0, format[0]); - my_gradient.addColorStop(1, format[1]); - canvasName.fillStyle = my_gradient; - canvasName.fillRect(x + w * minusLen, y, w * plusLen * valueLen, h); - - canvasName.beginPath(); - canvasName.moveTo(x + w * minusLen, y); - canvasName.lineTo(x + w * minusLen, y + h); - canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y + h); - canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y); - canvasName.lineTo(x + w * minusLen, y); - canvasName.lineWidth = Store.devicePixelRatio; - canvasName.strokeStyle = format[0]; - canvasName.stroke(); - canvasName.closePath(); + //单色 + offlinecanvas.fillStyle = format[0]; } + + offlinecanvas.fillRect( + x, + y, + w * valueLen, + h + ); + + offlinecanvas.beginPath(); + offlinecanvas.moveTo( + x, + y + ); + offlinecanvas.lineTo( + x, + y + h + ); + offlinecanvas.lineTo( + x + w * valueLen, + y + h + ); + offlinecanvas.lineTo( + x + w * valueLen, + y + ); + offlinecanvas.lineTo( + x, + y + ); + offlinecanvas.lineWidth = Store.devicePixelRatio; + offlinecanvas.strokeStyle = format[0]; + offlinecanvas.stroke(); + offlinecanvas.closePath(); } - } - else{ //单色 - if(valueType == "minus"){ - //负数 + else{ let minusLen = checksCF["dataBar"]["minusLen"]; - - canvasName.fillStyle = "#ff0000"; - canvasName.fillRect(x + w * minusLen * (1 - valueLen), y, w * minusLen * valueLen, h); - - canvasName.beginPath(); - canvasName.moveTo(x + w * minusLen * (1 - valueLen), y); - canvasName.lineTo(x + w * minusLen * (1 - valueLen), y + h); - canvasName.lineTo(x + w * minusLen, y + h); - canvasName.lineTo(x + w * minusLen, y); - canvasName.lineTo(x + w * minusLen * (1 - valueLen), y); - canvasName.lineWidth = Store.devicePixelRatio; - canvasName.strokeStyle = "#ff0000"; - canvasName.stroke(); - canvasName.closePath(); - } - else if(valueType == "plus"){ - //正数 - let plusLen = checksCF["dataBar"]["plusLen"]; - - if(plusLen == 1){ - canvasName.fillStyle = format[0]; - canvasName.fillRect(x, y, w * valueLen, h); - - canvasName.beginPath(); - canvasName.moveTo(x, y); - canvasName.lineTo(x, y + h); - canvasName.lineTo(x + w * valueLen, y + h); - canvasName.lineTo(x + w * valueLen, y); - canvasName.lineTo(x, y); - canvasName.lineWidth = Store.devicePixelRatio; - canvasName.strokeStyle = format[0]; - canvasName.stroke(); - canvasName.closePath(); + + if(format.length > 1){ + //渐变 + let my_gradient = offlinecanvas.createLinearGradient( + x + w * minusLen, + y, + x + w * minusLen + w * plusLen * valueLen, + y + ); + my_gradient.addColorStop(0, format[0]); + my_gradient.addColorStop(1, format[1]); + + offlinecanvas.fillStyle = my_gradient; } else{ - let minusLen = checksCF["dataBar"]["minusLen"]; - - canvasName.fillStyle = format[0]; - canvasName.fillRect(x + w * minusLen, y, w * plusLen * valueLen, h); - - canvasName.beginPath(); - canvasName.moveTo(x + w * minusLen, y); - canvasName.lineTo(x + w * minusLen, y + h); - canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y + h); - canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y); - canvasName.lineTo(x + w * minusLen, y); - canvasName.lineWidth = Store.devicePixelRatio; - canvasName.strokeStyle = format[0]; - canvasName.stroke(); - canvasName.closePath(); + //单色 + offlinecanvas.fillStyle = format[0]; } + + offlinecanvas.fillRect( + x + w * minusLen, + y, + w * plusLen * valueLen, + h + ); + + offlinecanvas.beginPath(); + offlinecanvas.moveTo( + x + w * minusLen, + y + ); + offlinecanvas.lineTo( + x + w * minusLen, + y + h + ); + offlinecanvas.lineTo( + x + w * minusLen + w * plusLen * valueLen, + y + h + ); + offlinecanvas.lineTo( + x + w * minusLen + w * plusLen * valueLen, + y + ); + offlinecanvas.lineTo( + x + w * minusLen, + y + ); + offlinecanvas.lineWidth = Store.devicePixelRatio; + offlinecanvas.strokeStyle = format[0]; + offlinecanvas.stroke(); + offlinecanvas.closePath(); } } } + //水平对齐 + let horizonAlign = menuButton.checkstatus(Store.flowdata, r, c, "ht"); + let horizonAlignPos = space_width * Store.devicePixelRatio; //默认为1,左对齐 + if(horizonAlign == "0"){ //居中对齐 + horizonAlignPos = (cellWidth / 2) * Store.devicePixelRatio - (textMetrics / 2); + } + else if(horizonAlign == "2"){ //右对齐 + horizonAlignPos = (cellWidth - space_width) * Store.devicePixelRatio - textMetrics; + } + + //垂直对齐 + let verticalAlign = menuButton.checkstatus(Store.flowdata, r, c, "vt"); + let verticalAlignPos = (cellHeight - space_height) * Store.devicePixelRatio - oneLineTextHeight; //默认为2,下对齐 + + let verticalAlignPos_text = (cellHeight - space_height) * Store.devicePixelRatio; //文本垂直方向基准线 + offlinecanvas.textBaseline = "bottom"; + + if(verticalAlign == "0"){ //居中对齐 + verticalAlignPos = (cellHeight / 2) * Store.devicePixelRatio - (oneLineTextHeight / 2); + + verticalAlignPos_text = (cellHeight / 2) * Store.devicePixelRatio; + offlinecanvas.textBaseline = "middle"; + } + else if(verticalAlign == "1"){ //上对齐 + verticalAlignPos = space_height * Store.devicePixelRatio; + + verticalAlignPos_text = space_height * Store.devicePixelRatio; + offlinecanvas.textBaseline = "top"; + } + //若单元格有条件格式图标集 if(checksCF != null && checksCF["icons"] != null){ let l = checksCF["icons"]["left"]; let t = checksCF["icons"]["top"]; - canvasName.drawImage( + offlinecanvas.drawImage( luckysheet_CFiconsImg, l * 42, t * 32, 32, 32, - cellsize[0], - verticalAlignPos + 2, - oneLineTextHeight - 2, - oneLineTextHeight - 2 + 0, + verticalAlignPos, + oneLineTextHeight, + oneLineTextHeight ); if(horizonAlign != "0" && horizonAlign != "2"){ //左对齐时 文本渲染空出一个图标的距离 - horizonAlignPos = horizonAlignPos + oneLineTextHeight - 2; + horizonAlignPos = horizonAlignPos + oneLineTextHeight; } } //单元格 文本颜色 - canvasName.fillStyle = menuButton.checkstatus(Store.flowdata, r, c , "fc"); + offlinecanvas.fillStyle = menuButton.checkstatus(Store.flowdata, r, c , "fc"); //若单元格有交替颜色 文本颜色 if(checksAF != null && checksAF[0] != null){ - canvasName.fillStyle = checksAF[0]; + offlinecanvas.fillStyle = checksAF[0]; } - //若单元格有条件格式 文本颜色 if(checksCF != null && checksCF["textColor"] != null){ - canvasName.fillStyle = checksCF["textColor"]; + offlinecanvas.fillStyle = checksCF["textColor"]; } - //单元格有下钻属性,文本颜色变成超链接的颜色 - if(Store.flowdata[r][c].dd != null){ - canvasName.fillStyle = "#0000ff"; + //单元格是否有删除线 + let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); - canvasName.fillText(value == null ? "" : value, horizonAlignPos, verticalAlignPos_text); + if(cell.tb == '2'){ + //自动换行 + offlinecanvas.textBaseline = 'top'; //textBaseline以top计算 + + let strArr = [];//文本截断数组 + strArr = getCellTextSplitArr(value.toString(), strArr, cellWidth - space_width * 2, offlinecanvas); - canvasName.beginPath(); - canvasName.strokeStyle = "#0000ff"; - canvasName.moveTo(horizonAlignPos, verticalAlignPos + oneLineTextHeight); - canvasName.lineTo(horizonAlignPos + textMetrics, verticalAlignPos + oneLineTextHeight); - canvasName.closePath(); - canvasName.stroke(); - } - else{ - //自动换行、旋转、删除线功能 - if(Store.flowdata[r][c].tb == "2"){ - canvasName.textBaseline = 'top'; //自动换行 textBaseline以top计算 + for(let i = 0; i < strArr.length; i++){ + let strV = strArr[i]; - let strValue = value.toString(); - let cellWidth = end_c - start_c - 8; + let strWidth = offlinecanvas.measureText(strV).width; + let strHeight = oneLineTextHeight; - let strArr = [];//文本截断数组 - strArr = getCellTextSplitArr(strValue, strArr, cellWidth, canvasName); + //水平对齐计算 + if(horizonAlign == "0"){ + horizonAlignPos = (cellWidth / 2) * Store.devicePixelRatio - (strWidth / 2); + } + else if(horizonAlign == "2"){ + horizonAlignPos = (cellWidth - space_width) * Store.devicePixelRatio - strWidth; + } + else{ + horizonAlignPos = space_width * Store.devicePixelRatio; + } + + //垂直对齐计算 + if(verticalAlign == "0"){ + verticalAlignPos = (cellHeight / 2) * Store.devicePixelRatio - (strHeight / 2) * strArr.length; + } + else if(verticalAlign == "1"){ + verticalAlignPos = space_height * Store.devicePixelRatio; + } + else{ + verticalAlignPos = (cellHeight - space_height) * Store.devicePixelRatio - strHeight * strArr.length; + } - for(let iFill = 0; iFill < strArr.length; iFill++){ - //水平对齐计算 - let strWidth = canvasName.measureText(strArr[iFill]).width; - if(horizonAlign == "0"){ - horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (strWidth)/2; - } - else if(horizonAlign == "2"){ - horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (strWidth); - } - - //垂直对齐计算 - if(verticalAlign == "0"){ - verticalAlignPos = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * strArr.length / 2; - } - else if(verticalAlign == "1"){ - verticalAlignPos = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; - } - else{ - verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * strArr.length; - } + offlinecanvas.fillText(strV, horizonAlignPos, (verticalAlignPos + i * strHeight)); - canvasName.fillText(strArr[iFill], horizonAlignPos, (verticalAlignPos + iFill * oneLineTextHeight)); + if(cl == "1" && !isRealNull(strV)){ + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#000"; + offlinecanvas.moveTo( + horizonAlignPos, + (verticalAlignPos + i * strHeight) + strHeight / 2 + ); + offlinecanvas.lineTo( + horizonAlignPos + strWidth, + (verticalAlignPos + i * strHeight) + strHeight / 2 + ); + offlinecanvas.stroke(); + offlinecanvas.closePath(); } } - else if(Store.flowdata[r][c].tr != null && Store.flowdata[r][c].tr != "0"){ - canvasName.textBaseline = 'top'; //旋转 textBaseline以top计算 + } + else if(cell.tr != null && cell.tr != '0'){ + //旋转 + offlinecanvas.textBaseline = 'top'; //textBaseline以top计算 - //单元格旋转属性 - let tr = Store.flowdata[r][c].tr; - - if(tr == "1" || tr == "2"){ - //旋转重新计算水平、垂直方向坐标 - let textW = 0.707 * (textMetrics + oneLineTextHeight); - let textH = 0.707 * (textMetrics + oneLineTextHeight); - - let hAP = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; - if(horizonAlign == "0"){ - hAP = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textW) / 2; - } - else if(horizonAlign == "2"){ - hAP = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textW); - } + //单元格旋转属性 + let tr = cell.tr; - let vAP = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - textH; - if(verticalAlign == "0"){ - vAP = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - textH / 2; - } - else if(verticalAlign == "1"){ - vAP = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; - } + //旋转重新计算水平、垂直方向坐标 + if(cell.tr == "1" || cell.tr == "2"){ + let textW = 0.707 * (textMetrics + oneLineTextHeight); + let textH = 0.707 * (textMetrics + oneLineTextHeight); + + let hAP = space_width * Store.devicePixelRatio; + if(horizonAlign == "0"){ + hAP = (cellWidth / 2) * Store.devicePixelRatio - (textW / 2); + } + else if(horizonAlign == "2"){ + hAP = (cellWidth - space_width) * Store.devicePixelRatio - textW; + } + + let vAP = (cellHeight - space_height) * Store.devicePixelRatio - textH; + if(verticalAlign == "0"){ + vAP = (cellHeight / 2) * Store.devicePixelRatio - (textH / 2); + } + else if(verticalAlign == "1"){ + vAP = space_height * Store.devicePixelRatio; + } + + //向下倾斜(45 旋转) + if(cell.tr == "1"){ + offlinecanvas.save(); + offlinecanvas.translate(hAP, vAP); + offlinecanvas.rotate(45 * Math.PI / 180); + offlinecanvas.translate(-hAP, -vAP); + offlinecanvas.fillText( + value == null ? "" : value, + hAP + (0.707 * 0.707 * oneLineTextHeight), + vAP - (0.707 * 0.707 * oneLineTextHeight) + ); + offlinecanvas.restore(); - //向下倾斜(45 旋转) - if(tr == "1"){ - canvasName.save(); - canvasName.translate(hAP, vAP); - canvasName.rotate(45 * Math.PI / 180); - canvasName.translate(-hAP, -vAP); - canvasName.fillText(value == null ? "" : value, hAP + (0.707 * 0.707 * oneLineTextHeight), vAP - (0.707 * 0.707 * oneLineTextHeight)); - canvasName.restore(); - - //是否有删除线 - let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); - if(cl == "1" && !isRealNull(value)){ - canvasName.beginPath(); - canvasName.strokeStyle = "#000"; - canvasName.moveTo(hAP + oneLineTextHeight / 2, vAP + oneLineTextHeight / 2); - canvasName.lineTo(hAP + textW - oneLineTextHeight / 2, vAP + textH - oneLineTextHeight / 2); - canvasName.closePath(); - canvasName.stroke(); - } + if(cl == "1" && !isRealNull(value)){ + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#000"; + offlinecanvas.moveTo( + hAP + oneLineTextHeight / 2, + vAP + oneLineTextHeight / 2 + ); + offlinecanvas.lineTo( + hAP + textW - oneLineTextHeight / 2, + vAP + textH - oneLineTextHeight / 2 + ); + offlinecanvas.closePath(); + offlinecanvas.stroke(); } + } + + //向上倾斜(-45 旋转) + if(cell.tr == "2"){ + offlinecanvas.save(); + offlinecanvas.translate(hAP, vAP + textH); + offlinecanvas.rotate(-45 * Math.PI / 180); + offlinecanvas.translate(-hAP, -(vAP + textH)); + offlinecanvas.fillText( + value == null ? "" : value, + hAP + (0.707 * 0.707 * oneLineTextHeight), + vAP + textH - (0.707 * 0.707 * oneLineTextHeight) + ); + offlinecanvas.restore(); - //向上倾斜(-45 旋转) - if(tr == "2"){ - canvasName.save(); - canvasName.translate(hAP, vAP + textH); - canvasName.rotate(-45 * Math.PI / 180); - canvasName.translate(-hAP, -(vAP + textH)); - canvasName.fillText(value == null ? "" : value, hAP + (0.707 * 0.707 * oneLineTextHeight), vAP + textH - (0.707 * 0.707 * oneLineTextHeight)); - canvasName.restore(); - - //是否有删除线 - let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); - if(cl == "1" && !isRealNull(value)){ - canvasName.beginPath(); - canvasName.strokeStyle = "#000"; - canvasName.moveTo(hAP + oneLineTextHeight / 2, vAP + textH - oneLineTextHeight / 2); - canvasName.lineTo(hAP + textW - oneLineTextHeight / 2, vAP + oneLineTextHeight / 2); - canvasName.closePath(); - canvasName.stroke(); - } + if(cl == "1" && !isRealNull(value)){ + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#000"; + offlinecanvas.moveTo( + hAP + oneLineTextHeight / 2, + vAP + textH - oneLineTextHeight / 2 + ); + offlinecanvas.lineTo( + hAP + textW - oneLineTextHeight / 2, + vAP + oneLineTextHeight / 2 + ); + offlinecanvas.closePath(); + offlinecanvas.stroke(); } } - else if(tr == "3"){ - if(!isRealNull(value)){ - value = value.toString(); + } + else if(cell.tr == "3"){ + if(!isRealNull(value)){ + value = value.toString(); + + let vArr = []; + if(value.length > 1){ + vArr = value.split(""); + } + else{ + vArr.push(value); + } + + let textW_all = 0; //拆分后宽高度合计 + let textH_all = 0; + + for(let i = 0; i < vArr.length; i++){ + let textW = offlinecanvas.measureText(vArr[i]).width; + let textH = oneLineTextHeight; - let vArr; - if(value.length > 1){ - vArr = value.split(""); + textW_all += textW; + textH_all += textH; + + let hAP = space_width * Store.devicePixelRatio; + if(horizonAlign == "0"){ + hAP = (cellWidth / 2) * Store.devicePixelRatio - (textW / 2); } - else{ - vArr = []; - vArr.push(value); + else if(horizonAlign == "2"){ + hAP = (cellWidth - space_width) * Store.devicePixelRatio - textW; } - - let textW = canvasName.measureText(vArr[0]).width; - let textH = vArr.length * oneLineTextHeight; - - for(let i = 0; i < vArr.length; i++){ - let vWidth = canvasName.measureText(vArr[i]).width; - - //水平对齐计算 - if(horizonAlign == "0"){ - horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (vWidth)/2; - } - else if(horizonAlign == "2"){ - horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (vWidth); - } - else{ - horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; - } - - //垂直对齐计算 - if(verticalAlign == "0"){ - verticalAlignPos = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * vArr.length/2; - } - else if(verticalAlign == "1"){ - verticalAlignPos = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; - } - else{ - verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * vArr.length; - } - - canvasName.fillText(vArr[i], horizonAlignPos, (verticalAlignPos + i * oneLineTextHeight)); + + let vAP = (cellHeight - space_height) * Store.devicePixelRatio - textH * vArr.length; + if(verticalAlign == "0"){ + vAP = (cellHeight / 2) * Store.devicePixelRatio - (textH / 2) * vArr.length; } - - //是否有删除线 - let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); - if(cl == "1" && !isRealNull(value)){ - canvasName.beginPath(); - canvasName.strokeStyle = "#000"; - canvasName.moveTo(horizonAlignPos + textW / 2, verticalAlignPos); - canvasName.lineTo(horizonAlignPos + textW / 2, verticalAlignPos + textH); - canvasName.closePath(); - canvasName.stroke(); + else if(verticalAlign == "1"){ + vAP = space_height * Store.devicePixelRatio; } + + offlinecanvas.fillText(vArr[i], hAP, (vAP + i * textH)); } - } - else if(tr == "4" || tr == "5"){ - //旋转重新计算水平、垂直方向坐标 - let textW = oneLineTextHeight; - let textH = textMetrics; - let hAP = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; - if(horizonAlign == "0"){ - hAP = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textW) / 2; - } - else if(horizonAlign == "2"){ - hAP = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textW); - } + if(cl == "1" && !isRealNull(value)){ + let textW = textW_all / vArr.length; + let textH = textH_all; - let vAP = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - textH; - if(verticalAlign == "0"){ - vAP = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - textH / 2; - } - else if(verticalAlign == "1"){ - vAP = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; - } - - //向下90(90 旋转) - if(tr == "4"){ - canvasName.save(); - canvasName.translate(hAP, vAP); - canvasName.rotate(90 * Math.PI / 180); - canvasName.translate(-hAP, -vAP); - canvasName.fillText(value == null ? "" : value, hAP, vAP - textW); - canvasName.restore(); - - //是否有删除线 - let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); - if(cl == "1" && !isRealNull(value)){ - canvasName.beginPath(); - canvasName.strokeStyle = "#000"; - canvasName.moveTo(hAP + textW / 2, vAP); - canvasName.lineTo(hAP + textW / 2, vAP + textH); - canvasName.closePath(); - canvasName.stroke(); + let hAP = space_width * Store.devicePixelRatio; + if(horizonAlign == "0"){ + hAP = (cellWidth / 2) * Store.devicePixelRatio - (textW / 2); } - } - - //向上90(-90 旋转) - if(tr == "5"){ - canvasName.save(); - canvasName.translate(hAP + textH, vAP); - canvasName.rotate(-90 * Math.PI / 180); - canvasName.translate(-(hAP + textH), -vAP); - canvasName.fillText(value == null ? "" : value, hAP, vAP - textH); - canvasName.restore(); - - //是否有删除线 - let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); - if(cl == "1" && !isRealNull(value)){ - canvasName.beginPath(); - canvasName.strokeStyle = "#000"; - canvasName.moveTo(hAP + textW / 2, vAP); - canvasName.lineTo(hAP + textW / 2, vAP + textH); - canvasName.closePath(); - canvasName.stroke(); + else if(horizonAlign == "2"){ + hAP = (cellWidth - space_width) * Store.devicePixelRatio - textW; + } + + let vAP = (cellHeight - space_height) * Store.devicePixelRatio - textH; + if(verticalAlign == "0"){ + vAP = (cellHeight / 2) * Store.devicePixelRatio - (textH / 2); + } + else if(verticalAlign == "1"){ + vAP = space_height * Store.devicePixelRatio; } + + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#000"; + offlinecanvas.moveTo( + hAP + textW / 2, + vAP + ); + offlinecanvas.lineTo( + hAP + textW / 2, + vAP + textH + ); + offlinecanvas.closePath(); + offlinecanvas.stroke(); } } } - else{ - canvasName.fillText(value == null ? "" : value, horizonAlignPos, verticalAlignPos_text); + else if(cell.tr == "4" || cell.tr == "5"){ + let textW = oneLineTextHeight; + let textH = textMetrics; + + let hAP = space_width * Store.devicePixelRatio; + if(horizonAlign == "0"){ + hAP = (cellWidth / 2) * Store.devicePixelRatio - (textW / 2); + } + else if(horizonAlign == "2"){ + hAP = (cellWidth - space_width) * Store.devicePixelRatio - textW; + } + + let vAP = (cellHeight - space_height) * Store.devicePixelRatio - textH; + if(verticalAlign == "0"){ + vAP = (cellHeight / 2) * Store.devicePixelRatio - (textH / 2); + } + else if(verticalAlign == "1"){ + vAP = space_height * Store.devicePixelRatio; + } + + //向下90(90 旋转) + if(tr == "4"){ + offlinecanvas.save(); + offlinecanvas.translate(hAP, vAP); + offlinecanvas.rotate(90 * Math.PI / 180); + offlinecanvas.translate(-hAP, -vAP); + offlinecanvas.fillText(value == null ? "" : value, hAP, vAP - textW); + offlinecanvas.restore(); + } - //是否有删除线 - let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); + //向上90(-90 旋转) + if(tr == "5"){ + offlinecanvas.save(); + offlinecanvas.translate(hAP + textH, vAP); + offlinecanvas.rotate(-90 * Math.PI / 180); + offlinecanvas.translate(-(hAP + textH), -vAP); + offlinecanvas.fillText(value == null ? "" : value, hAP, vAP - textH); + offlinecanvas.restore(); + } + if(cl == "1" && !isRealNull(value)){ - canvasName.beginPath(); - canvasName.strokeStyle = "#000"; - canvasName.moveTo(horizonAlignPos, verticalAlignPos + oneLineTextHeight / 2); - canvasName.lineTo(horizonAlignPos + textMetrics, verticalAlignPos + oneLineTextHeight / 2); - canvasName.closePath(); - canvasName.stroke(); + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#000"; + offlinecanvas.moveTo(hAP + textW / 2, vAP); + offlinecanvas.lineTo(hAP + textW / 2, vAP + textH); + offlinecanvas.closePath(); + offlinecanvas.stroke(); } } } + else{ + //单元格有下钻属性,文本颜色变成超链接的颜色 + if(cell.dd != null){ + offlinecanvas.fillStyle = "#0000ff"; - //水平对齐方式是 居中或居右对齐 且单元格宽度小于文字宽度 (用离屏canvas渲染) - if(browser.BrowserType() != "Safari" && (canvasType == "offline" || ((horizonAlign == "0" || horizonAlign == "2") && (end_c - start_c) < textW) || ((verticalAlign == "0" || verticalAlign == "2") && (end_r - start_r) < textH))){ - canvasName.font = luckysheetdefaultstyle.font; - - if($("#luckysheetTableContentF").length > 0){ - luckysheetTableContent.drawImage($("#luckysheetTableContentF").get(0), cellsize[0], cellsize[1], cellsize[2], cellsize[3], cellsize[0], cellsize[1], cellsize[2], cellsize[3]); + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#0000ff"; + offlinecanvas.moveTo( + horizonAlignPos, + verticalAlignPos + oneLineTextHeight + ); + offlinecanvas.lineTo( + horizonAlignPos + textMetrics, + verticalAlignPos + oneLineTextHeight + ); + offlinecanvas.stroke(); + offlinecanvas.closePath(); } - else{ - luckysheetTableContent.drawImage(offlineElement, cellsize[0], cellsize[1], cellsize[2], cellsize[3], cellsize[0], cellsize[1], cellsize[2], cellsize[3]); + + offlinecanvas.fillText(value == null ? "" : value, horizonAlignPos, verticalAlignPos_text); + + if(cl == "1" && !isRealNull(value)){ + offlinecanvas.beginPath(); + offlinecanvas.strokeStyle = "#000"; + offlinecanvas.moveTo( + horizonAlignPos, + verticalAlignPos + oneLineTextHeight / 2 + ); + offlinecanvas.lineTo( + horizonAlignPos + textMetrics, + verticalAlignPos + oneLineTextHeight / 2 + ); + offlinecanvas.stroke(); + offlinecanvas.closePath(); } } - luckysheetTableContent.font = luckysheetdefaultstyle.font; + //将离屏canvas 画到主表格canvas上 + luckysheetTableContent.drawImage( + offlinecanvasElement, + 0, + 0, + cellWidth * Store.devicePixelRatio, + cellHeight * Store.devicePixelRatio, + (start_c + offsetLeft) * Store.devicePixelRatio, + (start_r + offsetTop + 1) * Store.devicePixelRatio, + cellWidth * Store.devicePixelRatio, + cellHeight * Store.devicePixelRatio, + ); //右边框 luckysheetTableContent.beginPath(); @@ -1652,22 +1676,1447 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of (fill_row_ed - scrollHeight) * Store.devicePixelRatio ); } - - if(ctx != null){ - ctx.drawImage( - luckysheetTableElement, - 0, - 0, - drawWidth, - drawHeight, - -drawWidth/2 + offsetLeft, - -drawHeight/2 + offsetTop, - drawWidth, - drawHeight - ); - } } +// function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, offsetLeft, offsetTop, columnOffsetCell, rowOffsetCell, mycanvas, ctx, ctxdata) { +// if(ctxdata != null){ +// Store.flowdata = ctxdata; +// } + +// if(Store.flowdata == null){ +// return; +// } + +// if (scrollWidth == null) { +// scrollWidth = $("#luckysheet-cell-main").scrollLeft(); +// } +// if (scrollHeight == null) { +// scrollHeight = $("#luckysheet-cell-main").scrollTop(); +// } + +// if (drawWidth == null) { +// drawWidth = Store.luckysheetTableContentHW[0]; +// } +// if (drawHeight == null) { +// drawHeight = Store.luckysheetTableContentHW[1]; +// } + +// if (offsetLeft == null) { +// offsetLeft = Store.rowHeaderWidth; +// } +// if (offsetTop == null) { +// offsetTop = Store.columeHeaderHeight; +// } + +// if (columnOffsetCell == null) { +// columnOffsetCell = 0; +// } +// if (rowOffsetCell == null) { +// rowOffsetCell = 0; +// } + +// let luckysheetTableContent = null; +// if(ctx != null){ +// let luckysheetTableElement = document.createElement('canvas'); +// luckysheetTableElement.width = drawWidth; +// luckysheetTableElement.height = drawHeight; +// luckysheetTableContent = luckysheetTableElement.getContext("2d"); +// } +// else{ +// if(mycanvas == null){ +// luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d"); +// } +// else { +// if(getObjType(mycanvas) == "object"){ +// try{ +// luckysheetTableContent = mycanvas.get(0).getContext("2d"); +// } +// catch(err){ +// luckysheetTableContent = mycanvas; +// } +// } +// else{ +// luckysheetTableContent = $("#" + mycanvas).get(0).getContext("2d"); +// } +// } +// } + +// luckysheetTableContent.clearRect( +// 0, +// 0, +// Store.luckysheetTableContentHW[0] * Store.devicePixelRatio, +// Store.luckysheetTableContentHW[1] * Store.devicePixelRatio +// ); + +// //离屏canvas +// let offlinecanvas = null; +// if(ctx != null){ +// let offlineElement = document.createElement('canvas'); +// offlineElement.width = drawWidth; +// offlineElement.height = drawHeight; +// offlinecanvas = offlineElement.getContext("2d"); +// } +// else{ +// offlinecanvas = $("#luckysheetTableContentF").get(0).getContext("2d"); +// } +// offlinecanvas.fillStyle = "#ffffff"; +// offlinecanvas.fillRect( +// 0, +// 0, +// Store.luckysheetTableContentHW[0] * Store.devicePixelRatio, +// Store.luckysheetTableContentHW[1] * Store.devicePixelRatio +// ); +// offlinecanvas.font = luckysheetdefaultstyle.font; +// offlinecanvas.textBaseline = "top"; +// offlinecanvas.fillStyle = luckysheetdefaultstyle.fillStyle; + +// // +// let dataset_row_st, dataset_row_ed, dataset_col_st, dataset_col_ed; + +// dataset_row_st = luckysheet_searcharray(Store.visibledatarow, scrollHeight); +// dataset_row_ed = luckysheet_searcharray(Store.visibledatarow, scrollHeight + drawHeight); + +// if (dataset_row_st == -1) { +// dataset_row_st = 0; +// } + +// dataset_row_st += rowOffsetCell; + +// if (dataset_row_ed == -1) { +// dataset_row_ed = Store.visibledatarow.length - 1; +// } + +// dataset_row_ed += rowOffsetCell; + +// if (dataset_row_ed >= Store.visibledatarow.length) { +// dataset_row_ed = Store.visibledatarow.length - 1; +// } + +// dataset_col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollWidth); +// dataset_col_ed = luckysheet_searcharray(Store.visibledatacolumn, scrollWidth + drawWidth); + +// if (dataset_col_st == -1) { +// dataset_col_st = 0; +// } + +// dataset_col_st += columnOffsetCell; + +// if (dataset_col_ed == -1) { +// dataset_col_ed = Store.visibledatacolumn.length - 1; +// } + +// dataset_col_ed += columnOffsetCell; + +// if (dataset_col_ed >= Store.visibledatacolumn.length) { +// dataset_col_ed = Store.visibledatacolumn.length - 1; +// } + + +// let fill_row_st, fill_row_ed, fill_col_st, fill_col_ed; +// if(dataset_row_st == 0){ +// fill_row_st = 0; +// } +// else{ +// fill_row_st = Store.visibledatarow[dataset_row_st - 1]; +// } + +// fill_row_ed = Store.visibledatarow[dataset_row_ed]; + +// if(dataset_col_st == 0){ +// fill_col_st = 0; +// } +// else{ +// fill_col_st = Store.visibledatacolumn[dataset_col_st - 1]; +// } + +// fill_col_ed = Store.visibledatacolumn[dataset_col_ed]; + +// luckysheetTableContent.fillStyle = "#ffffff"; +// luckysheetTableContent.fillRect( +// (offsetLeft - 1) * Store.devicePixelRatio, +// (offsetTop - 1) * Store.devicePixelRatio, +// (fill_col_ed - scrollWidth) * Store.devicePixelRatio, +// (fill_row_ed - scrollHeight) * Store.devicePixelRatio +// ); +// luckysheetTableContent.font = luckysheetdefaultstyle.font; +// luckysheetTableContent.textBaseline = "top"; +// luckysheetTableContent.fillStyle = luckysheetdefaultstyle.fillStyle; + +// let end_r, start_r, end_c, start_c; + +// let cellupdate = []; +// let mergeCache = {}; + +// let borderOffset = {}; + +// for (let r = dataset_row_st; r <= dataset_row_ed; r++) { +// if (r == 0) { +// start_r = -scrollHeight - 1; +// } +// else { +// start_r = Store.visibledatarow[r - 1] - scrollHeight - 1; +// } + +// end_r = Store.visibledatarow[r] - scrollHeight; + +// for (let c = dataset_col_st; c <= dataset_col_ed; c++) { +// if (c == 0) { +// start_c = -scrollWidth; +// } +// else { +// start_c = Store.visibledatacolumn[c - 1] - scrollWidth; +// } + +// end_c = Store.visibledatacolumn[c] - scrollWidth; + +// //横线 +// if(c == dataset_col_ed && !Store.luckysheetcurrentisPivotTable){ +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo( +// Store.devicePixelRatio * (offsetLeft - 1), +// Store.devicePixelRatio * (end_r + offsetTop - 2 + 0.5) +// ); +// luckysheetTableContent.lineTo( +// Store.devicePixelRatio * (fill_col_ed - scrollWidth + offsetLeft - 2), +// Store.devicePixelRatio * (end_r + offsetTop - 2 + 0.5) +// ); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; +// luckysheetTableContent.strokeStyle = luckysheetdefaultstyle.strokeStyle; +// luckysheetTableContent.closePath(); +// luckysheetTableContent.stroke(); +// } + +// //竖线 +// if(r == dataset_row_st && !Store.luckysheetcurrentisPivotTable){ +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo( +// Store.devicePixelRatio * (end_c + offsetLeft - 2 + 0.5), +// Store.devicePixelRatio * (offsetTop - 1) +// ); +// luckysheetTableContent.lineTo( +// Store.devicePixelRatio * (end_c + offsetLeft - 2 + 0.5), +// Store.devicePixelRatio * (fill_row_ed - scrollHeight + offsetTop - 2) +// ); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; +// luckysheetTableContent.strokeStyle = luckysheetdefaultstyle.strokeStyle; +// luckysheetTableContent.closePath(); +// luckysheetTableContent.stroke(); +// } + +// //数据透视表 +// if (!!Store.luckysheetcurrentisPivotTable && pivotTable.drawPivotTable) { +// if ((c == 0 || c == 5) && r <= 11) { +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo( +// Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft), +// Store.devicePixelRatio * (start_r + offsetTop) +// ); +// luckysheetTableContent.lineTo( +// Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft), +// Store.devicePixelRatio * (end_r - 2 + offsetTop) +// ); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; +// luckysheetTableContent.strokeStyle = "#000000"; +// luckysheetTableContent.closePath(); +// luckysheetTableContent.stroke(); +// } + +// if ((r == 2 || r == 11) && c <= 5) { +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo( +// Store.devicePixelRatio * (start_c - 1 + offsetLeft), +// Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop) +// ); +// luckysheetTableContent.lineTo( +// Store.devicePixelRatio * (end_c - 2 + offsetLeft), +// Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop) +// ); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; +// luckysheetTableContent.strokeStyle = "#000000"; +// luckysheetTableContent.closePath(); +// luckysheetTableContent.stroke(); +// } + +// if (r == 6 && c == 3) { +// luckysheetTableContent.fillText( +// "数据透视表", +// Store.devicePixelRatio * (start_c + 4 + offsetLeft), +// Store.devicePixelRatio *(start_r + (end_r - start_r) / 2 - 1 + offsetTop) +// ); +// } +// } +// else if (!!Store.luckysheetcurrentisPivotTable) { +// if (c < pivotTable.pivotTableBoundary[1] && r < pivotTable.pivotTableBoundary[0]) { +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo( +// Store.devicePixelRatio*(end_c - 2 + 0.5 + offsetLeft), +// Store.devicePixelRatio*(start_r + offsetTop) +// ); +// luckysheetTableContent.lineTo( +// Store.devicePixelRatio*(end_c - 2 + 0.5 + offsetLeft), +// Store.devicePixelRatio*(end_r - 2 + offsetTop) +// ); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; +// luckysheetTableContent.strokeStyle = "#000000"; +// luckysheetTableContent.closePath(); +// luckysheetTableContent.stroke(); + +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo( +// Store.devicePixelRatio*(start_c - 1 + offsetLeft), +// Store.devicePixelRatio*(end_r - 2 + 0.5 + offsetTop) +// ); +// luckysheetTableContent.lineTo( +// Store.devicePixelRatio*(end_c - 2 + offsetLeft), +// Store.devicePixelRatio*(end_r - 2 + 0.5 + offsetTop) +// ); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; +// luckysheetTableContent.strokeStyle = "#000000"; +// luckysheetTableContent.closePath(); +// luckysheetTableContent.stroke(); +// } +// } + +// if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) { + +// } +// else { +// let firstcolumlen = Store.defaultcollen; +// if (Store.config["columlen"] != null && Store.config["columlen"][c] != null) { +// firstcolumlen = Store.config["columlen"][c]; +// } + +// if (Store.flowdata[r] != null && Store.flowdata[r][c] != null) { +// let value = Store.flowdata[r][c]; + +// if(getObjType(value) == "object" && ("mc" in value)){ +// borderOffset[r + "_" + c] = { +// "start_r": start_r, +// "start_c": start_c, +// "end_r": end_r, +// "end_c": end_c +// }; + +// if("rs" in value["mc"]){ +// let key = "r"+ r + "c" + c; +// mergeCache[key] = cellupdate.length; +// } +// else{ +// let key = "r"+ value["mc"].r + "c" + value["mc"].c; +// let margeMain = cellupdate[mergeCache[key]]; + +// if(margeMain == null){ +// mergeCache[key] = cellupdate.length; +// cellupdate.push({ +// "r": r, +// "c": c, +// "start_c": start_c, +// "start_r": start_r, +// "end_r": end_r, +// "end_c": end_c, +// "firstcolumlen": firstcolumlen, +// startlist: [] +// }); +// } +// else{ +// if(margeMain.c == c){ +// margeMain.end_r += (end_r - start_r - 1); +// margeMain.startlist.push(start_r); +// } + +// if(margeMain.r == r){ +// margeMain.end_c += (end_c - start_c); +// margeMain.firstcolumlen += firstcolumlen; +// } +// } + +// continue; +// } +// } +// } + +// cellupdate.push({ +// "r": r, +// "c": c, +// "start_r": start_r, +// "start_c": start_c, +// "end_r": end_r, +// "end_c": end_c, +// "firstcolumlen": firstcolumlen, +// startlist: [] +// }); +// borderOffset[r + "_" + c] = { +// "start_r": start_r, +// "start_c": start_c, +// "end_r": end_r, +// "end_c": end_c +// }; +// } +// } +// } + +// //动态数组公式计算 +// let dynamicArray_compute = dynamicArrayCompute(Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray"]); + +// //交替颜色计算 +// let af_compute = alternateformat.getComputeMap(); + +// //条件格式计算 +// let cf_compute = conditionformat.getComputeMap(); + +// //sparklines渲染 +// let sparklinesRender = function(r, c, offsetX, offsetY, canvasid, ctx){ +// if(Store.flowdata[r] == null || Store.flowdata[r][c] == null){ +// return; +// } + +// let sparklines = Store.flowdata[r][c].spl; +// if(sparklines != null){ +// if(typeof sparklines == "string"){ +// sparklines = eval('('+ sparklines +')'); +// } + +// if(getObjType(sparklines) == "object"){ +// let temp1 = sparklines; +// let x = temp1.offsetX; +// let y = temp1.offsetY; +// x = x == null ? 0 : x; +// y = y == null ? 0 : y; +// luckysheetSparkline.render( +// temp1.shapeseq, +// temp1.shapes, +// offsetX + x, +// offsetY + y, +// temp1.pixelWidth, +// temp1.pixelHeight, +// canvasid, +// ctx +// ); +// } +// else if(getObjType(sparklines) == "array" && getObjType(sparklines[0]) == "object"){ +// for(let i = 0; i < sparklines.length; i++){ +// let temp1 = sparklines[i]; +// let x = temp1.offsetX; +// let y = temp1.offsetY; +// x = x == null ? 0 : x; +// y = y == null ? 0 : y; +// luckysheetSparkline.render( +// temp1.shapeseq, +// temp1.shapes, +// offsetX + x, +// offsetY + y, +// temp1.pixelWidth, +// temp1.pixelHeight, +// canvasid, +// ctx +// ); +// } +// } +// } +// } + +// //空白单元格渲染 +// let nullCellRender = function(r, c, start_r, start_c, end_r, end_c){ +// let checksAF = alternateformat.checksAF(r, c, af_compute); //交替颜色 +// let checksCF = conditionformat.checksCF(r, c, cf_compute); //条件格式 + +// let borderfix = menuButton.borderfix(Store.flowdata, r, c); + +// //背景色 +// luckysheetTableContent.fillStyle = menuButton.checkstatus(Store.flowdata, r, c , "bg"); + +// if(checksAF != null && checksAF[1] != null){//交替颜色 +// luckysheetTableContent.fillStyle = checksAF[1]; +// } + +// if(checksCF != null && checksCF["cellColor"] != null){//条件格式 +// luckysheetTableContent.fillStyle = checksCF["cellColor"]; +// } + +// if(Store.flowdata[r][c] != null && Store.flowdata[r][c].tc != null){//标题色 +// luckysheetTableContent.fillStyle = Store.flowdata[r][c].tc; +// } + +// let cellsize = [ +// Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), +// Store.devicePixelRatio * (start_r + offsetTop + 1 + borderfix[1]), +// Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), +// Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) +// ]; +// luckysheetTableContent.fillRect(cellsize[0], cellsize[1], cellsize[2], cellsize[3]); + +// if((r + "_" + c) in dynamicArray_compute){ +// let value = dynamicArray_compute[r + "_" + c].v; + +// luckysheetTableContent.fillStyle = "#000000"; +// //文本宽度和高度 +// let fontset = luckysheetdefaultstyle.font; +// luckysheetTableContent.font = fontset; + +// let textMetrics = luckysheetTableContent.measureText(value).width; +// let oneLineTextHeight = menuButton.getTextSize("田", fontset)[1]; + +// //水平对齐 (默认为1,左对齐) +// let horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; + +// //垂直对齐 (默认为2,下对齐) +// let verticalFixed = browser.luckysheetrefreshfixed(); +// let verticalAlignPos = (end_r + offsetTop - 2) * Store.devicePixelRatio; +// luckysheetTableContent.textBaseline = 'bottom'; + +// luckysheetTableContent.fillText(value == null ? "" : value, horizonAlignPos, verticalAlignPos); +// } + +// //若单元格有批注 +// if(Store.flowdata[r][c] != null && Store.flowdata[r][c].ps != null){ +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo(Store.devicePixelRatio * (end_c + offsetLeft - 6), Store.devicePixelRatio * (start_r + offsetTop)); +// luckysheetTableContent.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 1), Store.devicePixelRatio * (start_r + offsetTop)); +// luckysheetTableContent.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 1), Store.devicePixelRatio * (start_r + offsetTop + 5)); +// luckysheetTableContent.fillStyle = "#FC6666"; +// luckysheetTableContent.fill(); +// luckysheetTableContent.closePath(); +// } + +// //右边框 +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo(Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft), Store.devicePixelRatio * (start_r + offsetTop)); +// luckysheetTableContent.lineTo(Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft), Store.devicePixelRatio * (end_r - 2 + offsetTop)); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; + +// if (!!Store.luckysheetcurrentisPivotTable && !pivotTable.drawPivotTable) { +// luckysheetTableContent.strokeStyle = "#000000"; +// } +// else{ +// luckysheetTableContent.strokeStyle = luckysheetdefaultstyle.strokeStyle; +// } + +// luckysheetTableContent.stroke(); +// luckysheetTableContent.closePath(); + +// //下边框 +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo(Store.devicePixelRatio * (start_c - 2 + offsetLeft), Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop)); +// luckysheetTableContent.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 2), Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop)); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; + +// if (!!Store.luckysheetcurrentisPivotTable && !pivotTable.drawPivotTable) { +// luckysheetTableContent.strokeStyle = "#000000"; +// } +// else{ +// luckysheetTableContent.strokeStyle = luckysheetdefaultstyle.strokeStyle; +// } + +// luckysheetTableContent.stroke(); +// luckysheetTableContent.closePath(); +// } + +// //非空白单元格渲染 +// let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, canvasType){ +// let checksAF = alternateformat.checksAF(r, c, af_compute); //交替颜色 +// let checksCF = conditionformat.checksCF(r, c, cf_compute); //条件格式 + +// let borderfix = menuButton.borderfix(Store.flowdata, r, c); + +// //文本宽度和高度 +// let fontset = luckysheetfontformat(Store.flowdata[r][c]); +// luckysheetTableContent.font = fontset; + +// let measureText = luckysheetTableContent.measureText(value); +// let textMetrics = measureText.width; +// // let oneLineTextHeight = menuButton.getTextSize("田", fontset)[1]; +// // let oneLineTextHeight = menuButton.getTextSize(value, fontset)[1]; +// let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent; + +// let textW, textH; + +// if(Store.flowdata[r][c].tb == "2"){ +// let strValue = value.toString(); +// let tbWidth = luckysheetTableContent.measureText(strValue).width; +// let cellWidth = end_c - start_c - 8; + +// if(tbWidth > cellWidth){ +// let strArr = [];//文本截断数组 +// strArr = getCellTextSplitArr(strValue, strArr, cellWidth, luckysheetTableContent); +// textH = strArr.length * oneLineTextHeight; +// } +// else{ +// textH = oneLineTextHeight; +// } +// } +// else if(Store.flowdata[r][c].tr != null && Store.flowdata[r][c].tr != "0"){ +// let tr = Store.flowdata[r][c].tr; + +// if(tr == "1" || tr == "2"){ +// textW = 0.707 * (textMetrics + oneLineTextHeight); +// textH = 0.707 * (textMetrics + oneLineTextHeight); +// } +// else if(tr == "3"){ +// value = value.toString(); + +// let vArr; +// if(value.length > 1){ +// vArr = value.split(""); +// } +// else{ +// vArr = []; +// vArr.push(value); +// } + +// textW = luckysheetTableContent.measureText(vArr[0]).width; +// textH = vArr.length * oneLineTextHeight; +// } +// else if(tr == "4" || tr == "5"){ +// textW = oneLineTextHeight; +// textH = textMetrics; +// } +// } +// else{ +// textW = textMetrics; +// textH = oneLineTextHeight; +// } + +// //水平对齐 +// let horizonAlign = menuButton.checkstatus(Store.flowdata, r, c , "ht"); +// //垂直对齐 +// let verticalAlign = menuButton.checkstatus(Store.flowdata, r, c , "vt"); + +// //水平对齐方式是 居中或居右对齐 且单元格宽度小于文字宽度 (用离屏canvas渲染) +// let canvasName, cellsize; +// if(browser.BrowserType() != "Safari" && (canvasType == "offline" || ((horizonAlign == "0" || horizonAlign == "2") && (end_c - start_c) < textW) || ((end_r - start_r) < textH))){ +// canvasName = offlinecanvas; +// canvasName.font = fontset; + +// cellsize = [ +// Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), +// Store.devicePixelRatio * (start_r + offsetTop + 0.5 + borderfix[1]), +// Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), +// Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) +// ]; +// } +// else{ +// canvasName = luckysheetTableContent; + +// cellsize = [ +// Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), +// Store.devicePixelRatio * (start_r + offsetTop + 1 + borderfix[1]), +// Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), +// Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) +// ]; +// } + +// //horizonAlign默认为1,左对齐 +// let horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; +// if(horizonAlign == "0"){ +// //居中对齐 +// horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textMetrics) / 2; +// } +// else if(horizonAlign == "2"){ +// //右对齐 +// horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textMetrics); +// } + +// //verticalAlign默认为2,下对齐 +// let verticalFixed = browser.luckysheetrefreshfixed(); +// let verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight; +// let verticalAlignPos_text = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio; +// canvasName.textBaseline = "bottom"; + +// if(verticalAlign == "0"){ +// //居中对齐 +// verticalAlignPos = (start_r + offsetTop + (end_r - start_r) / 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight / 2; +// verticalAlignPos_text = (start_r + offsetTop + (end_r - start_r) / 2 + verticalFixed) * Store.devicePixelRatio; +// canvasName.textBaseline = "middle"; +// } +// else if(verticalAlign == "1"){ +// //上对齐 +// verticalAlignPos = (start_r + offsetTop + 2 + verticalFixed) * Store.devicePixelRatio; +// verticalAlignPos_text = (start_r + offsetTop + 2 + verticalFixed) * Store.devicePixelRatio; +// canvasName.textBaseline = "top"; +// } + +// //单元格 背景颜色 +// canvasName.fillStyle= menuButton.checkstatus(Store.flowdata, r, c , "bg"); + +// //若单元格有交替颜色 背景颜色 +// if(checksAF != null && checksAF[1] != null){ +// canvasName.fillStyle = checksAF[1]; +// } + +// //若单元格有条件格式 背景颜色 +// if(checksCF != null && checksCF["cellColor"] != null){ +// canvasName.fillStyle = checksCF["cellColor"]; +// } + +// //若单元格有标题色 +// if(Store.flowdata[r][c] != null && Store.flowdata[r][c].tc != null){ +// luckysheetTableContent.fillStyle = Store.flowdata[r][c].tc; +// } + +// canvasName.fillRect(cellsize[0], cellsize[1], cellsize[2], cellsize[3]); + +// //若单元格有批注 +// if(Store.flowdata[r][c].ps != null){ +// canvasName.beginPath(); +// canvasName.moveTo(Store.devicePixelRatio * (end_c + offsetLeft - 6), Store.devicePixelRatio * (start_r + offsetTop)); +// canvasName.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 1), Store.devicePixelRatio * (start_r + offsetTop)); +// canvasName.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 1), Store.devicePixelRatio * (start_r + offsetTop + 5)); +// canvasName.fillStyle = "#FC6666"; +// canvasName.fill(); +// canvasName.closePath(); +// } + +// //若单元格有条件格式数据条 +// if(checksCF != null && checksCF["dataBar"] != null){ +// let x = Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0] + 2); +// let y = Store.devicePixelRatio * (start_r + offsetTop + 0.5 + borderfix[1] + 2); +// let w = Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2] - 4); +// let h = Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3] - 4); + +// let valueType = checksCF["dataBar"]["valueType"]; +// let valueLen = checksCF["dataBar"]["valueLen"]; +// let format = checksCF["dataBar"]["format"]; + +// if(format.length > 1){ //渐变 +// if(valueType == "minus"){ +// //负数 +// let minusLen = checksCF["dataBar"]["minusLen"]; + +// let my_gradient = canvasName.createLinearGradient(x + w * minusLen * (1 - valueLen), y, x + w * minusLen, y); +// my_gradient.addColorStop(0, "#ffffff"); +// my_gradient.addColorStop(1, "#ff0000"); +// canvasName.fillStyle = my_gradient; +// canvasName.fillRect(x + w * minusLen * (1 - valueLen), y, w * minusLen * valueLen, h); + +// canvasName.beginPath(); +// canvasName.moveTo(x + w * minusLen * (1 - valueLen), y); +// canvasName.lineTo(x + w * minusLen * (1 - valueLen), y + h); +// canvasName.lineTo(x + w * minusLen, y + h); +// canvasName.lineTo(x + w * minusLen, y); +// canvasName.lineTo(x + w * minusLen * (1 - valueLen), y); +// canvasName.lineWidth = Store.devicePixelRatio; +// canvasName.strokeStyle = "#ff0000"; +// canvasName.stroke(); +// canvasName.closePath(); +// } +// else if(valueType == "plus"){ +// //正数 +// let plusLen = checksCF["dataBar"]["plusLen"]; + +// if(plusLen == 1){ +// let my_gradient = canvasName.createLinearGradient(x, y, x + w * valueLen, y); +// my_gradient.addColorStop(0, format[0]); +// my_gradient.addColorStop(1, format[1]); +// canvasName.fillStyle = my_gradient; +// canvasName.fillRect(x, y, w * valueLen, h); + +// canvasName.beginPath(); +// canvasName.moveTo(x, y); +// canvasName.lineTo(x, y + h); +// canvasName.lineTo(x + w * valueLen, y + h); +// canvasName.lineTo(x + w * valueLen, y); +// canvasName.lineTo(x, y); +// canvasName.lineWidth = Store.devicePixelRatio; +// canvasName.strokeStyle = format[0]; +// canvasName.stroke(); +// canvasName.closePath(); +// } +// else{ +// let minusLen = checksCF["dataBar"]["minusLen"]; + +// let my_gradient = canvasName.createLinearGradient(x + w * minusLen, y, x + w * minusLen + w * plusLen * valueLen, y); +// my_gradient.addColorStop(0, format[0]); +// my_gradient.addColorStop(1, format[1]); +// canvasName.fillStyle = my_gradient; +// canvasName.fillRect(x + w * minusLen, y, w * plusLen * valueLen, h); + +// canvasName.beginPath(); +// canvasName.moveTo(x + w * minusLen, y); +// canvasName.lineTo(x + w * minusLen, y + h); +// canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y + h); +// canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y); +// canvasName.lineTo(x + w * minusLen, y); +// canvasName.lineWidth = Store.devicePixelRatio; +// canvasName.strokeStyle = format[0]; +// canvasName.stroke(); +// canvasName.closePath(); +// } +// } +// } +// else{ //单色 +// if(valueType == "minus"){ +// //负数 +// let minusLen = checksCF["dataBar"]["minusLen"]; + +// canvasName.fillStyle = "#ff0000"; +// canvasName.fillRect(x + w * minusLen * (1 - valueLen), y, w * minusLen * valueLen, h); + +// canvasName.beginPath(); +// canvasName.moveTo(x + w * minusLen * (1 - valueLen), y); +// canvasName.lineTo(x + w * minusLen * (1 - valueLen), y + h); +// canvasName.lineTo(x + w * minusLen, y + h); +// canvasName.lineTo(x + w * minusLen, y); +// canvasName.lineTo(x + w * minusLen * (1 - valueLen), y); +// canvasName.lineWidth = Store.devicePixelRatio; +// canvasName.strokeStyle = "#ff0000"; +// canvasName.stroke(); +// canvasName.closePath(); +// } +// else if(valueType == "plus"){ +// //正数 +// let plusLen = checksCF["dataBar"]["plusLen"]; + +// if(plusLen == 1){ +// canvasName.fillStyle = format[0]; +// canvasName.fillRect(x, y, w * valueLen, h); + +// canvasName.beginPath(); +// canvasName.moveTo(x, y); +// canvasName.lineTo(x, y + h); +// canvasName.lineTo(x + w * valueLen, y + h); +// canvasName.lineTo(x + w * valueLen, y); +// canvasName.lineTo(x, y); +// canvasName.lineWidth = Store.devicePixelRatio; +// canvasName.strokeStyle = format[0]; +// canvasName.stroke(); +// canvasName.closePath(); +// } +// else{ +// let minusLen = checksCF["dataBar"]["minusLen"]; + +// canvasName.fillStyle = format[0]; +// canvasName.fillRect(x + w * minusLen, y, w * plusLen * valueLen, h); + +// canvasName.beginPath(); +// canvasName.moveTo(x + w * minusLen, y); +// canvasName.lineTo(x + w * minusLen, y + h); +// canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y + h); +// canvasName.lineTo(x + w * minusLen + w * plusLen * valueLen, y); +// canvasName.lineTo(x + w * minusLen, y); +// canvasName.lineWidth = Store.devicePixelRatio; +// canvasName.strokeStyle = format[0]; +// canvasName.stroke(); +// canvasName.closePath(); +// } +// } +// } +// } + +// //若单元格有条件格式图标集 +// if(checksCF != null && checksCF["icons"] != null){ +// let l = checksCF["icons"]["left"]; +// let t = checksCF["icons"]["top"]; + +// canvasName.drawImage( +// luckysheet_CFiconsImg, +// l * 42, +// t * 32, +// 32, +// 32, +// cellsize[0], +// verticalAlignPos + 2, +// oneLineTextHeight - 2, +// oneLineTextHeight - 2 +// ); + +// if(horizonAlign != "0" && horizonAlign != "2"){ //左对齐时 文本渲染空出一个图标的距离 +// horizonAlignPos = horizonAlignPos + oneLineTextHeight - 2; +// } +// } + +// //单元格 文本颜色 +// canvasName.fillStyle = menuButton.checkstatus(Store.flowdata, r, c , "fc"); + +// //若单元格有交替颜色 文本颜色 +// if(checksAF != null && checksAF[0] != null){ +// canvasName.fillStyle = checksAF[0]; +// } + +// //若单元格有条件格式 文本颜色 +// if(checksCF != null && checksCF["textColor"] != null){ +// canvasName.fillStyle = checksCF["textColor"]; +// } + +// //单元格有下钻属性,文本颜色变成超链接的颜色 +// if(Store.flowdata[r][c].dd != null){ +// canvasName.fillStyle = "#0000ff"; + +// canvasName.fillText(value == null ? "" : value, horizonAlignPos, verticalAlignPos_text); + +// canvasName.beginPath(); +// canvasName.strokeStyle = "#0000ff"; +// canvasName.moveTo(horizonAlignPos, verticalAlignPos + oneLineTextHeight); +// canvasName.lineTo(horizonAlignPos + textMetrics, verticalAlignPos + oneLineTextHeight); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// else{ +// //自动换行、旋转、删除线功能 +// if(Store.flowdata[r][c].tb == "2"){ +// canvasName.textBaseline = 'top'; //自动换行 textBaseline以top计算 + +// let strValue = value.toString(); +// let cellWidth = end_c - start_c - 8; + +// let strArr = [];//文本截断数组 +// strArr = getCellTextSplitArr(strValue, strArr, cellWidth, canvasName); + +// for(let iFill = 0; iFill < strArr.length; iFill++){ +// //水平对齐计算 +// let strWidth = canvasName.measureText(strArr[iFill]).width; +// if(horizonAlign == "0"){ +// horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (strWidth)/2; +// } +// else if(horizonAlign == "2"){ +// horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (strWidth); +// } + +// //垂直对齐计算 +// if(verticalAlign == "0"){ +// verticalAlignPos = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * strArr.length / 2; +// } +// else if(verticalAlign == "1"){ +// verticalAlignPos = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; +// } +// else{ +// verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * strArr.length; +// } + +// canvasName.fillText(strArr[iFill], horizonAlignPos, (verticalAlignPos + iFill * oneLineTextHeight)); +// } +// } +// else if(Store.flowdata[r][c].tr != null && Store.flowdata[r][c].tr != "0"){ +// canvasName.textBaseline = 'top'; //旋转 textBaseline以top计算 + +// //单元格旋转属性 +// let tr = Store.flowdata[r][c].tr; + +// if(tr == "1" || tr == "2"){ +// //旋转重新计算水平、垂直方向坐标 +// let textW = 0.707 * (textMetrics + oneLineTextHeight); +// let textH = 0.707 * (textMetrics + oneLineTextHeight); + +// let hAP = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; +// if(horizonAlign == "0"){ +// hAP = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textW) / 2; +// } +// else if(horizonAlign == "2"){ +// hAP = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textW); +// } + +// let vAP = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - textH; +// if(verticalAlign == "0"){ +// vAP = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - textH / 2; +// } +// else if(verticalAlign == "1"){ +// vAP = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; +// } + +// //向下倾斜(45 旋转) +// if(tr == "1"){ +// canvasName.save(); +// canvasName.translate(hAP, vAP); +// canvasName.rotate(45 * Math.PI / 180); +// canvasName.translate(-hAP, -vAP); +// canvasName.fillText(value == null ? "" : value, hAP + (0.707 * 0.707 * oneLineTextHeight), vAP - (0.707 * 0.707 * oneLineTextHeight)); +// canvasName.restore(); + +// //是否有删除线 +// let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); +// if(cl == "1" && !isRealNull(value)){ +// canvasName.beginPath(); +// canvasName.strokeStyle = "#000"; +// canvasName.moveTo(hAP + oneLineTextHeight / 2, vAP + oneLineTextHeight / 2); +// canvasName.lineTo(hAP + textW - oneLineTextHeight / 2, vAP + textH - oneLineTextHeight / 2); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// } + +// //向上倾斜(-45 旋转) +// if(tr == "2"){ +// canvasName.save(); +// canvasName.translate(hAP, vAP + textH); +// canvasName.rotate(-45 * Math.PI / 180); +// canvasName.translate(-hAP, -(vAP + textH)); +// canvasName.fillText(value == null ? "" : value, hAP + (0.707 * 0.707 * oneLineTextHeight), vAP + textH - (0.707 * 0.707 * oneLineTextHeight)); +// canvasName.restore(); + +// //是否有删除线 +// let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); +// if(cl == "1" && !isRealNull(value)){ +// canvasName.beginPath(); +// canvasName.strokeStyle = "#000"; +// canvasName.moveTo(hAP + oneLineTextHeight / 2, vAP + textH - oneLineTextHeight / 2); +// canvasName.lineTo(hAP + textW - oneLineTextHeight / 2, vAP + oneLineTextHeight / 2); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// } +// } +// else if(tr == "3"){ +// if(!isRealNull(value)){ +// value = value.toString(); + +// let vArr; +// if(value.length > 1){ +// vArr = value.split(""); +// } +// else{ +// vArr = []; +// vArr.push(value); +// } + +// let textW = canvasName.measureText(vArr[0]).width; +// let textH = vArr.length * oneLineTextHeight; + +// for(let i = 0; i < vArr.length; i++){ +// let vWidth = canvasName.measureText(vArr[i]).width; + +// //水平对齐计算 +// if(horizonAlign == "0"){ +// horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (vWidth)/2; +// } +// else if(horizonAlign == "2"){ +// horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (vWidth); +// } +// else{ +// horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; +// } + +// //垂直对齐计算 +// if(verticalAlign == "0"){ +// verticalAlignPos = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * vArr.length/2; +// } +// else if(verticalAlign == "1"){ +// verticalAlignPos = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; +// } +// else{ +// verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight * vArr.length; +// } + +// canvasName.fillText(vArr[i], horizonAlignPos, (verticalAlignPos + i * oneLineTextHeight)); +// } + +// //是否有删除线 +// let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); +// if(cl == "1" && !isRealNull(value)){ +// canvasName.beginPath(); +// canvasName.strokeStyle = "#000"; +// canvasName.moveTo(horizonAlignPos + textW / 2, verticalAlignPos); +// canvasName.lineTo(horizonAlignPos + textW / 2, verticalAlignPos + textH); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// } +// } +// else if(tr == "4" || tr == "5"){ +// //旋转重新计算水平、垂直方向坐标 +// let textW = oneLineTextHeight; +// let textH = textMetrics; + +// let hAP = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; +// if(horizonAlign == "0"){ +// hAP = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textW) / 2; +// } +// else if(horizonAlign == "2"){ +// hAP = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textW); +// } + +// let vAP = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - textH; +// if(verticalAlign == "0"){ +// vAP = (start_r + (end_r - start_r) / 2 + offsetTop + verticalFixed) * Store.devicePixelRatio - textH / 2; +// } +// else if(verticalAlign == "1"){ +// vAP = (start_r + offsetTop + verticalFixed) * Store.devicePixelRatio; +// } + +// //向下90(90 旋转) +// if(tr == "4"){ +// canvasName.save(); +// canvasName.translate(hAP, vAP); +// canvasName.rotate(90 * Math.PI / 180); +// canvasName.translate(-hAP, -vAP); +// canvasName.fillText(value == null ? "" : value, hAP, vAP - textW); +// canvasName.restore(); + +// //是否有删除线 +// let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); +// if(cl == "1" && !isRealNull(value)){ +// canvasName.beginPath(); +// canvasName.strokeStyle = "#000"; +// canvasName.moveTo(hAP + textW / 2, vAP); +// canvasName.lineTo(hAP + textW / 2, vAP + textH); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// } + +// //向上90(-90 旋转) +// if(tr == "5"){ +// canvasName.save(); +// canvasName.translate(hAP + textH, vAP); +// canvasName.rotate(-90 * Math.PI / 180); +// canvasName.translate(-(hAP + textH), -vAP); +// canvasName.fillText(value == null ? "" : value, hAP, vAP - textH); +// canvasName.restore(); + +// //是否有删除线 +// let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); +// if(cl == "1" && !isRealNull(value)){ +// canvasName.beginPath(); +// canvasName.strokeStyle = "#000"; +// canvasName.moveTo(hAP + textW / 2, vAP); +// canvasName.lineTo(hAP + textW / 2, vAP + textH); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// } +// } +// } +// else{ +// canvasName.fillText(value == null ? "" : value, horizonAlignPos, verticalAlignPos_text); + +// //是否有删除线 +// let cl = menuButton.checkstatus(Store.flowdata, r, c , "cl"); +// if(cl == "1" && !isRealNull(value)){ +// canvasName.beginPath(); +// canvasName.strokeStyle = "#000"; +// canvasName.moveTo(horizonAlignPos, verticalAlignPos + oneLineTextHeight / 2); +// canvasName.lineTo(horizonAlignPos + textMetrics, verticalAlignPos + oneLineTextHeight / 2); +// canvasName.closePath(); +// canvasName.stroke(); +// } +// } +// } + +// //水平对齐方式是 居中或居右对齐 且单元格宽度小于文字宽度 (用离屏canvas渲染) +// if(browser.BrowserType() != "Safari" && (canvasType == "offline" || ((horizonAlign == "0" || horizonAlign == "2") && (end_c - start_c) < textW) || ((verticalAlign == "0" || verticalAlign == "2") && (end_r - start_r) < textH))){ +// canvasName.font = luckysheetdefaultstyle.font; + +// if($("#luckysheetTableContentF").length > 0){ +// luckysheetTableContent.drawImage($("#luckysheetTableContentF").get(0), cellsize[0], cellsize[1], cellsize[2], cellsize[3], cellsize[0], cellsize[1], cellsize[2], cellsize[3]); +// } +// else{ +// luckysheetTableContent.drawImage(offlineElement, cellsize[0], cellsize[1], cellsize[2], cellsize[3], cellsize[0], cellsize[1], cellsize[2], cellsize[3]); +// } +// } + +// luckysheetTableContent.font = luckysheetdefaultstyle.font; + +// //右边框 +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo(Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft), Store.devicePixelRatio * (start_r + offsetTop)); +// luckysheetTableContent.lineTo(Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft), Store.devicePixelRatio * (end_r - 2 + offsetTop)); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; + +// if (!!Store.luckysheetcurrentisPivotTable && !pivotTable.drawPivotTable) { +// luckysheetTableContent.strokeStyle = "#000000"; +// } +// else{ +// luckysheetTableContent.strokeStyle = luckysheetdefaultstyle.strokeStyle; +// } + +// luckysheetTableContent.stroke(); +// luckysheetTableContent.closePath(); + +// //下边框 +// luckysheetTableContent.beginPath(); +// luckysheetTableContent.moveTo(Store.devicePixelRatio * (start_c - 2 + offsetLeft), Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop)); +// luckysheetTableContent.lineTo(Store.devicePixelRatio * (end_c + offsetLeft - 2), Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop)); +// luckysheetTableContent.lineWidth = Store.devicePixelRatio; + +// if (!!Store.luckysheetcurrentisPivotTable && !pivotTable.drawPivotTable) { +// luckysheetTableContent.strokeStyle = "#000000"; +// } +// else{ +// luckysheetTableContent.strokeStyle = luckysheetdefaultstyle.strokeStyle; +// } + +// luckysheetTableContent.stroke(); +// luckysheetTableContent.closePath(); +// } + +// let mcArr = []; + +// for(let cud = 0; cud < cellupdate.length; cud++){ +// let item = cellupdate[cud]; +// let r = item.r, +// c = item.c, +// start_r = item.start_r, +// start_c = item.start_c, +// end_r = item.end_r, +// end_c = item.end_c; +// let firstcolumlen = item.firstcolumlen; + +// if(Store.flowdata[r] == null){ +// continue; +// } + +// if(Store.flowdata[r][c] == null){ //空单元格 +// nullCellRender(r, c, start_r, start_c, end_r, end_c); +// } +// else{ +// let cell = Store.flowdata[r][c]; +// let value = null, er = r, ec = c, end_ec = end_c; + +// if((typeof cell == "object") && "mc" in cell){ +// mcArr.push(cellupdate[cud]); + +// let margeMaindata = cell["mc"]; +// value = getcellvalue(margeMaindata.r, margeMaindata.c, null, "m"); + +// if(value == null){ +// value = getcellvalue(margeMaindata.r, margeMaindata.c); +// } + +// r = margeMaindata.r; +// c = margeMaindata.c; + +// er += margeMaindata.rs; +// ec += margeMaindata.rc; + +// if (c == 0) { +// start_c = -scrollWidth; +// } +// else { +// start_c = Store.visibledatacolumn[c - 1] - scrollWidth; +// } + +// if (r == 0) { +// start_r = -scrollHeight - 1; +// } +// else { +// start_r = Store.visibledatarow[r - 1] - scrollHeight - 1; +// } + +// end_ec = Store.visibledatacolumn[ec] - scrollWidth; +// } +// else{ +// value = getcellvalue(r, c, null, "m"); +// if(value == null){ +// value = getcellvalue(r, c); +// } +// } + +// if(value == null || value.toString().length == 0){ +// nullCellRender(r, c, start_r, start_c, end_r, end_c); + +// //sparklines渲染 +// let borderfix = menuButton.borderfix(Store.flowdata, r, c); +// let cellsize = [ +// Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), +// Store.devicePixelRatio * (start_r + offsetTop + 0.5 + borderfix[1]), +// Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), +// Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) +// ]; +// sparklinesRender(r, c, cellsize[0], cellsize[1], "luckysheetTableContent", luckysheetTableContent); +// } +// else{ +// if((r + "_" + c) in dynamicArray_compute){//动态数组公式 +// value = dynamicArray_compute[r + "_" + c].v; +// } + +// cellRender(r, c, start_r, start_c, end_r, end_c, value); +// } +// } +// } + +// //合并单元格再处理 +// for(let m = 0; m < mcArr.length; m++){ +// let item = mcArr[m]; +// let r = item.r, +// c = item.c, +// start_r = item.start_r, +// start_c = item.start_c, +// end_r = item.end_r, +// end_c = item.end_c; +// let firstcolumlen = item.firstcolumlen; + +// let cell = Store.flowdata[r][c]; +// let value = null, er = r, ec = c, end_ec = end_c; + +// let margeMaindata = cell["mc"]; +// value = getcellvalue(margeMaindata.r, margeMaindata.c, null, "m"); + +// if(value == null){ +// value = getcellvalue(margeMaindata.r, margeMaindata.c); +// } + +// r = margeMaindata.r; +// c = margeMaindata.c; + +// er += margeMaindata.rs; +// ec += margeMaindata.rc; + +// if (c == 0) { +// start_c = -scrollWidth; +// } +// else { +// start_c = Store.visibledatacolumn[c - 1] - scrollWidth; +// } + +// if (r == 0) { +// start_r = -scrollHeight - 1; +// } +// else { +// start_r = Store.visibledatarow[r - 1] - scrollHeight - 1; +// } + +// end_ec = Store.visibledatacolumn[ec] - scrollWidth; + +// if(value == null || value.toString().length == 0){ +// nullCellRender(r, c, start_r, start_c, end_r, end_c); + +// //sparklines渲染 +// let borderfix = menuButton.borderfix(Store.flowdata, r, c); +// let cellsize = [ +// Store.devicePixelRatio * (start_c + offsetLeft + borderfix[0]), +// Store.devicePixelRatio * (start_r + offsetTop + 0.5 + borderfix[1]), +// Store.devicePixelRatio * (end_c - start_c - 3 + borderfix[2]), +// Store.devicePixelRatio * (end_r - start_r - 3 - 0.5 + borderfix[3]) +// ]; +// sparklinesRender(r, c, cellsize[0], cellsize[1], "luckysheetTableContent", luckysheetTableContent); +// } +// else{ +// if((r + "_" + c) in dynamicArray_compute){//动态数组公式 +// value = dynamicArray_compute[r + "_" + c].v; +// } + +// cellRender(r, c, start_r, start_c, end_r, end_c, value, "offline"); +// } +// } + +// //边框单独渲染 +// if(Store.config["borderInfo"] != null && Store.config["borderInfo"].length > 0){ +// //边框渲染 +// let borderLeftRender = function(style, color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, canvas){ +// let linetype = style; + +// let m_st = Store.devicePixelRatio * (start_c - 2 + 0.5 + offsetLeft); +// let m_ed = Store.devicePixelRatio * (start_r + offsetTop); +// let line_st = Store.devicePixelRatio * (start_c - 2 + 0.5 + offsetLeft); +// let line_ed = Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop); + +// menuButton.setLineDash(canvas, linetype, "v", m_st, m_ed, line_st, line_ed); + +// canvas.strokeStyle = color; + +// canvas.stroke(); +// canvas.closePath(); +// canvas.restore(); +// } + +// let borderRightRender = function(style, color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, canvas){ +// let linetype = style; + +// let m_st = Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft); +// let m_ed = Store.devicePixelRatio * (start_r + offsetTop); +// let line_st = Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft); +// let line_ed = Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop); + +// menuButton.setLineDash(canvas, linetype, "v", m_st, m_ed, line_st, line_ed); + +// canvas.strokeStyle = color; + +// canvas.stroke(); +// canvas.closePath(); +// canvas.restore(); +// } + +// let borderBottomRender = function(style, color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, canvas){ +// let linetype = style; + +// let m_st = Store.devicePixelRatio * (start_c - 2 + offsetLeft); +// let m_ed = Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop); +// let line_st = Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft); +// let line_ed = Store.devicePixelRatio * (end_r - 2 + 0.5 + offsetTop); + +// menuButton.setLineDash(canvas, linetype, "h", m_st, m_ed, line_st, line_ed); + +// canvas.strokeStyle = color; + +// canvas.stroke(); +// canvas.closePath(); +// canvas.restore(); +// } + +// let borderTopRender = function(style, color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, canvas){ +// let linetype = style; + +// let m_st = Store.devicePixelRatio * (start_c - 2 + offsetLeft); +// let m_ed = Store.devicePixelRatio * (start_r - 1 + 0.5 + offsetTop); +// let line_st = Store.devicePixelRatio * (end_c - 2 + 0.5 + offsetLeft); +// let line_ed = Store.devicePixelRatio * (start_r - 1 + 0.5 + offsetTop); + +// menuButton.setLineDash(canvas, linetype, "h", m_st, m_ed, line_st, line_ed); + +// canvas.strokeStyle = color; + +// canvas.stroke(); +// canvas.closePath(); +// canvas.restore(); +// } + +// let borderInfoCompute = getBorderInfoCompute(); + +// for(let x in borderInfoCompute){ +// let bd_r = x.split("_")[0], bd_c = x.split("_")[1]; + +// if(borderOffset[bd_r + "_" + bd_c]){ +// let start_r = borderOffset[bd_r + "_" + bd_c].start_r; +// let start_c = borderOffset[bd_r + "_" + bd_c].start_c; +// let end_r = borderOffset[bd_r + "_" + bd_c].end_r; +// let end_c = borderOffset[bd_r + "_" + bd_c].end_c; + +// let borderLeft = borderInfoCompute[x].l; +// if(borderLeft != null){ +// borderLeftRender(borderLeft.style, borderLeft.color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, luckysheetTableContent); +// } + +// let borderRight = borderInfoCompute[x].r; +// if(borderRight != null){ +// borderRightRender(borderRight.style, borderRight.color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, luckysheetTableContent); +// } + +// let borderTop = borderInfoCompute[x].t; +// if(borderTop != null){ +// borderTopRender(borderTop.style, borderTop.color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, luckysheetTableContent); +// } + +// let borderBottom = borderInfoCompute[x].b; +// if(borderBottom != null){ +// borderBottomRender(borderBottom.style, borderBottom.color, start_r, start_c, end_r, end_c, offsetLeft, offsetTop, luckysheetTableContent); +// } +// } +// } +// } + +// //渲染表格时有尾列时,清除右边灰色区域,防止表格有值溢出 +// if(dataset_col_ed == Store.visibledatacolumn.length - 1){ +// luckysheetTableContent.clearRect( +// (fill_col_ed - scrollWidth + offsetLeft - 1) * Store.devicePixelRatio, +// (offsetTop - 1) * Store.devicePixelRatio, +// (Store.ch_width - Store.visibledatacolumn[dataset_col_ed]) * Store.devicePixelRatio, +// (fill_row_ed - scrollHeight) * Store.devicePixelRatio +// ); +// } + +// if(ctx != null){ +// ctx.drawImage( +// luckysheetTableElement, +// 0, +// 0, +// drawWidth, +// drawHeight, +// -drawWidth/2 + offsetLeft, +// -drawHeight/2 + offsetTop, +// drawWidth, +// drawHeight +// ); +// } +// } + function luckysheetDrawMain_back(scrollWidth, scrollHeight, drawWidth, drawHeight, offsetLeft, offsetTop, columnOffsetCell, rowOffsetCell, mycanvas) { if (scrollWidth == null) { scrollWidth = $("#luckysheet-cell-main").scrollLeft(); diff --git a/src/global/formula.js b/src/global/formula.js index 868a554dd..9515f77bd 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -20,7 +20,7 @@ import { luckysheetRangeLast } from './cursorPos'; import { jfrefreshgrid } from './refresh'; import luckysheet_function from '../function/luckysheet_function'; import functionlist from '../function/functionlist'; -import { luckysheet_compareWith, luckysheet_getcelldata } from '../function/func'; +import { luckysheet_compareWith, luckysheet_getcelldata, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check } from '../function/func'; import Store from '../store'; const luckysheetformula = { @@ -1217,6 +1217,8 @@ const luckysheetformula = { } window.luckysheet_getcelldata_cache = null; + + let isRunExecFunction = true; let d = editor.deepCopyFlowData(Store.flowdata); @@ -1245,7 +1247,7 @@ const luckysheetformula = { else{ _this.delFunctionGroup(r, c); _this.execFunctionGroup(r, c, value); - + isRunExecFunction = false; curv = _this.execFunctionGroupData[r][c]; delete curv.f; @@ -1278,6 +1280,7 @@ const luckysheetformula = { else{ _this.delFunctionGroup(r, c); _this.execFunctionGroup(r, c, value); + isRunExecFunction = false; } } @@ -1325,10 +1328,10 @@ const luckysheetformula = { } if(RowlChange){ - jfrefreshgrid(d, [{"row": [r, r], "column": [c, c]}], cfg, null, RowlChange); + jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], cfg, null, RowlChange, isRunExecFunction); } - else{ - jfrefreshgrid(d, [{"row": [r, r], "column": [c, c]}]); + else { + jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], undefined, undefined, undefined, isRunExecFunction); } // Store.luckysheetCellUpdate.length = 0; //clear array @@ -3922,7 +3925,7 @@ const luckysheetformula = { setluckysheetfile(luckysheetfile); }, isFunctionRangeSave: false, - isFunctionRange: function(txt, r, c) { + isFunctionRange1: function(txt, r, c) { let _this = this; if (_this.operatorjson == null) { @@ -4020,12 +4023,12 @@ const luckysheetformula = { let row = range.row, col = range.column; - if((r + "_" + c) in dynamicArray_compute){ + if ((r + "_" + c) in dynamicArray_compute) { let isd_range = false; - for(let d_r = row[0]; d_r <= row[1]; d_r++){ - for(let d_c = col[0]; d_c <= col[1]; d_c++){ - if((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c){ + for (let d_r = row[0]; d_r <= row[1]; d_r++) { + for (let d_c = col[0]; d_c <= col[1]; d_c++) { + if ((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c) { isd_range = true; } } @@ -4033,38 +4036,367 @@ const luckysheetformula = { if (isd_range) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; - } + } else { _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; } } - else{ + else { if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; - } + } else { _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; } } - } + } else { let sheetlen = $.trim(str).split("!"); if (sheetlen.length > 1) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; - } + } else { _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; } } } + else { + //console.log(str); + } } i++; } + //console.log(function_str); + return function_str; + }, + isFunctionRange: function (txt, r, c) { + let _this = this; + if (_this.operatorjson == null) { + let arr = _this.operator.split("|"), + op = {}; + + for (let i = 0; i < arr.length; i++) { + op[arr[i].toString()] = 1; + } + + _this.operatorjson = op; + } + + if (txt.substr(0, 1) == "=") { + txt = txt.substr(1); + } + + let funcstack = txt.split(""); + let i = 0, + str = "", + function_str = "", + ispassby = true; + + let matchConfig = { + "bracket": 0, + "comma": 0, + "squote": 0, + "dquote": 0, + "compare": 0, + "braces": 0 + } + + let luckysheetfile = getluckysheetfile(); + let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"]; + + //bracket 0为运算符括号、1为函数括号 + let cal1 = [], cal2 = [], bracket = []; + + while (i < funcstack.length) { + let s = funcstack[i]; + + if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { + if (str.length > 0 && bracket.length == 0) { + function_str += "luckysheet_function." + str.toUpperCase() + ".f("; + bracket.push(1); + str = ""; + } + else if (bracket.length == 0) { + function_str += "("; + bracket.push(0); + str = ""; + } + else { + bracket.push(0); + str += s; + } + } + else if (s == ")" && matchConfig.dquote == 0 && matchConfig.braces == 0) { + let bt = bracket.pop(); + + if (bracket.length == 0) { + function_str += _this.isFunctionRange(str,r,c) + ")"; + str = ""; + } + else { + str += s; + } + } + else if (s == "{" && matchConfig.dquote == 0) { + str += '{'; + matchConfig.braces += 1; + } + else if (s == "}" && matchConfig.dquote == 0) { + str += '}'; + matchConfig.braces -= 1; + } + else if (s == '"') { + str += '"'; + + if (matchConfig.dquote > 0) { + matchConfig.dquote -= 1; + } + else { + matchConfig.dquote += 1; + } + } + else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { + if (bracket.length <= 1) { + function_str += _this.isFunctionRange(str, r, c) + ","; + str = ""; + } + else { + str += ","; + } + } + else if (s in _this.operatorjson && matchConfig.dquote == 0 && matchConfig.braces == 0) { + let s_next = ""; + let op = _this.operatorPriority; + + if ((i + 1) < funcstack.length) { + s_next = funcstack[i + 1]; + } + + if ((s + s_next) in _this.operatorjson) { + if (bracket.length == 0) { + if ($.trim(str).length > 0) { + cal2.unshift(_this.isFunctionRange($.trim(str), r, c)); + } + else if ($.trim(function_str).length > 0) { + cal2.unshift($.trim(function_str)); + } + + if (cal1[0] in _this.operatorjson) { + let stackCeilPri = op[cal1[0]]; + + while (cal1.length > 0 && stackCeilPri != null) { + cal2.unshift(cal1.shift()); + stackCeilPri = op[cal1[0]]; + } + } + + cal1.unshift(s + s_next); + + function_str = ""; + str = ""; + } + else { + str += s + s_next; + } + + i++; + } + else { + if (bracket.length == 0) { + if ($.trim(str).length > 0) { + cal2.unshift(_this.isFunctionRange($.trim(str), r, c)); + } + else if ($.trim(function_str).length > 0) { + cal2.unshift($.trim(function_str)); + } + + if (cal1[0] in _this.operatorjson) { + let stackCeilPri = op[cal1[0]]; + stackCeilPri = stackCeilPri == null ? 1000 : stackCeilPri; + + let sPri = op[s]; + sPri = sPri == null ? 1000 : sPri; + + while (cal1.length > 0 && sPri >= stackCeilPri) { + cal2.unshift(cal1.shift()); + + stackCeilPri = op[cal1[0]]; + stackCeilPri = stackCeilPri == null ? 1000 : stackCeilPri; + } + } + + cal1.unshift(s); + + function_str = ""; + str = ""; + } + else { + str += s; + } + } + } + else { + if (matchConfig.dquote == 0) { + str += $.trim(s); + } + else { + str += s; + } + } + + if (i == funcstack.length - 1) { + let endstr = ""; + + if (_this.iscelldata($.trim(str))) { + endstr = "luckysheet_getcelldata('" + $.trim(str) + "')"; + + _this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute); + } + else { + str = $.trim(str); + + let regx = /{.*?}/; + if (regx.test(str) && str.substr(0, 1) != '"' && str.substr(str.length - 1, 1) != '"') { + let arraytxt = regx.exec(str)[0]; + let arraystart = str.search(regx); + let alltxt = ""; + + if (arraystart > 0) { + endstr += str.substr(0, arraystart); + } + + endstr += "luckysheet_getarraydata('" + arraytxt + "')"; + + if (arraystart + arraytxt.length < str.length) { + endstr += str.substr(arraystart + arraytxt.length, str.length); + } + } + else { + endstr = str; + } + } + + if (endstr.length > 0) { + cal2.unshift(endstr); + } + + if (cal1.length > 0) { + if (function_str.length > 0) { + cal2.unshift(function_str); + function_str = ""; + } + + while (cal1.length > 0) { + cal2.unshift(cal1.shift()); + } + } + + if (cal2.length > 0) { + function_str = _this.calPostfixExpression(cal2); + } + else { + function_str += endstr; + } + } + + i++; + } + //console.log(function_str); + _this.checkSpecialFunctionRange(function_str, r, c, dynamicArray_compute); return function_str; }, + isFunctionRangeSaveChange: function (str, r, c, dynamicArray_compute) { + let _this = this; + if (r != null && c != null) { + let range = _this.getcellrange($.trim(str)); + let row = range.row, + col = range.column; + + if ((r + "_" + c) in dynamicArray_compute) { + let isd_range = false; + + for (let d_r = row[0]; d_r <= row[1]; d_r++) { + for (let d_c = col[0]; d_c <= col[1]; d_c++) { + if ((d_r + "_" + d_c) in dynamicArray_compute && dynamicArray_compute[d_r + "_" + d_c].r == r && dynamicArray_compute[d_r + "_" + d_c].c == c) { + isd_range = true; + } + } + } + + if (isd_range) { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; + } + else { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; + } + } + else { + if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1]) { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; + } + else { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; + } + } + } + else { + let sheetlen = $.trim(str).split("!"); + + if (sheetlen.length > 1) { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; + } + else { + _this.isFunctionRangeSave = _this.isFunctionRangeSave || false; + } + } + }, + checkSpecialFunctionRange: function (function_str, r, c, dynamicArray_compute) { + if (!window.luckysheet_indirect_check) { + window.luckysheet_indirect_check = luckysheet_indirect_check; + window.luckysheet_indirect_check_return = luckysheet_indirect_check_return; + window.luckysheet_offset_check = luckysheet_offset_check; + } + if (function_str.substr(0, 20) == "luckysheet_function.") { + let funcName = function_str.split(".")[1]; + if (funcName != null) { + funcName = funcName.toUpperCase(); + if (funcName == "INDIRECT") { + let tempFunc = "luckysheet_indirect_check" + function_str.substr(30, function_str.length); + + //tempFunc = tempFunc.replace(/luckysheet_getcelldata/g, "luckysheet_indirect_check_return"); + + try { + let str = eval(tempFunc); + if (this.iscelldata($.trim(str))) { + this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute); + console.log(function_str, str, this.isFunctionRangeSave,r,c); + } + } + catch{ + + } + } + else if (funcName == "OFFSET") { + let tempFunc = "luckysheet_offset_check" + function_str.substr(28, function_str.length); + + let str = eval(tempFunc); + if (this.iscelldata($.trim(str))) { + this.isFunctionRangeSaveChange(str, r, c, dynamicArray_compute); + + //console.log(function_str, str, this.isFunctionRangeSave,r,c); + } + + //let result = eval(function_str); + + //console.log(function_str, result); + } + } + + } + }, execvertex: {}, execFunctionGroupData: null, execFunctionExist: null, @@ -4332,10 +4664,10 @@ const luckysheetformula = { quotalen += quota2.length; } - if ((fp.substr(0, 16) == "luckysheet_function." || fp.substr(0, 18) == "luckysheet_compareWith") && funclen != quotalen / 2) { + if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") && funclen != quotalen / 2) { fp += ")"; - if(fp.substr(0, 16) == "luckysheet_function."){ + if(fp.substr(0, 20) == "luckysheet_function."){ txt += ")"; } @@ -4410,7 +4742,7 @@ const luckysheetformula = { let fp = $.trim(_this.functionParser(txt)); - if ((fp.substr(0, 16) == "luckysheet_function." || fp.substr(0, 18) == "luckysheet_compareWith") ) { + if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") ) { _this.functionHTMLIndex = 0; } diff --git a/src/global/refresh.js b/src/global/refresh.js index 7a281014e..4f3abe81f 100644 --- a/src/global/refresh.js +++ b/src/global/refresh.js @@ -18,19 +18,21 @@ import { createFilterOptions } from '../controllers/filter'; import { getSheetIndex } from '../methods/get'; import Store from '../store'; -function jfrefreshgrid(data, range, cfg, cdformat, RowlChange) { +function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction=true) { //单元格数据更新联动 - formula.execFunctionExist = []; - for(let s = 0; s < range.length; s++){ - for(let r = range[s].row[0]; r <= range[s].row[1]; r++){ - for(let c = range[s].column[0]; c <= range[s].column[1]; c++){ - formula.execFunctionExist.push({ "r": r, "c": c, "i": Store.currentSheetIndex }); + if (isRunExecFunction) { + formula.execFunctionExist = []; + for(let s = 0; s < range.length; s++){ + for(let r = range[s].row[0]; r <= range[s].row[1]; r++){ + for(let c = range[s].column[0]; c <= range[s].column[1]; c++){ + formula.execFunctionExist.push({ "r": r, "c": c, "i": Store.currentSheetIndex }); + } } } + formula.execFunctionExist.reverse(); + formula.execFunctionGroup(null, null, null, null, data); + formula.execFunctionGroupData = null; } - formula.execFunctionExist.reverse(); - formula.execFunctionGroup(null, null, null, null, data); - formula.execFunctionGroupData = null; if (Store.clearjfundo) { Store.jfundo = [];