|
@@ -435,10 +435,14 @@ const SpreadJsObj = {
|
|
}
|
|
}
|
|
cell.vAlign(1).hAlign(col.hAlign);
|
|
cell.vAlign(1).hAlign(col.hAlign);
|
|
|
|
|
|
- if (col.formatter) {
|
|
|
|
|
|
+ if(col.type === 'Number') {
|
|
|
|
+ if (col.formatter) {
|
|
|
|
+ cell.formatter(SpreadJsObj.Formatter.getNumberFormatter(col.formatter))
|
|
|
|
+ } else {
|
|
|
|
+ cell.formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
+ }
|
|
|
|
+ } else if (col.formatter) {
|
|
cell.formatter(col.formatter);
|
|
cell.formatter(col.formatter);
|
|
- } else if (col.type === 'Number') {
|
|
|
|
- cell.formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
cell.setBorder(sheet.borderLine, {all: true});
|
|
cell.setBorder(sheet.borderLine, {all: true});
|
|
@@ -478,19 +482,14 @@ const SpreadJsObj = {
|
|
cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
|
|
cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
|
|
}
|
|
}
|
|
|
|
|
|
- // if(col.type === 'Number') {
|
|
|
|
- // if (col.formatter) {
|
|
|
|
- // cell.formatter(SpreadJsObj.Formatter.getNumberFormatter(col.formatter))
|
|
|
|
- // } else {
|
|
|
|
- // cell.formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
- // }
|
|
|
|
- // } else if (col.formatter) {
|
|
|
|
- // cell.formatter(col.formatter);
|
|
|
|
- // }
|
|
|
|
- if (col.formatter) {
|
|
|
|
|
|
+ if(col.type === 'Number') {
|
|
|
|
+ if (col.formatter) {
|
|
|
|
+ cell.formatter(SpreadJsObj.Formatter.getNumberFormatter(col.formatter))
|
|
|
|
+ } else {
|
|
|
|
+ cell.formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
+ }
|
|
|
|
+ } else if (col.formatter) {
|
|
cell.formatter(col.formatter);
|
|
cell.formatter(col.formatter);
|
|
- } else if (col.type === 'Number') {
|
|
|
|
- cell.formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
cell.backColor(SpreadJsObj._getBackColor(sheet, data, row, col));
|
|
cell.backColor(SpreadJsObj._getBackColor(sheet, data, row, col));
|
|
@@ -611,6 +610,15 @@ const SpreadJsObj = {
|
|
}
|
|
}
|
|
if (colSetting.formatter) {
|
|
if (colSetting.formatter) {
|
|
sheet.getRange(-1, col, -1, 1).formatter(colSetting.formatter);
|
|
sheet.getRange(-1, col, -1, 1).formatter(colSetting.formatter);
|
|
|
|
+ if(colSetting.type === 'Number') {
|
|
|
|
+ if (col.formatter) {
|
|
|
|
+ sheet.getRange(-1, col, -1, 1).formatter(SpreadJsObj.Formatter.getNumberFormatter(colSetting.formatter));
|
|
|
|
+ } else {
|
|
|
|
+ sheet.getRange(-1, col, -1, 1).formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
+ }
|
|
|
|
+ } else if (col.formatter) {
|
|
|
|
+ cell.formatter(col.formatter);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
@@ -745,7 +753,13 @@ const SpreadJsObj = {
|
|
cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
|
|
cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
|
|
}
|
|
}
|
|
// 设置单元格格式
|
|
// 设置单元格格式
|
|
- if (col.formatter) {
|
|
|
|
|
|
+ if(col.type === 'Number') {
|
|
|
|
+ if (col.formatter) {
|
|
|
|
+ cell.formatter(SpreadJsObj.Formatter.getNumberFormatter(col.formatter))
|
|
|
|
+ } else {
|
|
|
|
+ cell.formatter(SpreadJsObj.Formatter.getNumberFormatter('0.######'));
|
|
|
|
+ }
|
|
|
|
+ } else if (col.formatter) {
|
|
cell.formatter(col.formatter);
|
|
cell.formatter(col.formatter);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -2080,9 +2094,10 @@ const SpreadJsObj = {
|
|
},
|
|
},
|
|
|
|
|
|
Formatter: {
|
|
Formatter: {
|
|
- baseNumberFormatter: (function (){
|
|
|
|
- const formatter = {};
|
|
|
|
- formatter.prototype = GC.Spread.Formatter.FormatterBase;
|
|
|
|
|
|
+ baseNumberFormatter: function () {
|
|
|
|
+ const formatter = function () {};
|
|
|
|
+ formatter.prototype = new GC.Spread.Formatter.FormatterBase();
|
|
|
|
+ const proto = formatter.prototype;
|
|
/**
|
|
/**
|
|
* 格式化数字显示方式
|
|
* 格式化数字显示方式
|
|
* 用法
|
|
* 用法
|
|
@@ -2092,7 +2107,7 @@ const SpreadJsObj = {
|
|
* @param num
|
|
* @param num
|
|
* @param pattern
|
|
* @param pattern
|
|
*/
|
|
*/
|
|
- formatter.formatNum = function (num, pattern) {
|
|
|
|
|
|
+ proto.formatNum = function (num, pattern) {
|
|
var strarr = num?num.toString().split('.'):['0'];
|
|
var strarr = num?num.toString().split('.'):['0'];
|
|
var fmtarr = pattern?pattern.split('.'):[''];
|
|
var fmtarr = pattern?pattern.split('.'):[''];
|
|
var retstr='';
|
|
var retstr='';
|
|
@@ -2146,23 +2161,22 @@ const SpreadJsObj = {
|
|
}
|
|
}
|
|
return retstr.replace(/^,+/,'').replace(/\.$/,'');
|
|
return retstr.replace(/^,+/,'').replace(/\.$/,'');
|
|
};
|
|
};
|
|
- formatter.format = function (obj, conditionalForeColor) {
|
|
|
|
|
|
+ proto.format = function (obj, formattedData) {
|
|
if (this.pattern) {
|
|
if (this.pattern) {
|
|
return this.formatNum(obj, this.pattern);
|
|
return this.formatNum(obj, this.pattern);
|
|
} else {
|
|
} else {
|
|
return obj;
|
|
return obj;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- return formatter;
|
|
|
|
- })(),
|
|
|
|
|
|
+ return new formatter();
|
|
|
|
+ },
|
|
_numFormatter: [],
|
|
_numFormatter: [],
|
|
getNumberFormatter(pattern) {
|
|
getNumberFormatter(pattern) {
|
|
let formatter = this._numFormatter.find(function (f) {
|
|
let formatter = this._numFormatter.find(function (f) {
|
|
return f.pattern === pattern;
|
|
return f.pattern === pattern;
|
|
});
|
|
});
|
|
if (!formatter) {
|
|
if (!formatter) {
|
|
- formatter = {};
|
|
|
|
- formatter.prototype = this.baseNumberFormatter.prototype;
|
|
|
|
|
|
+ formatter = this.baseNumberFormatter();
|
|
formatter.pattern = pattern;
|
|
formatter.pattern = pattern;
|
|
this._numFormatter.push(formatter);
|
|
this._numFormatter.push(formatter);
|
|
}
|
|
}
|