ExcelTool.prototype.instCustomFunction=function(){
/****
* 自定义函数
*/
function FactorialFunction() {
this.name = "MONEYTOCHINESE";
this.maxArgs = 1;
this.minArgs = 1;
}
FactorialFunction.prototype = new GcSpread.Sheets.Calc.Functions.Function();
FactorialFunction.prototype.evaluate=function(money){
var cnNums = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); //汉字的数字
var cnIntRadice = new Array("","拾","佰","仟"); //基本单位
var cnIntUnits = new Array("","万","亿","兆"); //对应整数部分扩展单位
var cnDecUnits = new Array("角","分","毫","厘"); //对应小数部分单位
var cnInteger = "整"; //整数金额时后面跟的字符
var cnIntLast = "元"; //整型完以后的单位
var maxNum = 999999999999999.9999; //最大处理的数字
var IntegerNum; //金额整数部分
var DecimalNum; //金额小数部分
var ChineseStr=""; //输出的中文金额字符串
var parts; //分离金额后用的数组,预定义
if( money == "" ){
return "";
}
money = parseFloat(money);
if( money >= maxNum ){
return "";
}
if( money == 0 ){
ChineseStr = cnNums[0]+cnIntLast+cnInteger;
return ChineseStr;
}
money = money.toString(); //转换为字符串
if( money.indexOf(".") == -1 ){
IntegerNum = money;
DecimalNum = '';
}else{
parts = money.split(".");
IntegerNum = parts[0];
DecimalNum = parts[1].substr(0,4);
}
if(parseInt(IntegerNum,10) > 0 ){//获取整型部分转换
zeroCount = 0;
IntLen = IntegerNum.length;
for( i=0;i<IntLen;i++ ){
n = IntegerNum.substr(i,1);
p = IntLen - i - 1;
q = p / 4;
m = p % 4;
if( n == "0" ){
zeroCount++;
}else{
if( zeroCount > 0 ){
ChineseStr += cnNums[0];
}
zeroCount = 0; //归零
ChineseStr += cnNums[parseInt(n)]+cnIntRadice[m];
}
if( m==0 && zeroCount<4 ){
ChineseStr += cnIntUnits[q];
}
}
ChineseStr += cnIntLast;
//整型部分处理完毕
}
if( DecimalNum!= '' ){//小数部分
decLen = DecimalNum.length;
for( i=0; i<decLen; i++ ){
n = DecimalNum.substr(i,1);
if( n != '0' ){
ChineseStr += cnNums[Number(n)]+cnDecUnits;
}
}
}
if(ChineseStr == '' ){
ChineseStr += cnNums[0]+cnIntLast+cnInteger;
}
else if( DecimalNum == '' ){
ChineseStr += cnInteger;
}
return ChineseStr;
};
var factorial = new FactorialFunction();
this.sheet.addCustomFunction(factorial);
}这个是我的自定义函数,
ExcelTool.prototype.printInfo=function(sheetNum){
/***打印设置**/
var printInfo = this.sheet.printInfo();
printInfo.qualityFactor(4);
printInfo.orientation(GcSpread.Sheets.PrintPageOrientation.Landscape);
printInfo.paperSize(new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4));
printInfo.showRowHeader(true);
printInfo.showColumnHeader(true);
//top:5, bottom:5, left:5, right:5, header:5, footer:5
printInfo.margin({top:1,left:1,right:1,bottom:1});
printInfo.showGridLine(false);
printInfo.showBorder(false);
if(typeof(sheetNum) != "undefined"){
this.spread.print(sheetNum);
} else {
this.spread.print();
}
}这个是打印的方法
1、用户只要根据我的规律比如单元格值=111我就替换这个函数为我的自定义函数。打印的时候就显示乱码(注:就是excel找不到这个函数出现的那种错误)
|