From 74d6ec850784d021a114ee0c01d076cf2a505b8e Mon Sep 17 00:00:00 2001 From: liuyang Date: Thu, 17 Sep 2020 15:51:37 +0800 Subject: [PATCH 1/4] refactor(inline string): develop --- src/controllers/rowColumnOperation.js | 65 ++++++++++++++++++++------- src/global/draw.js | 2 +- src/global/getRowlen.js | 16 ++++--- 3 files changed, 60 insertions(+), 23 deletions(-) diff --git a/src/controllers/rowColumnOperation.js b/src/controllers/rowColumnOperation.js index f8b039c..ba01c2d 100644 --- a/src/controllers/rowColumnOperation.js +++ b/src/controllers/rowColumnOperation.js @@ -32,7 +32,7 @@ import { getcellvalue } from '../global/getdata'; import tooltip from '../global/tooltip'; import editor from '../global/editor'; import locale from '../locale/locale'; -import {getMeasureText} from '../global/getRowlen'; +import {getMeasureText,getCellTextInfo} from '../global/getRowlen'; import { luckysheet_searcharray } from '../controllers/sheetSearch'; import Store from '../store'; @@ -1711,24 +1711,39 @@ function luckysheetcolsdbclick() { for(let r = dataset_row_st; r <= dataset_row_ed; r++){ let cell = d[r][colIndex]; - if(cell == null || isRealNull(cell.v)){ + if(cell == null || (isRealNull(cell.v) && !(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0)) ){ continue; } - let fontset = luckysheetfontformat(cell); - canvas.font = fontset; + // let fontset = luckysheetfontformat(cell); + // canvas.font = fontset; - let value = getcellvalue(r, colIndex, d, "m").toString(); //单元格文本 - let textMetrics = getMeasureText(value, canvas).width; //文本宽度 + // let value = getcellvalue(r, colIndex, d, "m").toString(); //单元格文本 + // let textMetrics = getMeasureText(value, canvas).width; //文本宽度 + let cellWidth = colLocationByIndex(colIndex)[1] - colLocationByIndex(colIndex)[0] - 2; + let textInfo = getCellTextInfo(cell, canvas,{ + r:r, + c:colIndex, + cellWidth:cellWidth + }); + + let computeRowlen = 0; + // console.log("rowlen", textInfo); + if(textInfo!=null){ + computeRowlen = textInfo.textWidthAll; + } - if(textMetrics + 6 > currentColLen){ - currentColLen = textMetrics + 6; + if(computeRowlen + 6 > currentColLen){ + currentColLen = computeRowlen + 6; } } if(currentColLen != Store.defaultcollen){ cfg["columnlen"][colIndex] = currentColLen; + if(cfg["customWidth"]){ + delete cfg["customWidth"][colIndex]; + } } matchColumn[colIndex] = 1; @@ -1744,24 +1759,44 @@ function luckysheetcolsdbclick() { for(let r = dataset_row_st; r <= dataset_row_ed; r++){ let cell = d[r][c]; - if(cell == null || isRealNull(cell.v)){ + if(cell == null || (isRealNull(cell.v) && !(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0)) ){ continue; } - let fontset = luckysheetfontformat(cell); - canvas.font = fontset; + // let fontset = luckysheetfontformat(cell); + // canvas.font = fontset; + + // let value = getcellvalue(r, c, d, "m").toString(); //单元格文本 + // let textMetrics = getMeasureText(value, canvas).width; //文本宽度 - let value = getcellvalue(r, c, d, "m").toString(); //单元格文本 - let textMetrics = getMeasureText(value, canvas).width; //文本宽度 + // if(textMetrics + 6 > currentColLen){ + // currentColLen = textMetrics + 6; + // } - if(textMetrics + 6 > currentColLen){ - currentColLen = textMetrics + 6; + let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2; + let textInfo = getCellTextInfo(cell, canvas,{ + r:r, + c:c, + cellWidth:cellWidth + }); + + let computeRowlen = 0; + // console.log("rowlen", textInfo); + if(textInfo!=null){ + computeRowlen = textInfo.textWidthAll; + } + + if(computeRowlen + 6 > currentColLen){ + currentColLen = computeRowlen + 6; } } if(currentColLen != Store.defaultcollen){ cfg["columnlen"][c] = currentColLen; + if(cfg["customWidth"]){ + delete cfg["customWidth"][c]; + } } matchColumn[c] = 1; diff --git a/src/global/draw.js b/src/global/draw.js index 1598568..fb321e7 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -1801,7 +1801,7 @@ function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){ continue } - if(cell != null && !isRealNull(cell.v) && cell.mc == null && cell.tb == '1'){ + if(cell != null && (!isRealNull(cell.v) || (cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0) ) && cell.mc == null && cell.tb == '1'){ // let fontset = luckysheetfontformat(cell); // canvas.font = fontset; diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index f8c4b0e..2942a84 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -423,11 +423,13 @@ function getCellTextInfo(cell , ctx, option){ showValue = ""; - if(!(preShareCell==null || preShareCell.wrap==true || (i==inlineStringArr.length-1))){ - console.log("wrap",i,shareCell, preShareCell); + if( preShareCell!=null && preShareCell.wrap!==true && (icellHeight && textH_all_Column[colIndex]!=null){ // textW_all += textW; // textH_all = Math.max(textH_all,textH_all_cache); - console.log(">",i,shareCell, preShareCell); + // console.log(">",i,colIndex); textH_all_ColumnHeight.push(textH_all_cache-textH); textH_all_cache = textH; colIndex +=1; @@ -478,7 +480,7 @@ function getCellTextInfo(cell , ctx, option){ } textH_all_Column[colIndex].push(item); - + console.log("normal",i,colIndex,shareCell, preShareCell, textH_all_Column); preShareCell = shareCell; } @@ -596,9 +598,9 @@ function getCellTextInfo(cell , ctx, option){ width:columnWidth, height:word.height, left:left, - top:top+word.height/2, - asc:word.asc, - desc:word.desc + top:top+word.height-space_height, + asc:word.height, + desc:0 }); textContent.values.push(word); From 2ffd9aedd82e9abaf32b374337503f25d56fd9da Mon Sep 17 00:00:00 2001 From: liuyang Date: Thu, 17 Sep 2020 19:09:28 +0800 Subject: [PATCH 2/4] feat(inline string render finished): begin to develop edit feature --- src/controllers/handler.js | 12 ++++++ src/global/getRowlen.js | 8 ++++ src/index.html | 80 +++++++++++++++++++------------------- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 572a20c..5a39272 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -3146,6 +3146,12 @@ export default function luckysheetHandler() { cfg["rowlen"] = {}; } + if (cfg["customHeight"] == null) { + cfg["customHeight"] = {}; + } + + cfg["customHeight"][Store.luckysheet_rows_change_size_start[1]] = 1; + cfg["rowlen"][Store.luckysheet_rows_change_size_start[1]] = Math.ceil(size/Store.zoomRatio); let images = imageCtrl.moveChangeSize("row", Store.luckysheet_rows_change_size_start[1], size); @@ -3222,6 +3228,12 @@ export default function luckysheetHandler() { cfg["columnlen"] = {}; } + if (cfg["customWidth"] == null) { + cfg["customWidth"] = {}; + } + + cfg["customWidth"][Store.luckysheet_cols_change_size_start[1]] = 1; + cfg["columnlen"][Store.luckysheet_cols_change_size_start[1]] = Math.ceil(size/Store.zoomRatio); let images = imageCtrl.moveChangeSize("column", Store.luckysheet_cols_change_size_start[1], size); diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index 2942a84..2c3cbe5 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -12,6 +12,10 @@ function rowlenByRange(d, r1, r2, cfg) { cfg_clone["rowlen"] = {}; } + if(cfg_clone["customHeight"] == null){ + cfg_clone["customHeight"] = {}; + } + let canvas = $("#luckysheetTableContent").get(0).getContext("2d"); canvas.textBaseline = 'top'; //textBaseline以top计算 @@ -25,6 +29,10 @@ function rowlenByRange(d, r1, r2, cfg) { // currentRowLen = cfg_clone["rowlen"][r]; // } + if(cfg_clone["customHeight"][r]==1){ + continue; + } + delete cfg_clone["rowlen"][r]; for(let c = 0; c < d[r].length; c++){ diff --git a/src/index.html b/src/index.html index 8a7f066..04b69ca 100644 --- a/src/index.html +++ b/src/index.html @@ -78,46 +78,46 @@ forceCalculation:false, plugins: ['chart'], data: - [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] - // [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ - // {"r":0,"c":0, - // "v":{ - // "ct":{ - // "fa":"General", - // "t":"inlineStr", - // "s":[ - // { - // "ff":"等线", //font family - // "fc":"#fff000",//font color - // "fs":12,//font size - // "cl":0,//strike - // "un":0,//underline - // "bl":0,//blod - // "it":1,//italic - // v:"我在马路\r\n边捡到\r\n\r\n一分钱" - // }, - // { - // "ff":"等线", //font family - // "fc":"#ff0000",//font color - // "fs":14,//font size - // "cl":"1",//strike - // "un":"1",//underline - // "bl":"1",//blod - // "it":"0",//italic - // v:"交给警\r\n察叔叔\r\n" - // }, - // ] - // }, - // "fs":11, - // "ff":"等线", - // "vt":0, - // "tb":2, - // "v":"", - // "qp":1, - // } - // }, - // {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}} - // ],"calcChain":[]}] + // [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] + [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ + {"r":0,"c":0, + "v":{ + "ct":{ + "fa":"General", + "t":"inlineStr", + "s":[ + { + "ff":"等线", //font family + "fc":"#fff000",//font color + "fs":12,//font size + "cl":0,//strike + "un":0,//underline + "bl":0,//blod + "it":1,//italic + v:"我在马路\r\n边捡到\r\n\r\n一分钱" + }, + { + "ff":"等线", //font family + "fc":"#ff0000",//font color + "fs":14,//font size + "cl":"1",//strike + "un":"1",//underline + "bl":"1",//blod + "it":"0",//italic + v:"交给警\r\n察叔叔\r\n" + }, + ] + }, + "fs":11, + "ff":"等线", + "vt":0, + "tb":2, + "v":"", + "qp":1, + } + }, + {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}} + ],"calcChain":[]}] }) }) From 1ae5aa8f90dff9ec3d11cf5c557631c08d2b2642 Mon Sep 17 00:00:00 2001 From: gsw945 Date: Thu, 17 Sep 2020 19:37:15 +0800 Subject: [PATCH 3/4] collaborative editing bug(not defined ReferenceError) fix --- src/controllers/server.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controllers/server.js b/src/controllers/server.js index 086e246..d730157 100644 --- a/src/controllers/server.js +++ b/src/controllers/server.js @@ -714,13 +714,15 @@ const server = { multipleRangeShow: function(id, name, r, c) { let _this = this; + let r2 = Store.luckysheet_select_save[0].row[1], + c2 = Store.luckysheet_select_save[0].column[1]; let r1 = r2 = r; let c1 = c2 = c; - let row = visibledatarow[r2], - row_pre = r1 - 1 == -1 ? 0 : visibledatarow[r1 - 1], - col = visibledatacolumn[c2], - col_pre = c1 - 1 == -1 ? 0 : visibledatacolumn[c1 - 1]; + let row = Store.visibledatarow[r2], + row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1], + col = Store.visibledatacolumn[c2], + col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1]; let margeset = menuButton.mergeborer(Store.flowdata, r1, c1); if(!!margeset){ From 713805cd031ccdf3e5ef1b70da504b635fed85fa Mon Sep 17 00:00:00 2001 From: wbfsa Date: Fri, 18 Sep 2020 01:07:02 +0800 Subject: [PATCH 4/4] feat(inline string): when focus cell, show inline string content --- src/controllers/menuButton.js | 231 ++++++-------------------------- src/controllers/updateCell.js | 7 +- src/global/formula.js | 7 +- src/global/getRowlen.js | 16 +-- src/global/getdata.js | 240 ++++++++++++++++++++++++++++++++++ src/index.html | 80 ++++++------ 6 files changed, 341 insertions(+), 240 deletions(-) diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js index 56ef056..b883958 100644 --- a/src/controllers/menuButton.js +++ b/src/controllers/menuButton.js @@ -26,6 +26,7 @@ import { rowLocationByIndex, colLocationByIndex } from '../global/location'; import { isdatatypemulti } from '../global/datecontroll'; import { rowlenByRange, getCellTextSplitArr } from '../global/getRowlen'; import { setcellvalue } from '../global/setdata'; +import { getFontStyleByCell, checkstatusByCell} from '../global/getdata'; import { countfunc } from '../global/count'; import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get'; import { setluckysheetfile } from '../methods/set'; @@ -3312,165 +3313,9 @@ const menuButton = { } } }, - checkstatusByCell:function(cell, a){ - let foucsStatus =cell; - let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1}; - - if(a in tf){ - if(foucsStatus == null){ - foucsStatus = "0"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "0"; - } - } - } - else if(a == "fc"){ - if(foucsStatus == null){ - foucsStatus = "#000000"; - } - else{ - foucsStatus = foucsStatus[a]; - - if(foucsStatus == null){ - foucsStatus = "#000000"; - } - - if(foucsStatus.indexOf("rgba") > -1){ - foucsStatus = rgbTohex(foucsStatus); - } - } - } - else if(a == "bg"){ - if(foucsStatus == null){ - foucsStatus = null; - } - else{ - foucsStatus = foucsStatus[a]; - - if(foucsStatus == null){ - foucsStatus = null; - } - else if(foucsStatus.toString().indexOf("rgba") > -1){ - foucsStatus = rgbTohex(foucsStatus); - } - } - } - else if(a.substr(0, 2) == "bs"){ - if(foucsStatus == null){ - foucsStatus = "none"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "none"; - } - } - } - else if(a.substr(0, 2) == "bc"){ - if(foucsStatus == null){ - foucsStatus = "#000000"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "#000000"; - } - } - } - else if(a == "ht"){ - if(foucsStatus == null){ - foucsStatus = "1"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "1"; - } - } - - if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){ - foucsStatus = "1"; - } - } - else if(a == "vt"){ - if(foucsStatus == null){ - foucsStatus = "2"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "2"; - } - } - - if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){ - foucsStatus = "2"; - } - } - else if(a == "ct"){ - if(foucsStatus == null){ - foucsStatus = null; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = null; - } - } - } - else if(a == "fs"){ - if(foucsStatus == null){ - foucsStatus = "10"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "10"; - } - } - } - else if(a == "tb"){ - if(foucsStatus == null){ - foucsStatus = "0"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "0"; - } - } - } - else if(a == "tr"){ - if(foucsStatus == null){ - foucsStatus = "0"; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = "0"; - } - } - } - else if(a == "rt"){ - if(foucsStatus == null){ - foucsStatus = null; - } - else{ - foucsStatus = foucsStatus[a]; - if(foucsStatus == null){ - foucsStatus = null; - } - } - } - - return foucsStatus; - }, checkstatus: function(d, r, c, a){ let foucsStatus = d[r][c]; - return this.checkstatusByCell(foucsStatus, a); + return checkstatusByCell(foucsStatus, a); }, setLineDash: function(canvasborder, type, hv, m_st, m_ed, line_st, line_ed){ let borderType = { @@ -4232,6 +4077,10 @@ const menuButton = { const locale_fontarray = locale().fontarray; let cell = d[r][c]; + let ct = cell.ct, isInline=false; + if(ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0){ + isInline = true; + } for(let key in cell){ let value = _this.checkstatus(d, r, c , key); @@ -4260,37 +4109,39 @@ const menuButton = { } } - if(key == "bl" && value != "0"){ - style += "font-weight: bold;"; - } - - if(key == "it" && value != "0"){ - style += "font-style:italic;"; - } - - if(key == "ff" && value != "0"){ - let f = value; - if(!isNaN(parseInt(value))){ - f = locale_fontarray[parseInt(value)]; - } - style += "font-family: " + f + ";"; - } - - if(key == "fs" && value != "10"){ - style += "font-size: "+ value + "pt;"; - } - - if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){ - if(checksCF != null && checksCF["textColor"] != null){ - style += "color: " + checksCF["textColor"] + ";"; - } - else if(checksAF != null){ - style += "color: " + checksAF[0] + ";"; - } - else{ - style += "color: " + value + ";"; - } - } + // if(!isInline){ + // if(key == "bl" && value != "0"){ + // style += "font-weight: bold;"; + // } + + // if(key == "it" && value != "0"){ + // style += "font-style:italic;"; + // } + + // if(key == "ff" && value != "0"){ + // let f = value; + // if(!isNaN(parseInt(value))){ + // f = locale_fontarray[parseInt(value)]; + // } + // style += "font-family: " + f + ";"; + // } + + // if(key == "fs" && value != "10"){ + // style += "font-size: "+ value + "pt;"; + // } + + // if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){ + // if(checksCF != null && checksCF["textColor"] != null){ + // style += "color: " + checksCF["textColor"] + ";"; + // } + // else if(checksAF != null){ + // style += "color: " + checksAF[0] + ";"; + // } + // else{ + // style += "color: " + value + ";"; + // } + // } + // } if(key == "ht" && value != "1"){ if(value == "0"){ @@ -4311,6 +4162,10 @@ const menuButton = { } } + if(!isInline){ + style += getFontStyleByCell(cell,checksAF,checksCF); + } + return style; } } diff --git a/src/controllers/updateCell.js b/src/controllers/updateCell.js index 9df8116..08e4a5d 100644 --- a/src/controllers/updateCell.js +++ b/src/controllers/updateCell.js @@ -6,7 +6,7 @@ import alternateformat from './alternateformat'; import dataVerificationCtrl from './dataVerificationCtrl'; import { chatatABC } from '../utils/util'; import { isEditMode } from '../global/validate'; -import { getcellvalue } from '../global/getdata'; +import { getcellvalue,getInlineStringStyle } from '../global/getdata'; import { valueShowEs } from '../global/format'; import formula from '../global/formula'; import { luckysheetRangeLast } from '../global/cursorPos'; @@ -135,7 +135,10 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu if (!cover) { - if(cell.f!=null){ + if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0){ + value = getInlineStringStyle(row_index, col_index, d); + } + else if(cell.f!=null){ value = getcellvalue(row_index, col_index, d, "f"); } else{ diff --git a/src/global/formula.js b/src/global/formula.js index ff57a5b..e27bbb9 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,getcellFormula } from './getdata'; +import { getcellvalue,getcellFormula,getInlineStringNoStyle } from './getdata'; import { setcellvalue } from './setdata'; import { genarate, valueShowEs } from './format'; import editor from './editor'; @@ -325,7 +325,10 @@ const luckysheetformula = { if (d[r] != null && d[r][c] != null) { let cell = d[r][c]; - if(cell.f != null){ + if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0){ + value = getInlineStringNoStyle(r, c); + } + else if(cell.f != null){ value = getcellvalue(r, c, d, "f"); } else{ diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index 2c3cbe5..5e91b9c 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -1,6 +1,6 @@ import { luckysheetfontformat } from '../utils/util'; import menuButton from '../controllers/menuButton'; -import { getcellvalue } from './getdata'; +import { getcellvalue,checkstatusByCell } from './getdata'; import { colLocationByIndex } from './location'; import { hasChinaword, isRealNull } from './validate'; import Store from '../store'; @@ -277,13 +277,13 @@ function getCellTextInfo(cell , ctx, option){ } //水平对齐 - let horizonAlign = menuButton.checkstatusByCell(cell, "ht"); + let horizonAlign = checkstatusByCell(cell, "ht"); //垂直对齐 - let verticalAlign = menuButton.checkstatusByCell(cell, "vt"); + let verticalAlign = checkstatusByCell(cell, "vt"); - let tb = menuButton.checkstatusByCell(cell ,"tb");//wrap overflow - let tr = menuButton.checkstatusByCell(cell ,"tr");//rotate - let rt = menuButton.checkstatusByCell(cell ,"rt");//rotate angle + let tb = checkstatusByCell(cell ,"tb");//wrap overflow + let tr = checkstatusByCell(cell ,"tr");//rotate + let rt = checkstatusByCell(cell ,"rt");//rotate angle let isRotateUp = 1, isRotateDown=0; @@ -388,8 +388,8 @@ function getCellTextInfo(cell , ctx, option){ fontset = luckysheetfontformat(cell); ctx.font = fontset; - cancelLine = menuButton.checkstatusByCell(cell ,"cl");//cancelLine - underLine = menuButton.checkstatusByCell(cell ,"un");//underLine + cancelLine = checkstatusByCell(cell ,"cl");//cancelLine + underLine = checkstatusByCell(cell ,"un");//underLine if(cell instanceof Object){ value = cell.m; diff --git a/src/global/getdata.js b/src/global/getdata.js index dca78e8..29b94a7 100644 --- a/src/global/getdata.js +++ b/src/global/getdata.js @@ -5,6 +5,7 @@ import formula from './formula'; import editor from './editor'; import { dynamicArrayCompute } from './dynamicArray'; import sheetmanage from '../controllers/sheetmanage'; +import locale from '../locale/locale'; import Store from '../store'; //Get selection range value @@ -276,4 +277,243 @@ export function getRealCellValue(r, c){ } return value; +} + +export function getInlineStringNoStyle(r, c){ + let ct = getcellvalue(r, c, null, "ct"); + if(ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0){ + let strings = ct.s, value=""; + for(let i=0;i0){ + let strings = ct.s, value=""; + for(let i=0;i" + strObj.v + ""; + } + } + return value; + } + + return ""; +} + +export function getFontStyleByCell(cell,checksAF,checksCF){ + if(cell==null){ + return; + } + let style = ""; + const _locale = locale(); + const locale_fontarray = _locale.fontarray; + for(let key in cell){ + let value = checkstatusByCell(cell, key); + if(key == "bl" && value != "0"){ + style += "font-weight: bold;"; + } + + if(key == "it" && value != "0"){ + style += "font-style:italic;"; + } + + if(key == "ff" && value != "0"){ + let f = value; + if(!isNaN(parseInt(value))){ + f = locale_fontarray[parseInt(value)]; + } + style += "font-family: " + f + ";"; + } + + if(key == "fs" && value != "10"){ + style += "font-size: "+ value + "pt;"; + } + + if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){ + if(checksCF != null && checksCF["textColor"] != null){ + style += "color: " + checksCF["textColor"] + ";"; + } + else if(checksAF != null){ + style += "color: " + checksAF[0] + ";"; + } + else{ + style += "color: " + value + ";"; + } + } + + } + return style; +} + +export function checkstatusByCell(cell, a){ + let foucsStatus =cell; + let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1}; + + if(a in tf){ + if(foucsStatus == null){ + foucsStatus = "0"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "0"; + } + } + } + else if(a == "fc"){ + if(foucsStatus == null){ + foucsStatus = "#000000"; + } + else{ + foucsStatus = foucsStatus[a]; + + if(foucsStatus == null){ + foucsStatus = "#000000"; + } + + if(foucsStatus.indexOf("rgba") > -1){ + foucsStatus = rgbTohex(foucsStatus); + } + } + } + else if(a == "bg"){ + if(foucsStatus == null){ + foucsStatus = null; + } + else{ + foucsStatus = foucsStatus[a]; + + if(foucsStatus == null){ + foucsStatus = null; + } + else if(foucsStatus.toString().indexOf("rgba") > -1){ + foucsStatus = rgbTohex(foucsStatus); + } + } + } + else if(a.substr(0, 2) == "bs"){ + if(foucsStatus == null){ + foucsStatus = "none"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "none"; + } + } + } + else if(a.substr(0, 2) == "bc"){ + if(foucsStatus == null){ + foucsStatus = "#000000"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "#000000"; + } + } + } + else if(a == "ht"){ + if(foucsStatus == null){ + foucsStatus = "1"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "1"; + } + } + + if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){ + foucsStatus = "1"; + } + } + else if(a == "vt"){ + if(foucsStatus == null){ + foucsStatus = "2"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "2"; + } + } + + if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){ + foucsStatus = "2"; + } + } + else if(a == "ct"){ + if(foucsStatus == null){ + foucsStatus = null; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = null; + } + } + } + else if(a == "fs"){ + if(foucsStatus == null){ + foucsStatus = "10"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "10"; + } + } + } + else if(a == "tb"){ + if(foucsStatus == null){ + foucsStatus = "0"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "0"; + } + } + } + else if(a == "tr"){ + if(foucsStatus == null){ + foucsStatus = "0"; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = "0"; + } + } + } + else if(a == "rt"){ + if(foucsStatus == null){ + foucsStatus = null; + } + else{ + foucsStatus = foucsStatus[a]; + if(foucsStatus == null){ + foucsStatus = null; + } + } + } + + return foucsStatus; } \ No newline at end of file diff --git a/src/index.html b/src/index.html index 04b69ca..8a7f066 100644 --- a/src/index.html +++ b/src/index.html @@ -78,46 +78,46 @@ forceCalculation:false, plugins: ['chart'], data: - // [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] - [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ - {"r":0,"c":0, - "v":{ - "ct":{ - "fa":"General", - "t":"inlineStr", - "s":[ - { - "ff":"等线", //font family - "fc":"#fff000",//font color - "fs":12,//font size - "cl":0,//strike - "un":0,//underline - "bl":0,//blod - "it":1,//italic - v:"我在马路\r\n边捡到\r\n\r\n一分钱" - }, - { - "ff":"等线", //font family - "fc":"#ff0000",//font color - "fs":14,//font size - "cl":"1",//strike - "un":"1",//underline - "bl":"1",//blod - "it":"0",//italic - v:"交给警\r\n察叔叔\r\n" - }, - ] - }, - "fs":11, - "ff":"等线", - "vt":0, - "tb":2, - "v":"", - "qp":1, - } - }, - {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}} - ],"calcChain":[]}] + [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] + // [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ + // {"r":0,"c":0, + // "v":{ + // "ct":{ + // "fa":"General", + // "t":"inlineStr", + // "s":[ + // { + // "ff":"等线", //font family + // "fc":"#fff000",//font color + // "fs":12,//font size + // "cl":0,//strike + // "un":0,//underline + // "bl":0,//blod + // "it":1,//italic + // v:"我在马路\r\n边捡到\r\n\r\n一分钱" + // }, + // { + // "ff":"等线", //font family + // "fc":"#ff0000",//font color + // "fs":14,//font size + // "cl":"1",//strike + // "un":"1",//underline + // "bl":"1",//blod + // "it":"0",//italic + // v:"交给警\r\n察叔叔\r\n" + // }, + // ] + // }, + // "fs":11, + // "ff":"等线", + // "vt":0, + // "tb":2, + // "v":"", + // "qp":1, + // } + // }, + // {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}} + // ],"calcChain":[]}] }) })