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

Commit

Permalink
feat(optimization function): setCellvalue support any cell param
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer committed Sep 30, 2020
1 parent f512678 commit 9b208e4
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 179 deletions.
267 changes: 137 additions & 130 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2871,6 +2871,142 @@ const menuButton = {

return [style, color];
},
updateFormatCell:function(d, attr, foucsStatus,row_st, row_ed, col_st, col_ed){
if(d==null || attr==null){
return;
}
if(attr == "ct"){
for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

for (let c = col_st; c <= col_ed; c++) {
let cell = d[r][c], value = null;

if (getObjType(cell) == "object") {
value = d[r][c]["v"];
}
else{
value = d[r][c];
}

if(foucsStatus != "@" && isRealNum(value)){
value = parseFloat(value);
}

let mask = update(foucsStatus, value);
let type = "n";

if(is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47){
type = "d";
}
else if(foucsStatus == "@" || foucsStatus === 49){
type = "s"
}
else if(foucsStatus == "General" || foucsStatus === 0){
type = "g";
}

if (getObjType(cell) == "object") {
d[r][c]["m"] = mask;
if(d[r][c]["ct"] == null){
d[r][c]["ct"] = {};
}
d[r][c]["ct"]["fa"] = foucsStatus;
d[r][c]["ct"]["t"] = type;
}
else{
d[r][c] = { "ct":{"fa":foucsStatus, "t":type}, "v": value, "m": mask };
}
}
}
}
else{
if(attr == "ht"){
if(foucsStatus == "left"){
foucsStatus = "1";
}
else if(foucsStatus == "center"){
foucsStatus = "0";
}
else if(foucsStatus == "right"){
foucsStatus = "2";
}
}
else if(attr == "vt"){
if(foucsStatus == "top"){
foucsStatus = "1";
}
else if(foucsStatus == "middle"){
foucsStatus = "0";
}
else if(foucsStatus == "bottom"){
foucsStatus = "2";
}
}
else if(attr == "tb"){
if(foucsStatus == "overflow"){
foucsStatus = "1";
}
else if(foucsStatus == "clip"){
foucsStatus = "0";
}
else if(foucsStatus == "wrap"){
foucsStatus = "2";
}
}
else if(attr == "tr"){
if(foucsStatus == "none"){
foucsStatus = "0";
}
else if(foucsStatus == "angleup"){
foucsStatus = "1";
}
else if(foucsStatus == "angledown"){
foucsStatus = "2";
}
else if(foucsStatus == "vertical"){
foucsStatus = "3";
}
else if(foucsStatus == "rotation-up"){
foucsStatus = "4";
}
else if(foucsStatus == "rotation-down"){
foucsStatus = "5";
}
}

for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

for (let c = col_st; c <= col_ed; c++) {
let value = d[r][c];

if (getObjType(value) == "object") {
// if(attr in inlineStyleAffectAttribute && isInlineStringCell(value)){
updateInlineStringFormatOutside(value, attr, foucsStatus);
// }
// else{
d[r][c][attr] = foucsStatus;
// }

}
else{
d[r][c] = { v: value };
d[r][c][attr] = foucsStatus;
}

// if(attr == "tr" && d[r][c].tb != null){
// d[r][c].tb = "0";
// }
}
}
}

},
updateFormat: function(d, attr, foucsStatus){
let _this = this;

Expand Down Expand Up @@ -2903,136 +3039,7 @@ const menuButton = {
let col_st = Store.luckysheet_select_save[s]["column"][0],
col_ed = Store.luckysheet_select_save[s]["column"][1];

if(attr == "ct"){
for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

for (let c = col_st; c <= col_ed; c++) {
let cell = d[r][c], value = null;

if (getObjType(cell) == "object") {
value = d[r][c]["v"];
}
else{
value = d[r][c];
}

if(foucsStatus != "@" && isRealNum(value)){
value = parseFloat(value);
}

let mask = update(foucsStatus, value);
let type = "n";

if(is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47){
type = "d";
}
else if(foucsStatus == "@" || foucsStatus === 49){
type = "s"
}
else if(foucsStatus == "General" || foucsStatus === 0){
type = "g";
}

if (getObjType(cell) == "object") {
d[r][c]["m"] = mask;
if(d[r][c]["ct"] == null){
d[r][c]["ct"] = {};
}
d[r][c]["ct"]["fa"] = foucsStatus;
d[r][c]["ct"]["t"] = type;
}
else{
d[r][c] = { "ct":{"fa":foucsStatus, "t":type}, "v": value, "m": mask };
}
}
}
}
else{
if(attr == "ht"){
if(foucsStatus == "left"){
foucsStatus = "1";
}
else if(foucsStatus == "center"){
foucsStatus = "0";
}
else if(foucsStatus == "right"){
foucsStatus = "2";
}
}
else if(attr == "vt"){
if(foucsStatus == "top"){
foucsStatus = "1";
}
else if(foucsStatus == "middle"){
foucsStatus = "0";
}
else if(foucsStatus == "bottom"){
foucsStatus = "2";
}
}
else if(attr == "tb"){
if(foucsStatus == "overflow"){
foucsStatus = "1";
}
else if(foucsStatus == "clip"){
foucsStatus = "0";
}
else if(foucsStatus == "wrap"){
foucsStatus = "2";
}
}
else if(attr == "tr"){
if(foucsStatus == "none"){
foucsStatus = "0";
}
else if(foucsStatus == "angleup"){
foucsStatus = "1";
}
else if(foucsStatus == "angledown"){
foucsStatus = "2";
}
else if(foucsStatus == "vertical"){
foucsStatus = "3";
}
else if(foucsStatus == "rotation-up"){
foucsStatus = "4";
}
else if(foucsStatus == "rotation-down"){
foucsStatus = "5";
}
}

for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

for (let c = col_st; c <= col_ed; c++) {
let value = d[r][c];

if (getObjType(value) == "object") {
// if(attr in inlineStyleAffectAttribute && isInlineStringCell(value)){
updateInlineStringFormatOutside(value, attr, foucsStatus);
// }
// else{
d[r][c][attr] = foucsStatus;
// }

}
else{
d[r][c] = { v: value };
d[r][c][attr] = foucsStatus;
}

// if(attr == "tr" && d[r][c].tb != null){
// d[r][c].tb = "0";
// }
}
}
}
this.updateFormatCell(d, attr, foucsStatus, row_st, row_ed, col_st, col_ed);

