本帖最后由 ilovegan 于 2018-6-12 01:23 编辑
自己解决了。
function NumberInWan(){};
NumberInWan.prototype = new GC.Spread.Formatter.FormatterBase();
NumberInWan.prototype.format = function (obj, formattedData) {
if (typeof obj === "number") {
return formatNumber(obj, formattedData);
} else if (typeof obj === "string") {
if ($.isNumeric(obj)) {
return formatNumber(parseFloat(obj), formattedData);
}
}
return obj ? obj.toString() : "";
};
function formatNumber(value, formattedData) {
var valuestr = value.toString();
if (isFinite(value)) {
valuestr = (value/10000).toFixed(1)
if(value<0)
{
formattedData.conditionalForeColor = "red";
value = -value;
valuestr = "("+valuestr.substr(1,valuestr.length-1)+")W";
}
else if(value>0)
{
valuestr = valuestr+"W";
}
else
{
valuestr = '-';
}
}
return valuestr;
}
NumberInWan.prototype.parse = function (str) {
return new GC.Spread.Formatter.GeneralFormatter().parse(str);
};
sheet.getRange(0,0,100,100).formatter(new NumberInWan()) |