diff --git a/src/config.js b/src/config.js index d224d2d..3ee1d32 100644 --- a/src/config.js +++ b/src/config.js @@ -54,4 +54,6 @@ export default { forceCalculation:false,//强制刷新公式,公式较多会有性能问题,慎用 rowHeaderWidth: 46, columeHeaderHeight: 20, + defaultColWidth:73, + defaultRowHeight:19, } \ No newline at end of file diff --git a/src/controllers/luckysheetConfigsetting.js b/src/controllers/luckysheetConfigsetting.js index 757f831..656d1c0 100644 --- a/src/controllers/luckysheetConfigsetting.js +++ b/src/controllers/luckysheetConfigsetting.js @@ -29,6 +29,9 @@ const luckysheetConfigsetting = { fireMousedown: null, plugins:[], forceCalculation:false,//强制刷新公式,公式较多会有性能问题,慎用 + + defaultColWidth:73, + defaultRowHeight:19, } export default luckysheetConfigsetting; \ No newline at end of file diff --git a/src/controllers/server.js b/src/controllers/server.js index 340a906..d0aa867 100644 --- a/src/controllers/server.js +++ b/src/controllers/server.js @@ -404,7 +404,6 @@ const server = { } let r = value.r, c = value.c; - let func = value.func; let calcChain = file["calcChain"] == null ? [] : file["calcChain"]; @@ -418,13 +417,13 @@ const server = { } } } - else if(op == "update"){ - for(let a = 0; a < calcChain.length; a++){ - if(r == calcChain[a].r && c == calcChain[a].c && index == calcChain[a].index){ - calcChain[a].func = func; - } - } - } + // else if(op == "update"){ + // for(let a = 0; a < calcChain.length; a++){ + // if(r == calcChain[a].r && c == calcChain[a].c && index == calcChain[a].index){ + // calcChain[a].func = func; + // } + // } + // } setTimeout(function () { luckysheetrefreshgrid(); diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index ae27a66..cdf7b94 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -1,6 +1,6 @@ import { isEditMode } from '../global/validate'; import cleargridelement from '../global/cleargridelement'; -import { getcellvalue, datagridgrowth } from '../global/getdata'; +import { getcellvalue, datagridgrowth,getcellFormula } from '../global/getdata'; import { setcellvalue } from '../global/setdata'; import luckysheetcreatedom from '../global/createdom'; import tooltip from '../global/tooltip'; @@ -598,14 +598,7 @@ const sheetmanage = { return data; }, - initialjfFile: function(menu, title) { - let _this = this; - - _this.getCurSheet(); - let file = Store.luckysheetfile[_this.getSheetIndex(Store.currentSheetIndex)]; - _this.nulldata = datagridgrowth([], Store.defaultrowNum, Store.defaultcolumnNum); - let data = _this.buildGridData(file); - + sheetParamRestore: function(file, data) { Store.luckysheet_select_save = file["luckysheet_select_save"]; if(Store.luckysheet_select_save == null || Store.luckysheet_select_save.length == 0){ if(data[0] != null && data[0][0] != null && data[0][0].mc != null){ @@ -627,6 +620,43 @@ const sheetmanage = { Store.zoomRatio = file["zoomRatio"] == null ? 1 : file["zoomRatio"]; + if(file["defaultRowHeight"]!=null){ + Store.defaultrowlen = parseFloat(file["defaultRowHeight"]); + } + else{ + Store.defaultrowlen = luckysheetConfigsetting["defaultRowHeight"]; + } + + if(file["defaultColWidth"]!=null){ + Store.defaultcollen = parseFloat(file["defaultColWidth"]); + } + else{ + Store.defaultcollen = luckysheetConfigsetting["defaultColWidth"]; + } + + if(file["showGridLines"]!=null){ + let showGridLines = file["showGridLines"]; + if(showGridLines==0 || showGridLines==false){ + Store.showGridLines = false; + } + else{ + Store.showGridLines = true; + } + } + else{ + Store.showGridLines = true; + } + }, + initialjfFile: function(menu, title) { + let _this = this; + + _this.getCurSheet(); + let file = Store.luckysheetfile[_this.getSheetIndex(Store.currentSheetIndex)]; + _this.nulldata = datagridgrowth([], Store.defaultrowNum, Store.defaultcolumnNum); + let data = _this.buildGridData(file); + + this.sheetParamRestore(file, data); + let r2 = Store.luckysheet_select_save[0].row[1], c2 = Store.luckysheet_select_save[0].column[1]; @@ -833,25 +863,7 @@ const sheetmanage = { luckysheetPostil.buildAllPs(Store.flowdata); - Store.config = file["config"]; - - Store.luckysheet_select_save = file["luckysheet_select_save"]; - if(Store.luckysheet_select_save == null || Store.luckysheet_select_save.length == 0){ - if(Store.flowdata[0] != null && Store.flowdata[0][0] != null && Store.flowdata[0][0].mc != null){ - Store.luckysheet_select_save = [{ - "row": [0, Store.flowdata[0][0].mc.rs - 1], - "column": [0, Store.flowdata[0][0].mc.cs - 1] - }]; - } - else{ - Store.luckysheet_select_save = [{ - "row": [0, 0], - "column": [0, 0] - }]; - } - } - - Store.luckysheet_selection_range = file["luckysheet_selection_range"] == null ? [] : file["luckysheet_selection_range"]; + this.sheetParamRestore(file, Store.flowdata); if(file["freezen"] == null){ luckysheetFreezen.freezenhorizontaldata = null; @@ -862,13 +874,6 @@ const sheetmanage = { luckysheetFreezen.freezenverticaldata = file["freezen"].vertical == null ? null : file["freezen"].vertical.freezenverticaldata; } - if(file["zoomRatio"] != null){ - Store.zoomRatio = file["zoomRatio"]; - } - else{ - Store.zoomRatio = 1; - } - createFilterOptions(file["filter_select"], file["filter"]); rhchInit(Store.flowdata.length, Store.flowdata[0].length); @@ -908,7 +913,11 @@ const sheetmanage = { mergeCalculationSheet:{}, mergeCalculation:function(index){ let file = Store.luckysheetfile[this.getSheetIndex(index)]; - let config = file.config, data = file.data, mergeConfig = config.merge; + let config = file.config, data = file.data; + if(config==null){ + return; + } + let mergeConfig = config.merge; if(mergeConfig==null || index in this.mergeCalculationSheet || file["autoCalculationMerge"]===false){ return; } @@ -1080,9 +1089,10 @@ const sheetmanage = { let dataNameList = {}; for(let i = 0; i < calchain.length; i++){ let f = calchain[i]; - let dataindex = f.index, func = f.func; + let dataindex = f.index; + let formulaTxt = getcellFormula(f.r, f.c, dataindex); - formula.functionParser(func[2], (str)=>{ + formula.functionParser(formulaTxt, (str)=>{ if(str.indexOf("!")>-1){ let name = str.substr(0, str.indexOf('!')); dataNameList[name] = true; @@ -1142,7 +1152,7 @@ const sheetmanage = { return ret; }, showSheet: function() { - changeSheetContainerSize(); + // changeSheetContainerSize(); $("#luckysheet-cell-flow_0").css({ "width": Store.ch_width, "top": "-1px" }); //width更新 $("#luckysheet-sheettable_0").css({ "width": Store.ch_width - 1, "height": Store.rh_height }); $("#luckysheetrowHeader_0").css("height", Store.rh_height); @@ -1523,13 +1533,12 @@ const sheetmanage = { } let r = value.r, c = value.c; - let func = value.func; if(op == "del" ){ formula.delFunctionGroup(r, c, index); } else { - formula.insertUpdateFunctionGroup(r, c, func, index); + formula.insertUpdateFunctionGroup(r, c, index); } } else if(type == "cg"){ diff --git a/src/core.js b/src/core.js index 402a6c5..393da8a 100644 --- a/src/core.js +++ b/src/core.js @@ -92,6 +92,9 @@ luckysheet.create = function (setting) { luckysheetConfigsetting.rowHeaderWidth = extendsetting.rowHeaderWidth; luckysheetConfigsetting.columeHeaderHeight = extendsetting.columeHeaderHeight; + luckysheetConfigsetting.defaultColWidth = extendsetting.defaultColWidth; + luckysheetConfigsetting.defaultRowHeight = extendsetting.defaultRowHeight; + // Register plugins initPlugins(extendsetting.plugins , extendsetting.data); diff --git a/src/demoData/sheetCell.js b/src/demoData/sheetCell.js index 8923485..9bb103a 100644 --- a/src/demoData/sheetCell.js +++ b/src/demoData/sheetCell.js @@ -1171,6 +1171,8 @@ const sheetCell = { }, "index": "0", "zoomRatio":1, + // "defaultColWidth":20, + // "showGridLines":0, "chart": [], "status": "1", "order": "0", diff --git a/src/demoData/sheetFormula.js b/src/demoData/sheetFormula.js index 9749d1e..70ce9b4 100644 --- a/src/demoData/sheetFormula.js +++ b/src/demoData/sheetFormula.js @@ -6399,7 +6399,7 @@ const sheetFormula = { "r": 6, "c": 3, "index": 1, - "func": [true, 23.75, "=AVERAGE(D3:D6)"], + // "func": [true, 23.75, "=AVERAGE(D3:D6)"], "color": "w", "parent": null, "chidren": {}, @@ -6408,7 +6408,7 @@ const sheetFormula = { "r": 7, "c": 3, "index": 1, - "func": [true, 30, "=MAX(D3:D6)"], + // "func": [true, 30, "=MAX(D3:D6)"], "color": "w", "parent": null, "chidren": {}, @@ -6417,7 +6417,7 @@ const sheetFormula = { "r": 8, "c": 3, "index": 1, - "func": [true, 17, "=MIN(D3:D6)"], + // "func": [true, 17, "=MIN(D3:D6)"], "color": "w", "parent": null, "chidren": {}, @@ -6426,7 +6426,7 @@ const sheetFormula = { "r": 5, "c": 9, "index": 1, - "func": [true, "J2", "=INDIRECT(\"I2\")"], + // "func": [true, "J2", "=INDIRECT(\"I2\")"], "color": "w", "parent": null, "chidren": {}, @@ -6435,7 +6435,7 @@ const sheetFormula = { "r": 6, "c": 9, "index": 1, - "func": [true, 1, "=INDIRECT(I2)"], + // "func": [true, 1, "=INDIRECT(I2)"], "color": "w", "parent": null, "chidren": {}, @@ -6444,7 +6444,7 @@ const sheetFormula = { "r": 7, "c": 9, "index": 1, - "func": [true, "I", "=INDIRECT(\"I\"&(1+2))"], + // "func": [true, "I", "=INDIRECT(\"I\"&(1+2))"], "color": "w", "parent": null, "chidren": {}, @@ -6453,7 +6453,7 @@ const sheetFormula = { "r": 8, "c": 9, "index": 1, - "func": [true, 1, "=INDIRECT(I4&J3)"], + // "func": [true, 1, "=INDIRECT(I4&J3)"], "color": "w", "parent": null, "chidren": {}, @@ -6462,7 +6462,7 @@ const sheetFormula = { "r": 16, "c": 7, "index": 1, - "func": [true, 152, "=SUBTOTAL(9,OFFSET(F15,ROW(F15:F18)-ROW(F15),1,3))"], + // "func": [true, 152, "=SUBTOTAL(9,OFFSET(F15,ROW(F15:F18)-ROW(F15),1,3))"], "color": "w", "parent": null, "chidren": {}, @@ -6471,7 +6471,7 @@ const sheetFormula = { "r": 17, "c": 7, "index": 1, - "func": [true, 541, "=SUBTOTAL(9,OFFSET(G15,ROW(G15:G18)-ROW(G15),1,3))"], + // "func": [true, 541, "=SUBTOTAL(9,OFFSET(G15,ROW(G15:G18)-ROW(G15),1,3))"], "color": "w", "parent": null, "chidren": {}, @@ -6480,7 +6480,7 @@ const sheetFormula = { "r": 22, "c": 8, "index": 1, - "func": [true, "dumpling", "=INDEX(D21:D25,MATCH(\"dumpling\",D21:D25),1)"], + // "func": [true, "dumpling", "=INDEX(D21:D25,MATCH(\"dumpling\",D21:D25),1)"], "color": "w", "parent": null, "chidren": {}, @@ -6489,7 +6489,7 @@ const sheetFormula = { "r": 38, "c": 6, "index": 1, - "func": [true, 1, "=SUM(IF((C31:C39=\"Fax\")+(D31:D39=\"Jones\")<>2,1,0))"], + // "func": [true, 1, "=SUM(IF((C31:C39=\"Fax\")+(D31:D39=\"Jones\")<>2,1,0))"], "color": "w", "parent": null, "chidren": {}, @@ -6498,7 +6498,7 @@ const sheetFormula = { "r": 30, "c": 6, "index": 1, - "func": [true, "#NAME?", "=SUM((C31:C39=\"Fax\")*(D31:D39=\"Brown\")*(E31:E39))"], + // "func": [true, "#NAME?", "=SUM((C31:C39=\"Fax\")*(D31:D39=\"Brown\")*(E31:E39))"], "color": "w", "parent": null, "chidren": {}, @@ -6507,7 +6507,7 @@ const sheetFormula = { "r": 32, "c": 6, "index": 1, - "func": [true, "#NAME?", "=SUM((C31:C39=\"Fax\")*(D31:D39=\"Brown\"))"], + // "func": [true, "#NAME?", "=SUM((C31:C39=\"Fax\")*(D31:D39=\"Brown\"))"], "color": "w", "parent": null, "chidren": {}, @@ -6516,7 +6516,7 @@ const sheetFormula = { "r": 34, "c": 6, "index": 1, - "func": [true, 1, "=SUM(IF((C31:C39=\"Fax\")+(D31:D39=\"Jones\"),1,0))"], + // "func": [true, 1, "=SUM(IF((C31:C39=\"Fax\")+(D31:D39=\"Jones\"),1,0))"], "color": "w", "parent": null, "chidren": {}, @@ -6525,7 +6525,7 @@ const sheetFormula = { "r": 36, "c": 6, "index": 1, - "func": [true, 1, "=SUM(IF(MOD((C31:C39=\"Fax\")+(D31:D39=\"Jones\"),2),1,0))"], + // "func": [true, 1, "=SUM(IF(MOD((C31:C39=\"Fax\")+(D31:D39=\"Jones\"),2),1,0))"], "color": "w", "parent": null, "chidren": {}, @@ -6534,7 +6534,7 @@ const sheetFormula = { "r": 9, "c": 9, "index": 1, - "func": [true, 1, "=INDIRECT(\"Formula!\"&I2)"], + // "func": [true, 1, "=INDIRECT(\"Formula!\"&I2)"], "color": "w", "parent": null, "chidren": {}, @@ -6543,7 +6543,7 @@ const sheetFormula = { "r": 10, "c": 9, "index": 1, - "func": [true, "J2", "=INDIRECT(\"Formula!I2\")"], + // "func": [true, "J2", "=INDIRECT(\"Formula!I2\")"], "color": "w", "parent": null, "chidren": {}, @@ -6552,7 +6552,7 @@ const sheetFormula = { "r": 14, "c": 7, "index": 1, - "func": [true, 207, "=SUBTOTAL(9,OFFSET($D$15,ROW($D$15:$D$18)-ROW($D$15),1,3))"], + // "func": [true, 207, "=SUBTOTAL(9,OFFSET($D$15,ROW($D$15:$D$18)-ROW($D$15),1,3))"], "color": "w", "parent": null, "chidren": {}, @@ -6561,7 +6561,7 @@ const sheetFormula = { "r": 15, "c": 7, "index": 1, - "func": [true, 182, "=SUBTOTAL(9,OFFSET(E15,ROW(E15:E18)-ROW(E15),1,3))"], + // "func": [true, 182, "=SUBTOTAL(9,OFFSET(E15,ROW(E15:E18)-ROW(E15),1,3))"], "color": "w", "parent": null, "chidren": {}, @@ -6570,7 +6570,7 @@ const sheetFormula = { "r": 23, "c": 8, "index": 1, - "func": [true, false, "=ISNA(MATCH(D21:D25,C21:C27,0))"], + // "func": [true, false, "=ISNA(MATCH(D21:D25,C21:C27,0))"], "color": "w", "parent": null, "chidren": {}, diff --git a/src/global/createdom.js b/src/global/createdom.js index 4531bcd..499dc13 100644 --- a/src/global/createdom.js +++ b/src/global/createdom.js @@ -110,6 +110,10 @@ export default function luckysheetcreatedom(colwidth, rowheight, data, menu, tit $("body").append(replaceHtml(filtersubmenuHTML(), { "menuid": "filter" })); $("body").append(sheetconfigHTML()); + $("#luckysheet-rows-h").width((Store.rowHeaderWidth-1.5)); + $("#luckysheet-cols-h-c").height((Store.columeHeaderHeight-1.5)); + $("#luckysheet-left-top").css({width:Store.rowHeaderWidth-1.5, height:Store.columeHeaderHeight-1.5}); + //批注 luckysheetPostil.buildAllPs(Store.flowdata); } \ No newline at end of file diff --git a/src/global/draw.js b/src/global/draw.js index 4da0812..bbc1ee9 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -623,7 +623,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of if((r + "_" + c) in dynamicArray_compute){//动态数组公式 value = dynamicArray_compute[r + "_" + c].v; } - + cellRender(r, c, start_r, start_c, end_r, end_c, value,luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05); } } @@ -653,6 +653,8 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of r = margeMaindata.r; c = margeMaindata.c; + let mainCell = Store.flowdata[r][c]; + if (c == 0) { start_c = -scrollWidth; } @@ -667,8 +669,8 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of start_r = Store.visibledatarow[r - 1] - scrollHeight - 1; } - end_r = Store.visibledatarow[r+margeMaindata.rs-1] - scrollHeight; - end_c = Store.visibledatacolumn[c+margeMaindata.cs-1] - scrollWidth; + end_r = Store.visibledatarow[r+mainCell["mc"].rs-1] - scrollHeight; + end_c = Store.visibledatacolumn[c+mainCell["mc"].cs-1] - scrollWidth; if(value == null || value.toString().length == 0){ nullCellRender(r, c, start_r, start_c, end_r, end_c,luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05, true); @@ -687,7 +689,6 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of if((r + "_" + c) in dynamicArray_compute){//动态数组公式 value = dynamicArray_compute[r + "_" + c].v; } - cellRender(r, c, start_r, start_c, end_r, end_c, value, luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05, true); } } @@ -997,7 +998,7 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab } if(fillStyle==null){ - luckysheetTableContent.fillStyle = "rgba(255,255,255)"; + luckysheetTableContent.fillStyle = "#FFFFFF"; } else{ luckysheetTableContent.fillStyle = fillStyle; @@ -1063,7 +1064,7 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab //即溢出单元格跨此单元格,此单元格不绘制右边框 if(!cellOverflow_colInObj.colIn || cellOverflow_colInObj.colLast){ //右边框 - if(!Store.luckysheetcurrentisPivotTable && !fillStyle){ + if(!Store.luckysheetcurrentisPivotTable && !fillStyle && Store.showGridLines){ luckysheetTableContent.beginPath(); luckysheetTableContent.moveTo( (end_c + offsetLeft - 2 + bodrder05), @@ -1082,7 +1083,7 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab } //下边框 - if(!Store.luckysheetcurrentisPivotTable && !fillStyle){ + if(!Store.luckysheetcurrentisPivotTable && !fillStyle && Store.showGridLines){ luckysheetTableContent.beginPath(); luckysheetTableContent.moveTo( (start_c + offsetLeft - 2), @@ -1137,7 +1138,7 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee } if(fillStyle==null){ - luckysheetTableContent.fillStyle = "rgba(255,255,255)"; + luckysheetTableContent.fillStyle = "#FFFFFF"; } else{ luckysheetTableContent.fillStyle = fillStyle; @@ -1162,7 +1163,7 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee //若单元格有批注(单元格右上角红色小三角标示) if(cell.ps != null){ - let ps_w = 5*Store.zoomRatio, ps_h = 5*Store.zoomRatio; //红色小三角宽高 + let ps_w = 8*Store.zoomRatio, ps_h = 8*Store.zoomRatio; //红色小三角宽高 luckysheetTableContent.beginPath(); luckysheetTableContent.moveTo( @@ -1401,13 +1402,15 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee horizonAlignPos = (pos_x + cellWidth - space_width) - textMetrics; } - let verticalAlignPos = (pos_y + cellHeight - space_height) - oneLineTextHeight; //默认为2,下对齐 - let verticalAlignPos_text = (pos_y + cellHeight - space_height) ; //文本垂直方向基准线 + let verticalCellHeight = cellHeight>oneLineTextHeight?cellHeight:oneLineTextHeight; + + let verticalAlignPos = (pos_y + verticalCellHeight - space_height) - oneLineTextHeight; //默认为2,下对齐 + let verticalAlignPos_text = (pos_y + verticalCellHeight - space_height) ; //文本垂直方向基准线 luckysheetTableContent.textBaseline = "bottom"; if(verticalAlign == "0"){ //居中对齐 - verticalAlignPos = (pos_y + cellHeight / 2) - (oneLineTextHeight / 2); + verticalAlignPos = (pos_y + verticalCellHeight / 2) - (oneLineTextHeight / 2); - verticalAlignPos_text = (pos_y + cellHeight / 2) ; + verticalAlignPos_text = (pos_y + verticalCellHeight / 2) ; luckysheetTableContent.textBaseline = "middle"; } else if(verticalAlign == "1"){ //上对齐 @@ -1910,7 +1913,7 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee if(cellOverflow_bd_r_render){ //右边框 - if(!Store.luckysheetcurrentisPivotTable && !fillStyle){ + if(!Store.luckysheetcurrentisPivotTable && !fillStyle && Store.showGridLines){ luckysheetTableContent.beginPath(); luckysheetTableContent.moveTo( (end_c + offsetLeft - 2 + bodrder05), @@ -1928,7 +1931,7 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee } //下边框 - if(!Store.luckysheetcurrentisPivotTable && !fillStyle){ + if(!Store.luckysheetcurrentisPivotTable && !fillStyle && Store.showGridLines){ luckysheetTableContent.beginPath(); luckysheetTableContent.moveTo( (start_c + offsetLeft - 2), @@ -2009,15 +2012,16 @@ let cellOverflowRender = function(r, c, stc, edc,luckysheetTableContent,scrollHe horizonAlignPos = (pos_x + cellWidth - space_width) - textMetrics; } + let verticalCellHeight = cellHeight>oneLineTextHeight?cellHeight:oneLineTextHeight; //溢出单元格 垂直对齐 let verticalAlign = menuButton.checkstatus(Store.flowdata, r, c, "vt"); - let verticalAlignPos = (pos_y + cellHeight - space_height) - oneLineTextHeight; //默认为2,下对齐 - let verticalAlignPos_text = (pos_y + cellHeight - space_height) ; //文本垂直方向基准线 + let verticalAlignPos = (pos_y + verticalCellHeight - space_height) - oneLineTextHeight; //默认为2,下对齐 + let verticalAlignPos_text = (pos_y + verticalCellHeight - space_height) ; //文本垂直方向基准线 luckysheetTableContent.textBaseline = "bottom"; if(verticalAlign == "0"){ //居中对齐 - verticalAlignPos = (pos_y + cellHeight / 2) - (oneLineTextHeight / 2); + verticalAlignPos = (pos_y + verticalCellHeight / 2) - (oneLineTextHeight / 2); - verticalAlignPos_text = (pos_y + cellHeight / 2) ; + verticalAlignPos_text = (pos_y + verticalCellHeight / 2) ; luckysheetTableContent.textBaseline = "middle"; } else if(verticalAlign == "1"){ //上对齐 @@ -2147,7 +2151,8 @@ function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){ edc = c; } - if(((stc >= col_st && stc <= col_ed) || (edc >= col_st && edc <= col_ed)) && stc < edc){ + // if(((stc >= col_st && stc <= col_ed) || (edc >= col_st && edc <= col_ed)) && stc < edc){ + if(((stc <= col_ed) || (edc >= col_st)) && stc < edc){ map[r + '_' + c] = { r: r, stc: stc, diff --git a/src/global/extend.js b/src/global/extend.js index 3734cf1..7f10000 100644 --- a/src/global/extend.js +++ b/src/global/extend.js @@ -95,7 +95,7 @@ function luckysheetextendtable(type, index, value, direction) { if(calcChain != null && calcChain.length > 0){ for(let i = 0; i < calcChain.length; i++){ let calc = $.extend(true, {}, calcChain[i]); - let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = calc.func[2]; + let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = getcellFormula(calc_r, calc_c, calc_i); if(type == "row"){ let functionStr = "=" + formula.functionStrChange(calc_funcStr, "add", "row", direction, index, value); @@ -104,7 +104,7 @@ function luckysheetextendtable(type, index, value, direction) { d[calc_r][calc_c].f = functionStr; } - calc.func[2] = functionStr; + // calc.func[2] = functionStr; if(direction == "lefttop"){ if(calc_r >= index){ @@ -126,7 +126,7 @@ function luckysheetextendtable(type, index, value, direction) { d[calc_r][calc_c].f = functionStr; } - calc.func[2] = functionStr; + // calc.func[2] = functionStr; if(direction == "lefttop"){ if(calc_c >= index){ @@ -882,7 +882,7 @@ function luckysheetdeletetable(type, st, ed) { if(calcChain != null && calcChain.length > 0){ for(let i = 0; i < calcChain.length; i++){ let calc = $.extend(true, {}, calcChain[i]); - let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = calc.func[2]; + let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = getcellFormula(calc_r, calc_c, calc_i); if(type == "row"){ if(calc_r < st || calc_r > ed){ @@ -892,7 +892,7 @@ function luckysheetdeletetable(type, st, ed) { d[calc_r][calc_c].f = functionStr; } - calc.func[2] = functionStr; + // calc.func[2] = functionStr; if(calc_r > ed){ calc.r = calc_r - slen; @@ -909,7 +909,7 @@ function luckysheetdeletetable(type, st, ed) { d[calc_r][calc_c].f = functionStr; } - calc.func[2] = functionStr; + // calc.func[2] = functionStr; if(calc_c > ed){ calc.c = calc_c - slen; @@ -1531,7 +1531,7 @@ function luckysheetDeleteCell(type, str, edr, stc, edc) { if(calcChain != null && calcChain.length > 0){ for(let i = 0; i < calcChain.length; i++){ let calc = $.extend(true, {}, calcChain[i]); - let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = calc.func[2]; + let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = getcellFormula(calc_r, calc_c, calc_i); if((calc_r < str || calc_r > edr) && (calc_c < stc || calc_c > edc)){ let functionStr; @@ -1555,7 +1555,7 @@ function luckysheetDeleteCell(type, str, edr, stc, edc) { d[calc_r][calc_c].f = functionStr; } - calc.func[2] = functionStr; + // calc.func[2] = functionStr; newCalcChain.push(calc); } diff --git a/src/global/formula.js b/src/global/formula.js index 46e0db4..a9a92df 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -10,7 +10,7 @@ import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/se import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate'; import { isdatetime, isdatatype } from './datecontroll'; import { getCellTextSplitArr } from '../global/getRowlen'; -import { getcellvalue } from './getdata'; +import { getcellvalue,getcellFormula } from './getdata'; import { setcellvalue } from './setdata'; import { genarate, valueShowEs } from './format'; import editor from './editor'; @@ -3845,7 +3845,7 @@ const luckysheetformula = { i++; } - console.log(function_str); + // console.log(function_str); return function_str; }, addFunctionGroup: function(r, c, func, index) { @@ -3887,7 +3887,7 @@ const luckysheetformula = { return file.calcChain; }, - updateFunctionGroup: function(r, c, func, index) { + updateFunctionGroup: function(r, c, index) { if (index == null) { index = Store.currentSheetIndex; } @@ -3900,7 +3900,6 @@ const luckysheetformula = { for (let i = 0; i < calcChain.length; i++) { let calc = calcChain[i]; if (calc.r == r && calc.c == c && calc.index == index) { - calcChain[i].func = func; server.saveParam("fc", index, JSON.stringify(calc), { "op": "update", "pos": i @@ -3912,15 +3911,16 @@ const luckysheetformula = { setluckysheetfile(luckysheetfile); }, - insertUpdateFunctionGroup: function(r, c, func, index) { + insertUpdateFunctionGroup: function(r, c, index) { if (index == null) { index = Store.currentSheetIndex; } - if (func == null) { - this.delFunctionGroup(r, c, index); - return; - } + // let func = getcellFormula(r, c, index); + // if (func == null || func.length==0) { + // this.delFunctionGroup(r, c, index); + // return; + // } let luckysheetfile = getluckysheetfile(); let file = luckysheetfile[getSheetIndex(index)]; @@ -3933,7 +3933,6 @@ const luckysheetformula = { for (let i = 0; i < calcChain.length; i++) { let calc = calcChain[i]; if (calc.r == r && calc.c == c && calc.index == index) { - calc.func = func; server.saveParam("fc", index, JSON.stringify(calc), { "op": "update", "pos": i @@ -3945,8 +3944,7 @@ const luckysheetformula = { let cc = { "r": r, "c": c, - "index": index, - "func": func + "index": index }; calcChain.push(cc); file.calcChain = calcChain; @@ -4487,8 +4485,8 @@ const luckysheetformula = { let item = group[i]; let cell = luckysheetfile[getSheetIndex(item["index"])].data[item.r][item.c]; - - if(cell != null && cell.f != null && cell.f == item.func[2]){ + let calc_funcStr = getcellFormula(item.r, item.c, item.index, _this.execFunctionGroupData); + if(cell != null && cell.f != null && cell.f == calc_funcStr){ if(!(item instanceof Object)){ item = eval('('+ item +')'); } @@ -4505,10 +4503,10 @@ const luckysheetformula = { _this.isFunctionRangeSave = true; } else if (origin_r != null && origin_c != null) { - _this.isFunctionRange(item.func[2], origin_r, origin_c); + _this.isFunctionRange(calc_funcStr, origin_r, origin_c); } else { - _this.isFunctionRange(item.func[2]); + _this.isFunctionRange(calc_funcStr); } if (_this.isFunctionRangeSave) { @@ -4529,7 +4527,7 @@ const luckysheetformula = { for (let i = 0; i < group.length; i++) { let item = group[i]; - + let calc_funcStr = getcellFormula(item.r, item.c, item.index, _this.execFunctionGroupData); item.color = "w"; item.parent = null; item.chidren = {}; @@ -4541,7 +4539,7 @@ const luckysheetformula = { _this.isFunctionRangeSave = true; } else{ - _this.isFunctionRange(item.func[2], cell.r, cell.c); + _this.isFunctionRange(calc_funcStr, cell.r, cell.c); } if (_this.isFunctionRangeSave) { @@ -4562,7 +4560,9 @@ const luckysheetformula = { } _this.isFunctionRangeSave = false; - _this.isFunctionRange(vertex1[name].func[2], u.r, u.c); + let item = vertex1[name]; + let calc_funcStr = getcellFormula(item.r, item.c, item.index, _this.execFunctionGroupData); + _this.isFunctionRange(calc_funcStr, u.r, u.c); if (_this.isFunctionRangeSave) { let v = vertex1[name]; @@ -4613,8 +4613,8 @@ const luckysheetformula = { u.color = "b"; window.luckysheet_getcelldata_cache = null; - - let v = _this.execfunction(u.func[2], u.r, u.c); + let calc_funcStr = getcellFormula(u.r, u.c, u.index, _this.execFunctionGroupData); + let v = _this.execfunction(calc_funcStr, u.r, u.c); let value = _this.execFunctionGroupData[u.r][u.c]; if(value == null){ @@ -4787,7 +4787,7 @@ const luckysheetformula = { if (isrefresh) { _this.execFunctionGroup(r, c, result); } - _this.insertUpdateFunctionGroup(r, c, [true, result, txt]); + _this.insertUpdateFunctionGroup(r, c); } return [true, result, txt]; @@ -4920,7 +4920,7 @@ const luckysheetformula = { } if(!notInsertFunc){ - _this.insertUpdateFunctionGroup(r, c, [true, result, txt]); + _this.insertUpdateFunctionGroup(r, c); } } diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index 9b7725a..4250ea1 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -43,7 +43,7 @@ function rowlenByRange(d, r1, r2, cfg) { let textMetrics = measureText.width; //文本宽度 let oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; - + let spaceHeight = Math.ceil(oneLineTextHeight/3); let computeRowlen; //计算行高 let word_space_height = oneLineTextHeight/3; if(cell.tb == "2"){ @@ -54,10 +54,10 @@ function rowlenByRange(d, r1, r2, cfg) { let strArr = []; //文本截断数组 strArr = getCellTextSplitArr(value, strArr, cellWidth, canvas); - computeRowlen = (oneLineTextHeight+word_space_height) * strArr.length + 4; + computeRowlen = (oneLineTextHeight+word_space_height) * strArr.length + spaceHeight; } else{ - computeRowlen = oneLineTextHeight + 4; + computeRowlen = oneLineTextHeight + spaceHeight; } } else if(cell.tr != null){ @@ -66,25 +66,25 @@ function rowlenByRange(d, r1, r2, cfg) { if(tr == "0"){ //无旋转 - computeRowlen = oneLineTextHeight + 4; + computeRowlen = oneLineTextHeight + spaceHeight; } else if(tr == "1" || tr == "2"){ //向下倾斜(45 旋转)----向上倾斜(-45 旋转) - computeRowlen = 0.707 * (textMetrics + oneLineTextHeight) + 4; + computeRowlen = 0.707 * (textMetrics + oneLineTextHeight) + spaceHeight; } else if(tr == "3"){ //竖排文字 - computeRowlen = value.length * oneLineTextHeight + 4; + computeRowlen = value.length * oneLineTextHeight + spaceHeight; } else if(tr == "4" || tr == "5"){ //向下90(90 旋转)----向上90(-90 旋转) - computeRowlen = textMetrics + 4; + computeRowlen = textMetrics + spaceHeight; } computeRowlen = Math.round(computeRowlen); } else{ - computeRowlen = oneLineTextHeight + 4; + computeRowlen = oneLineTextHeight + spaceHeight; } //比较计算高度和当前高度取最大高度 diff --git a/src/global/getdata.js b/src/global/getdata.js index 1ccb405..5fa8401 100644 --- a/src/global/getdata.js +++ b/src/global/getdata.js @@ -4,6 +4,7 @@ import server from '../controllers/server'; import formula from './formula'; import editor from './editor'; import { dynamicArrayCompute } from './dynamicArray'; +import sheetmanage from '../controllers/sheetmanage'; import Store from '../store'; //Get selection range value @@ -218,4 +219,46 @@ export function datagridgrowth(data, addr, addc, iscallback) { } return data; +} + + +//Get the formula of the cell +export function getcellFormula(r, c, i, data) { + let cell; + if(data!=null){ + cell = data[r][c]; + } + else{ + cell = getOrigincell(r,c,i); + } + + + if(cell==null){ + return null; + } + + return cell.f; +} + + +export function getOrigincell(r, c, i) { + if(r==null || c==null){ + return; + } + let data; + if (i == null) { + data = Store.flowdata; + } + else{ + let sheet = sheetmanage.getSheetByIndex(i); + data = sheet.data; + } + + if(data==null){ + return; + } + + return data[r][c]; + + } \ No newline at end of file diff --git a/src/global/refresh.js b/src/global/refresh.js index a6b7d7b..c360fd7 100644 --- a/src/global/refresh.js +++ b/src/global/refresh.js @@ -363,7 +363,7 @@ function jfrefreshgrid_adRC(data, cfg, ctrlType, ctrlValue, calc, filterObj, cf, for(let i = 0; i < calc.length; i++){ let clc = calc[i]; - let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = clc.func[2]; + let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = getcellFormula(clc_r, clc_c, clc_i); let clc_result = formula.execfunction(clc_funcStr, clc_r, clc_c, null, true); clc.func = clc_result; @@ -567,7 +567,7 @@ function jfrefreshgrid_deleteCell(data, cfg, ctrl, calc, filterObj, cf){ for(let i = 0; i < calc.length; i++){ let clc = calc[i]; - let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = clc.func[2]; + let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = getcellFormula(clc_r, clc_c, clc_i); let clc_result = formula.execfunction(clc_funcStr, clc_r, clc_c, null, true); clc.func = clc_result; diff --git a/src/global/rhchInit.js b/src/global/rhchInit.js index f8622b3..70c0f62 100644 --- a/src/global/rhchInit.js +++ b/src/global/rhchInit.js @@ -69,9 +69,9 @@ export default function rhchInit(rowheight, colwidth) { Store.visibledatacolumn.push(Store.ch_width);//列的临时长度分布 - if(maxColumnlen < firstcolumnlen + 1){ - maxColumnlen = firstcolumnlen + 1; - } + // if(maxColumnlen < firstcolumnlen + 1){ + // maxColumnlen = firstcolumnlen + 1; + // } } // Store.ch_width += 120; diff --git a/src/store/index.js b/src/store/index.js index 20ec8fc..43e4e40 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -26,6 +26,7 @@ const Store = { sheetBarHeight: 27, statisticBarHeight: 23, luckysheetTableContentHW: [0, 0], + defaultcollen: 73, defaultrowlen: 19, @@ -121,6 +122,8 @@ const Store = { visibledatacolumn_unique:null, visibledatarow_unique:null, + + showGridLines:true, } export default Store; \ No newline at end of file