本帖最后由 dp99 于 2018-8-7 21:40 编辑
我改了一下,好像还是不起作用,有需要设置的地方吗?附我的工程。
// JavaScript source code
function CalculateFunction() {
this.name = 'CALCULATE';
this.maxArgs = 6;
this.minArgs = 4;
}
CalculateFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
CalculateFunction.prototype.evaluate = function (args) {
var formula = arguments[0] == null ? 0 : arguments[0];
var gao = arguments[1] == null ? 0 : arguments[1];
var kuan = arguments[2] == null ? 0 : arguments[2];
var hou = arguments[3] == null ? 0 : arguments[3];
var shuliang = arguments[4] == null ? 0 : arguments[4];
var jiajia = arguments[5] == null ? 0 : arguments[5];
var fu1 = arguments[6] == null ? 0 : arguments[6];
var fu2 = arguments[7] == null ? 0 : arguments[7];
var danjia = arguments[8] == null ? 0 : arguments[8];
var men = arguments[9] == null ? 0 : arguments[9];
var tao = arguments[10] == null ? 0 : arguments[10];
var jijia = arguments[11] == null ? 0 : arguments[11];
var xian1 = arguments[12] == null ? 0 : arguments[12];
var xian2 = arguments[13] == null ? 0 : arguments[13];
var se1 = arguments[14] == null ? 0 : arguments[14];
var se2 = arguments[15] == null ? 0 : arguments[15];
var myParam = new Array("高", "宽","厚","数量","加价","附1","附2","单价","门尺寸","套板尺寸","基价","线1","线2","色1","色2");
var myValue = new Array(gao, kuan,hou,shuliang,jiajia,fu1,fu2,danjia,men,tao,jijia,xian1,xian2,se1,se2);
if (!formula) {
return "";
}
formula = formula.replace(/\PI\(\)/ig, Math.PI);
for (var i = 0; i < myParam.length; i++) {
var regEx = new RegExp(myParam, "g");
formula = formula.replace(regEx, myValue);
}
//return Forguncy.ForguncyData.pageInfo.formulaManager.evaluateFormula("=" + formula, false);
return Forguncy.ForguncyData.pageInfo.formulaManager.evaluateFormula("=" + formula, false) == 0 ?
"" : Forguncy.ForguncyData.pageInfo.formulaManager.evaluateFormula("=" + formula, false);
}
//function getAllCharNotContainOperator(string) {
// var str = string.replace(/\PI\(\)/ig, "派");
// var value = str.replace(/\+/g, "").replace(/\-/g, "").replace(/\*/g, "").replace(/\//g, "").replace(/\(/g, "").replace(/\)/g, "").replace(/[0-9]/g, '');
// value = value.split("").filter(function (x, n, s) { return s.indexOf(x) == n }).join("");
// value.replace(/\派/g, "");
// return value;
//}
GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("CALCULATE", new CalculateFunction());
|