if(attr == "tb" || attr == "tr" || attr == "fs"){
cfg = rowlenByRange(d, row_st, row_ed, cfg);
Expand Down
81 changes: 77 additions & 4 deletions src/global/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import editor from "./editor";
import luckysheetformula from './formula';
import cleargridelement from './cleargridelement';
import { genarate, update } from './format';
import { setAccuracy } from "./setdata";
import { setAccuracy,setcellvalue } from "./setdata";
import { orderbydata } from "./sort";
import { rowlenByRange } from "./getRowlen";
import { getdatabyselection, getcellvalue } from "./getdata";
Expand Down Expand Up @@ -98,16 +98,89 @@ export function setCellValue(row, column, value, options = {}) {
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
index = Store.currentSheetIndex,
order = curSheetOrder,
isRefresh = true,
success
} = {...options}

let luckysheetfile = getluckysheetfile();
let arrayIndex = getSheetIndex(index);
let data = luckysheetfile[arrayIndex].data;

luckysheetformula.updatecell(row, column, value);

// luckysheetformula.updatecell(row, column, value);
let formatList = {
//ct:1, //celltype,Cell value format: text, time, etc.
bg: 1,//background,#fff000
ff: 1,//fontfamily,
fc: 1,//fontcolor
bl: 1,//Bold
it: 1,//italic
fs: 1,//font size
cl: 1,//Cancelline, 0 Regular, 1 Cancelline
un: 1,//underline, 0 Regular, 1 underlines, fonts
vt: 1,//Vertical alignment, 0 middle, 1 up, 2 down
ht: 1,//Horizontal alignment,0 center, 1 left, 2 right
mc: 1, //Merge Cells
tr: 1, //Text rotation,0: 0、1: 45 、2: -45、3 Vertical text、4: 90 、5: -90
tb: 1, //Text wrap,0 truncation, 1 overflow, 2 word wrap
//v: 1, //Original value
//m: 1, //Display value
rt:1, //text rotation angle 0-180 alignment
//f: 1, //formula
qp:1 //quotePrefix, show number as string
}
if(value instanceof Object){
let curv = {};
if(value.f!=null && value.v==null){
curv.f = value.f;
if(value.ct!=null){
curv.ct = value.ct;
}
data = luckysheetformula.updatecell(row, column, curv, false).data;//update formula value
}
else{
if(value.ct!=null){
curv.ct = value.ct;
}
if(value.f!=null){
curv.f = value.f;
}
if(value.v!=null){
curv.v = value.v;
}
if(value.m!=null){
curv.m = value.m;
}
setcellvalue(row, column, data, curv);//update text value
}
for(let attr in value){
let v = value[attr];
if(attr in formatList){
menuButton.updateFormatCell(data, attr, v, row, row, column, column);//change range format
}
}
}
else{
if(value.substr(0,1)=="=" || value.substr(0,5)=="<span"){
data = luckysheetformula.updatecell(row, column, value, false).data;//update formula value or convert inline string html to object
}
else{
setcellvalue(row, column, data, value);
}

}


if(isRefresh){
jfrefreshgrid(data, [{ "row": [row, row], "column": [column, column] }]);//update data, meanwhile refresh canvas and store data to history
}
else{
luckysheetfile[arrayIndex] = data;//only update data
}

if (success && typeof success === 'function') {
success();
success(data);
}
}

Expand Down
Loading

0 comments on commit 9b208e4

Please sign in to comment.