Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(several bug and new feature): formula calculation , quotePrefix add
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Aug 31, 2020
1 parent 3d17426 commit 5a95304
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 16 deletions.
41 changes: 33 additions & 8 deletions src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const sheetmanage = {
return true;
}
},
createSheetbydata: function(data, isrenew) {
createSheetbydata: function(data, isrenew, isBefore=true) {
let _this = this;

let colorset = '';
Expand All @@ -452,13 +452,15 @@ const sheetmanage = {

$("#luckysheet-sheet-container-c").append(replaceHtml(sheetHTML, { "index": data.index, "active": "", "name": data.name, "order": data.order, "style": "", "colorset": colorset }));

let previndex = data.order;
if(previndex >= Store.luckysheetfile.length){
previndex = Store.luckysheetfile.length - 1;
$("#luckysheet-sheets-item" + data.index).insertAfter($("#luckysheet-sheets-item" + Store.luckysheetfile[previndex].index));
}
else{
$("#luckysheet-sheets-item" + data.index).insertBefore($("#luckysheet-sheets-item" + Store.luckysheetfile[previndex].index));
if(isBefore){
let previndex = data.order;
if(previndex >= Store.luckysheetfile.length){
previndex = Store.luckysheetfile.length - 1;
$("#luckysheet-sheets-item" + data.index).insertAfter($("#luckysheet-sheets-item" + Store.luckysheetfile[previndex].index));
}
else{
$("#luckysheet-sheets-item" + data.index).insertBefore($("#luckysheet-sheets-item" + Store.luckysheetfile[previndex].index));
}
}

Store.luckysheetfile.push(data);
Expand Down Expand Up @@ -1011,6 +1013,29 @@ const sheetmanage = {

file["data"] = data;
file["load"] = "1";

let sheetindexset = _this.checkLoadSheetIndex(file);
let sheetindex = [];

for(let i = 0; i < sheetindexset.length; i++){
let item = sheetindexset[i];

if(item == file["index"]){
continue;
}

sheetindex.push(item);
}

for(let i = 0;i<sheetindex.length;i++){
let item = sheetindex[i];
let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
if(otherfile["load"] == null || otherfile["load"] == "0"){
otherfile["data"] = _this.buildGridData(otherfile);
otherfile["load"] = "1";
}
}

_this.mergeCalculation(index);
_this.setSheetParam();
_this.showSheet();
Expand Down
2 changes: 2 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ luckysheet.setcellvalue = setcellvalue;
// Get selection range value
luckysheet.getdatabyselection = getdatabyselection;

luckysheet.sheetmanage = sheetmanage;

// Data of the current table
luckysheet.flowdata = function () {
return Store.flowdata;
Expand Down
26 changes: 24 additions & 2 deletions src/global/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { luckysheetdefaultstyle, luckysheet_CFiconsImg,luckysheetdefaultFont } f
import { luckysheet_searcharray } from '../controllers/sheetSearch';
import { dynamicArrayCompute } from './dynamicArray';
import browser from './browser';
import { isRealNull } from './validate';
import { isRealNull, isRealNum } from './validate';
import { getCellTextSplitArr,getMeasureText } from './getRowlen';
import { getcellvalue } from './getdata';
import { getBorderInfoCompute } from './border';
Expand Down Expand Up @@ -1239,7 +1239,7 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee

//若单元格有批注(单元格右上角红色小三角标示)
if(cell.ps != null){
let ps_w = 8*Store.zoomRatio, ps_h = 8*Store.zoomRatio; //红色小三角宽高
let ps_w = 6*Store.zoomRatio, ps_h = 6*Store.zoomRatio; //红色小三角宽高

luckysheetTableContent.beginPath();
luckysheetTableContent.moveTo(
Expand All @@ -1259,6 +1259,28 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee
luckysheetTableContent.closePath();
}

//若单元格强制为字符串,则显示绿色小三角
if(cell.qp==1 && isRealNum(cell.v)){
let ps_w = 6*Store.zoomRatio, ps_h = 6*Store.zoomRatio; //红色小三角宽高

luckysheetTableContent.beginPath();
luckysheetTableContent.moveTo(
(start_c + offsetLeft + ps_w),
(start_r + offsetTop)
);
luckysheetTableContent.lineTo(
(start_c + offsetLeft),
(start_r + offsetTop)
);
luckysheetTableContent.lineTo(
(start_c + offsetLeft),
(start_r + offsetTop + ps_h)
);
luckysheetTableContent.fillStyle = "#487f1e";
luckysheetTableContent.fill();
luckysheetTableContent.closePath();
}

//溢出单元格
let cellOverflow_bd_r_render = true; //溢出单元格右边框是否需要绘制
let cellOverflow_colInObj = cellOverflow_colIn(cellOverflowMap, r, c, dataset_col_st, dataset_col_ed);
Expand Down
24 changes: 18 additions & 6 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,8 @@ const luckysheetformula = {
oldvalue: null,
dontupdate: function() {
let _this = this;

Store.luckysheetCellUpdate.length = 0; //clear array
$("#luckysheet-functionbox-cell, #luckysheet-rich-text-editor").html(_this.oldvalue);

_this.cancelNormalSelected();
if (_this.rangetosheet != Store.currentSheetIndex) {
sheetmanage.changeSheetExec(_this.rangetosheet);
Expand Down Expand Up @@ -1209,7 +1207,7 @@ const luckysheetformula = {
return;
}
}
else{
else if(curv!=null && curv.qp != 1){
if (getObjType(curv) == "object" && (value == curv.f || value == curv.v || value == curv.m)) {
_this.cancelNormalSelected();
return;
Expand Down Expand Up @@ -1267,6 +1265,14 @@ const luckysheetformula = {

delete curv.f;
delete curv.spl;

if(curv.qp == 1 && value.substr(0,1)!="'"){//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
curv.qp = 0;
if(curv.ct!=null){
curv.ct.fa = "General";
curv.ct.t = "n";
}
}
}

value = curv;
Expand Down Expand Up @@ -3614,7 +3620,10 @@ const luckysheetformula = {
_this.operatorjson = op;
}

if (txt.substr(0, 1) == "=") {
if (txt.substr(0, 2) == "=+") {
txt = txt.substr(2);
}
else if (txt.substr(0, 1) == "=") {
txt = txt.substr(1);
}

Expand Down Expand Up @@ -4483,8 +4492,11 @@ const luckysheetformula = {

for (let i = 0; i < group.length; i++) {
let item = group[i];

let cell = luckysheetfile[getSheetIndex(item["index"])].data[item.r][item.c];
let file =luckysheetfile[getSheetIndex(item["index"])];
if(file==null){
continue;
}
let cell = file.data[item.r][item.c];
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)){
Expand Down
6 changes: 6 additions & 0 deletions src/global/setdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ function setcellvalue(r, c, d, v) {
cell.m = vupdate.toString().substr(1);
cell.ct = { "fa": "@", "t": "s" };
cell.v = vupdate.toString().substr(1);
cell.qp = 1;
}
else if(cell.qp == 1){
cell.m = vupdate.toString();
cell.ct = { "fa": "@", "t": "s" };
cell.v = vupdate.toString();
}
else if(vupdate.toString().toUpperCase() === "TRUE"){
cell.m = "TRUE";
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const Store = {
visibledatarow_unique:null,

showGridLines:true,

}

export default Store;

0 comments on commit 5a95304

Please sign in to comment.