//�첽�������� ReportAnsnFuncNum = 0; //�첽������ɸ��� ReportAnsnDoneNum = 0; //��ѯͳ��ֵ���б� ȫ���ռ����б��һ�β�ѯ var TagStasticSearchInfoList = new Array(); //��ѯ��ʷʱ��ֵ���б�ȫ���ռ����б��һ�β�ѯ var ReportTagHisValueSearchInfoList = new Array(); //�Ƿ��Զ��幫ʽ function IsCustumFormula(fromStr) { var index = fromStr.indexOf("GetTagSnapShort("); if (index >= 0) return true; index = fromStr.indexOf("GetTagHisValue("); if (index >= 0) return true; index = fromStr.indexOf("GetTagHisInterval("); if (index >= 0) return true; index = fromStr.indexOf("GetTimeInterval("); if (index >= 0) return true; index = fromStr.indexOf("GetTimeStastic("); if (index >= 0) return true; index = fromStr.indexOf("GetTagTimeStasticValue("); if (index >= 0) return true; index = fromStr.indexOf("GetTagTimeStasticValue2("); if (index >= 0) return true; index = fromStr.indexOf("GetTimeDisplayStr("); if (index >= 0) return true; return false; } //�Ƿ��Զ����첽���� function IsAnsnFunc(funcName) { index = funcName.indexOf("GetTagHisInterval("); if (index >= 0) return true; index = funcName.indexOf("GetTimeInterval("); if (index >= 0) return true; return false; } //�Ƿ��Զ���ͬ������ function IsCustomNoAnsnFunc(funcName) { index = funcName.indexOf("GetTimeDisplayStr("); if (index >= 0) return true; return false; } //ע���Զ��庯�� function ApplyCustomFunc(spread) { var sheet = spread.getSheet(0); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGSNAPSHORT", new goldenNameSpace.GetTagSnapShort()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGHISVALUE", new goldenNameSpace.GetTagHisValue()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGHISINTERVAL", new goldenNameSpace.GetTagHisInterval()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEINTERVAL", new goldenNameSpace.GetTimeInterval()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMESTASTIC", new goldenNameSpace.GetTimeStastic()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGTIMESTASTICVALUE", new goldenNameSpace.GetTagTimeStasticValue()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGTIMESTASTICVALUE2", new goldenNameSpace.GetTagTimeStasticValue2()); GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEDISPLAYSTR", new goldenNameSpace.GetTimeDisplayStr()); /* var getTagSnapShort = new goldenNameSpace.GetTagSnapShort(); sheet.addCustomFunction(getTagSnapShort); var getTagHisValue = new goldenNameSpace.GetTagHisValue(); sheet.addCustomFunction(getTagHisValue); var getTagHisInterval = new goldenNameSpace.GetTagHisInterval(); sheet.addCustomFunction(getTagHisInterval); var getTimeInterval = new goldenNameSpace.GetTimeInterval(); sheet.addCustomFunction(getTimeInterval); var getTimeStastic= new goldenNameSpace.GetTimeStastic(); sheet.addCustomFunction(getTimeStastic); var getTagTimeStasticValue= new goldenNameSpace.GetTagTimeStasticValue(); sheet.addCustomFunction(getTagTimeStasticValue); var getTagTimeStasticValue2= new goldenNameSpace.GetTagTimeStasticValue2(); sheet.addCustomFunction(getTagTimeStasticValue2); var getTimeDisplayStr= new goldenNameSpace.GetTimeDisplayStr(); sheet.addCustomFunction(getTimeDisplayStr); var getTagHisValue= new goldenNameSpace.GetTagHisValue(); sheet.addCustomFunction(getTagHisValue);*/ } //ִ���Զ���ͬ������ function DoCustomNoAnsnFunc(spread) { var sheet = spread.getSheet(0); //ApplyCustomFunc(spread); var colNum = sheet.getColumnCount(); var rowNum = sheet.getRowCount(); for (var i = 0; i < colNum; i++) { for (var j = 0; j < rowNum; j++) { var calcu = sheet.getFormula(j, i); if (calcu != null) { if (IsCustomNoAnsnFunc(calcu)) sheet.setFormula(j, i, "=" + calcu); } } } } //ִ�з��Զ��庯�� function DoNoCustomFunc(spread) { var sheet = spread.getSheet(0); //ApplyCustomFunc(spread); var colNum = sheet.getColumnCount(); var rowNum = sheet.getRowCount(); for (var i = 0; i < colNum; i++) { for (var j = 0; j < rowNum; j++) { var calcu = sheet.getFormula(j, i); if (calcu != null) { if (!IsCustumFormula(calcu)) sheet.setFormula(j, i, "=" + calcu); } } } } //���¼��ʽ function ResetFormular(spread) { var sheet = spread.getSheet(0); //ApplyCustomFunc(spread); var colNum = sheet.getColumnCount(); var rowNum = sheet.getRowCount(); ReportAnsnFuncNum = 0; for (var i = 0; i < colNum; i++) { for (var j = 0; j < rowNum; j++) { var calcu = sheet.getFormula(j, i); if (calcu != null) { //if(IsCustumFormula(calcu)) //sheet.setFormula(j,i, "="+calcu); if (IsAnsnFunc(calcu)) { ReportAnsnFuncNum++; } } /* var valueStr=sheet.getValue(j,i); if(!valueStr) continue; try { if(valueStr.indexOf(" ")>=0) { var myCellType = new MyCellType(); sheet.getCell(j,i).cellType(myCellType) } } catch(e) { }*/ } //sheet.autoFitColumn(i); } } //б�߱�ͷ function MyCellType() { } MyCellType.prototype = new GC.Spread.Sheets.CellTypes.Text(); MyCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) { //Paints a cell on the canvas. if (!ctx) { return; } ctx.save(); ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + w, y + h); ctx.stroke(); ctx.font = style.font; var text = value ? value.split(" ") : ["", ""]; ctx.fillText(text[0].trim(), x + w * 7 / 8, y + h / 3); ctx.fillText(text[1].trim(), x + w / 2, y + h * 3 / 4); ctx.restore(); }; var goldenNameSpace = {}; (function () { // �Զ��幫ʽ����ȡͳ��ʱ���ֵ2��---------------------------------------------------------------------- function GetTagTimeStasticValue2() { this.name = 'GetTagTimeStasticValue2'; this.maxArgs = 5; this.minArgs = 5; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue2", 0, 0]); this.typeName = "goldenNameSpace.GetTagTimeStasticValue2"; } //ͬ����ʽ goldenNameSpace.GetTagTimeStasticValue2 = GetTagTimeStasticValue2; GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.Function(); GetTagTimeStasticValue2.prototype.evaluateMode = function () { return 0; }; GetTagTimeStasticValue2.prototype.evaluate = function (arg) { if (arguments.length >= 4) { var ReportTag = arguments[0]; var ReportStartTime = arguments[1]; var ReportEndTime = arguments[2]; var ReportSelectType = arguments[3]; ReportStartTime = window[ReportStartTime];//��ȡ�ؼ��еı���ֵ if (!ReportStartTime) return ""; ReportEndTime = window[ReportEndTime];//��ȡ�ؼ��еı���ֵ if (!ReportEndTime) return ""; } else return ""; var TempStartTime = new Date(Date.parse(ReportStartTime)); var TempEndTime = new Date(Date.parse(ReportEndTime)); //��ȡͳ��ֵ var vv = GetTagStasticSearchValue(TempStartTime, TempEndTime, ReportTag, ReportSelectType); if (!vv) { return 0; } else return parseFloat(vv); } /* //�첽��ʽ GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(); GetTagTimeStasticValue2.prototype.evaluateMode = function () { return 0; }; goldenNameSpace.GetTagTimeStasticValue2=GetTagTimeStasticValue2; GetTagTimeStasticValue2.prototype.evaluateAsync = function (context) { if(arguments.length>=5) { var ReportTag=arguments[1]; var ReportStartTime=arguments[2]; var ReportEndTime=arguments[3]; var ReportSelectType=arguments[4]; ReportStartTime= window[ReportStartTime];//��ȡ�ؼ��еı���ֵ if(!ReportStartTime) { context.setAsyncResult(0); return; } ReportEndTime= window[ReportEndTime];//��ȡ�ؼ��еı���ֵ if(!ReportEndTime) { context.setAsyncResult(0); return; } } else { context.setAsyncResult(0); return; } var TempStartTime=new Date(Date.parse(ReportStartTime)); var TempEndTime=new Date(Date.parse(ReportEndTime)); //��ȡͳ��ֵ var vv=GetTagStasticSearchValue(TempStartTime,TempEndTime,ReportTag,ReportSelectType); if(!vv) { context.setAsyncResult(0); return; } else context.setAsyncResult(vv); } */ // �Զ��幫ʽ����ȡͳ��ʱ���ֵ��---------------------------------------------------------------------- function GetTagTimeStasticValue() { this.name = 'GetTagTimeStasticValue'; this.maxArgs = 4; this.minArgs = 4; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue", 0, 0]); this.typeName = "goldenNameSpace.GetTagTimeStasticValue"; } GetTagTimeStasticValue.prototype = new GC.Spread.CalcEngine.Functions.Function(); GetTagTimeStasticValue.prototype.evaluateMode = function () { return 0; }; goldenNameSpace.GetTagTimeStasticValue = GetTagTimeStasticValue; GetTagTimeStasticValue.prototype.evaluate = function (context) { if (arguments.length >= 4) { ReportTag = arguments[0]; ReportSelectTime = arguments[1]; ReportTimeType = arguments[2]; ReportSelectType = arguments[3]; ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ if (!ReportSelectTime) return ""; } else return ""; var TempStartTime = new Date(Date.parse(ReportSelectTime)); var TempEndTime = new Date(Date.parse(ReportSelectTime)); if (ReportTimeType == 'd' || ReportTimeType == 'D') { TempStartTime.setHours(0); TempStartTime.setMinutes(0); TempStartTime.setSeconds(0); TempEndTime.setHours(23); TempEndTime.setMinutes(59); TempEndTime.setSeconds(59); } else if (ReportTimeType == 'm' || ReportTimeType == 'M') { TempStartTime.setDate(1); TempStartTime.setHours(0); TempStartTime.setMinutes(0); TempStartTime.setSeconds(0); TempEndTime.setMonth(TempEndTime.getMonth() + 1); TempEndTime.setDate(0); TempEndTime.setHours(23); TempEndTime.setMinutes(59); TempEndTime.setSeconds(59); } else if (ReportTimeType == 'y' || ReportTimeType == 'Y') { TempStartTime.setMonth(0); TempStartTime.setDate(1); TempStartTime.setHours(0); TempStartTime.setMinutes(0); TempStartTime.setSeconds(0); var year = TempEndTime.getYear(); TempEndTime.setYear(year + 1 + 1900); TempEndTime.setMonth(0); TempEndTime.setDate(0); TempEndTime.setHours(23); TempEndTime.setMinutes(59); TempEndTime.setSeconds(59); } //��ȡͳ��ֵ var vv = GetTagStasticSearchValue(TempStartTime, TempEndTime, ReportTag, ReportSelectType); if (!vv) { return 0; } else return parseFloat(vv); } // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��---------------------------------------------------------------------- function GetTimeDisplayStr() { this.name = 'GetTimeDisplayStr'; this.maxArgs = 2; this.minArgs = 2; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeDisplayStr", 0, 0]); this.typeName = "goldenNameSpace.GetTimeDisplayStr"; } goldenNameSpace.GetTimeDisplayStr = GetTimeDisplayStr; GetTimeDisplayStr.prototype = new GC.Spread.CalcEngine.Functions.Function(); GetTagTimeStasticValue2.prototype.evaluateMode = function () { return 0; }; /*GetTimeDisplayStr.prototype.evaluateMode = function () { return 0; };*/ GetTimeDisplayStr.prototype.evaluate = function (context) { //context.setAsyncResult(""); //return; if (arguments.length >= 2) { ReportSelectTime = arguments[0]; ReportTimeFormat = arguments[1]; ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ if (!ReportSelectTime) { return "δ�ҵ�ʱ�����!"; } } else { return "������������!"; return; } ReportSelectTime = new Date(Date.parse(ReportSelectTime)); var ReportSelectTimeStr = ReportSelectTime.Format(ReportTimeFormat); return ReportSelectTimeStr + ""; } // �Զ��幫ʽ����ȡͳ��ʱ���ֵ��---------------------------------------------------------------------- // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��---------------------------------------------------------------------- function GetTimeStastic() { this.name = 'GetTimeStastic'; this.maxArgs = 4; this.minArgs = 4; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeStastic", 0, 0]); this.typeName = "goldenNameSpace.GetTimeStastic"; } goldenNameSpace.GetTimeStastic = GetTimeStastic; GetTimeStastic.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(); GetTimeStastic.prototype.evaluateMode = function () { return 0; }; GetTimeStastic.prototype.evaluateAsync = function (context) { if (arguments.length >= 5) { ReportSelectTime = arguments[1]; ReportTimeType = arguments[2]; ReportSelectType = arguments[3]; ReportTimeFormat = arguments[4]; ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ } else { context.setAsyncResult("error!"); return; } ReportSelectTime = new Date(Date.parse(ReportSelectTime)); if (ReportTimeType == 'd') { if (ReportSelectType == "start") { ReportSelectTime.setHours(0); ReportSelectTime.setMinutes(0); ReportSelectTime.setSeconds(0); } else { ReportSelectTime.setHours(23); ReportSelectTime.setMinutes(59); ReportSelectTime.setSeconds(59); } } else if (ReportTimeType == 'm') { if (ReportSelectType == "start") { ReportSelectTime.setSeconds(0); } else { ReportSelectTime.setSeconds(59); } } else if (ReportTimeType == 'h') { if (ReportSelectType == "start") { ReportSelectTime.setMinutes(0); ReportSelectTime.setSeconds(0); } else { ReportSelectTime.setMinutes(59); ReportSelectTime.setSeconds(59); } } else if (ReportTimeType == 'M') { if (ReportSelectType == "start") { ReportSelectTime.setDate(1); ReportSelectTime.setHours(0); ReportSelectTime.setMinutes(0); ReportSelectTime.setSeconds(0); } else { ReportSelectTime.setMonth(ReportSelectTime.getMonth() + 1); ReportSelectTime.setDate(0); ReportSelectTime.setHours(23); ReportSelectTime.setMinutes(59); ReportSelectTime.setSeconds(59); } } else if (ReportTimeType == 'y') { if (ReportSelectType == "start") { ReportSelectTime.setMonth(0); ReportSelectTime.setDate(1); ReportSelectTime.setHours(0); ReportSelectTime.setMinutes(0); ReportSelectTime.setSeconds(0); } else { var year = ReportSelectTime.getYear(); ReportSelectTime.setYear(year + 1 + 1900); ReportSelectTime.setMonth(0); ReportSelectTime.setDate(0); ReportSelectTime.setHours(23); ReportSelectTime.setMinutes(59); ReportSelectTime.setSeconds(59); } } var ReportSelectTimeStr = ReportSelectTime.Format(ReportTimeFormat); context.setAsyncResult(ReportSelectTimeStr); } // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��---------------------------------------------------------------------- // �Զ��幫ʽ����ȡʱ��εĵȼ����ʾ��---------------------------------------------------------------------- function GetTimeInterval() { this.name = 'GetTimeInterval'; this.maxArgs = 6; this.minArgs = 6; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeInterval", 0, 0]); this.typeName = "goldenNameSpace.GetTimeInterval"; } GetTimeInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(); GetTimeInterval.prototype.defaultValue = function () { return 'loading' }; GetTimeInterval.prototype.evaluateMode = function () { return 0; }; goldenNameSpace.GetTimeInterval = GetTimeInterval; //��ȡ��ʷ�ȼ������ GetTimeInterval.prototype.evaluateAsync = function (context) { var args = arguments; var curCol = context.col; var curRow = context.row; if (args.length >= 6) { var ReportStartTime = args[1]; var ReportEndTime = args[2]; var ReportInterval = args[3]; var ReportIntervalType = args[4]; var ReportTimeFormat = args[5]; var ReportVH = args[6]; ReportStartTime = window[ReportStartTime]; ReportEndTime = window[ReportEndTime]; if (ReportStartTime == "") return; if (ReportEndTime == "") return; //ReportInterval= window[ReportInterval]; //ReportIntervalType = window[ReportIntervalType]; } else { context.setAsyncResult(0); return; } //清除原数据 var clearNum = 0; var sheet = context.ctx.source; if (ReportIntervalType == 'd') { clearNum = 31; } else if (ReportIntervalType == 'm') { clearNum = 60; } else if (ReportIntervalType == 'h') { clearNum = 24; } var sheet = context.ctx.source; for (var kk = 0; kk < clearNum; kk++) { if (ReportVH == "v") { if (curRow + kk < sheet.getRowCount() && curCol < sheet.getColumnCount()) sheet.setValue(curRow + kk, curCol, ""); } else if (ReportVH == "h") { if (curRow < sheet.getRowCount() && curCol + kk < sheet.getColumnCount()) sheet.setValue(curRow, curCol + kk, ""); } } var tempDateTime = new Date(Date.parse(ReportStartTime)); var tempEndTime = new Date(Date.parse(ReportEndTime)); var sheet = context.ctx.source; for (var i = 0; i < 200; i++) { var tempDateStr = tempDateTime.Format(ReportTimeFormat); if (i == 0) { context.setAsyncResult(tempDateStr); //sheet.setValue(curRow,curCol,tempDateStr); } else if (ReportVH == "v") { if (curRow + i < sheet.getRowCount() && curCol < sheet.getColumnCount()) sheet.setValue(curRow + i, curCol, tempDateStr); } else if (ReportVH == "h") { if (curRow < sheet.getRowCount() && curCol + i < sheet.getColumnCount()) sheet.setValue(curRow, curCol + i, tempDateStr); } if (ReportIntervalType == 's') { tempDateTime.setSeconds(tempDateTime.getSeconds() + ReportInterval); } else if (ReportIntervalType == 'm') { tempDateTime.setMinutes(tempDateTime.getMinutes() + ReportInterval); } else if (ReportIntervalType == 'h') { tempDateTime.setHours(tempDateTime.getHours() + ReportInterval); } else if (ReportIntervalType == 'd') { tempDateTime.setDate(tempDateTime.getDate() + ReportInterval); } else if (ReportIntervalType == 'M') { tempDateTime.setMonth(tempDateTime.getMonth() + ReportInterval); } else if (ReportIntervalType == 'y') { tempDateTime.setYear(tempDateTime.getYear() + ReportInterval); } if (tempDateTime >= tempEndTime) break; } ReportAnsnDoneNum++; //tempDateTime=new Date(Date.parse(ReportStartTime)); //tempDateStr=tempDateTime.Format(ReportTimeFormat); //context.setAsyncResult(tempDateStr); } // �Զ��幫ʽ����ȡʱ��εĵȼ����ʾ��---------------------------------------------------------------------- // �Զ��幫ʽ����ȡ��ȡ��ʷ�ȼ�����ݣ�---------------------------------------------------------------------- function GetTagHisInterval() { this.name = 'GetTagHisInterval'; this.maxArgs = 6; this.minArgs = 6; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisInterval", 0, 0]); this.typeName = "goldenNameSpace.GetTagHisInterval"; } goldenNameSpace.GetTagHisInterval = GetTagHisInterval; GetTagHisInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(); GetTagHisInterval.prototype.defaultValue = function () { return 'loading' }; GetTagHisInterval.prototype.evaluateMode = function () { return 0; }; GetTagHisInterval.prototype.interval = function () { return 1000; }; //��ȡ��ʷ�ȼ������ GetTagHisInterval.prototype.evaluateAsync = function (context) { var args = arguments; var curCol = context.col; var curRow = context.row; var ReportIntervalSumType = "snap"; var valueCount = 0; if (args.length >= 5) { var Reporttag = args[1]; var ReportStartTime = args[2]; var ReportEndTime = args[3]; var ReportInterval = args[4]; var ReportIntervalType = args[5]; ReportIntervalSumType = args[6]; //ͳ������ ��min,max var ReportVH = args[7]; ReportStartTime = window[ReportStartTime]; ReportEndTime = window[ReportEndTime]; if (ReportStartTime == "") {ReportAnsnDoneNum++; return; } if (ReportEndTime == "") {ReportAnsnDoneNum++; return; } //ReportInterval= window[ReportInterval]; //ReportIntervalType= "0";// window[ReportIntervalType]; } else { ReportAnsnDoneNum++; context.setAsyncResult(0); return; } var TempEndTime = new Date(Date.parse(ReportEndTime)); var TempStartTime = new Date(Date.parse(ReportStartTime)); var ReportIntervalSumTypeStr = "0"; if (ReportIntervalSumType == "snap") { ReportIntervalSumTypeStr = "0"; } else if (ReportIntervalSumType == "max") { ReportIntervalSumTypeStr = "1"; } else if (ReportIntervalSumType == "min") { ReportIntervalSumTypeStr = "2"; } else if (ReportIntervalSumType == "avg") { ReportIntervalSumTypeStr = "3"; } else if (ReportIntervalSumType == "total") { ReportIntervalSumTypeStr = "4"; } else { ReportIntervalSumTypeStr = "0"; } if (ReportIntervalType == "m")//���� { ReportInterval = ReportInterval * 60; valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 60; } else if (ReportIntervalType == "h")//Сʱ { ReportInterval = ReportInterval * 3600; valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 3600; } else if (ReportIntervalType == "d")//�� { ReportInterval = ReportInterval * 3600 * 24; valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 24 / 3600; TempStartTime.setSeconds(TempStartTime.getSeconds() + 86399);//取每天23:59:59秒值 } var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName="; //+ cmdStr; pageIndex = 1; if (valueCount < 200) tagsCount = parseInt(valueCount + 0.5); else tagsCount = 200; urlStr += createSearchStr(Reporttag, TempStartTime, ReportEndTime, ReportInterval, ReportIntervalSumTypeStr, ReportInterval) + '&pageIndex=' + pageIndex + '&pageSize=' + tagsCount; // getTableHisData(shotTablePane,url,shotTableTableModel,shotTablecolumns,shotTablerows); $.ajax({ type: 'GET', url: urlStr, dataType: 'json', cache: false, error:function(data) { ReportAnsnDoneNum++; return; }, success: function (data) { if (!data.Datas && !data) { context.setAsyncResult("not find!"); ReportAnsnDoneNum++; return; } var arr; if (data.Datas) arr = data.Datas; else if (data) arr = data; //清除原数据 var clearNum = 0; if (ReportIntervalType == 'd') { clearNum = 31; } else if (ReportIntervalType == 'm') { clearNum = 60; } else if (ReportIntervalType == 'h') { clearNum = 24; } var sheet = context.ctx.source; for (var kk = 0; kk < clearNum; kk++) { if (ReportVH == "v") { if (curRow + kk < sheet.getRowCount() && curCol < sheet.getColumnCount()) sheet.setValue(curRow + kk, curCol, ""); } else if (ReportVH == "h") { if (curRow < sheet.getRowCount() && curCol + kk < sheet.getColumnCount()) sheet.setValue(curRow, curCol + kk, ""); } } for (var key in arr) { var tagData = arr[key]; if (!tagData) continue; if (tagData.length > 0) { var showCount = 200; if (tagData.length < showCount) showCount = tagData.length; var actVal = 0; if (ReportIntervalSumType == "snap") actVal = GetDital(tagData[0].Value, 3); else if (ReportIntervalSumType == "min") actVal = GetDital(tagData[0].Min, 3); else if (ReportIntervalSumType == "max") actVal = GetDital(tagData[0].Max, 3); else if (ReportIntervalSumType == "avg") actVal = GetDital(tagData[0].CalcAvg, 3); else if (ReportIntervalSumType == "total") actVal = GetDital(tagData[0].Total, 3); context.setAsyncResult(actVal); for (var i = 0; i < showCount; i++) { if (ReportIntervalSumType == "snap") actVal = GetDital(tagData[i].Value, 3); else if (ReportIntervalSumType == "min") actVal = GetDital(tagData[i].Min, 3); else if (ReportIntervalSumType == "max") actVal = GetDital(tagData[i].Max, 3); else if (ReportIntervalSumType == "avg") actVal = GetDital(tagData[i].CalcAvg, 3); else if (ReportIntervalSumType == "total") actVal = GetDital(tagData[i].Total, 3); if (ReportVH == "v") { if (curRow + i < sheet.getRowCount() && curCol < sheet.getColumnCount()) sheet.setValue(curRow + i, curCol, actVal); } else if (ReportVH == "h") { if (curRow < sheet.getRowCount() && curCol + i < sheet.getColumnCount()) sheet.setValue(curRow, curCol + i, actVal); } } //sheet.autoFitColumn(curCol); ReportAnsnDoneNum++; sheet.refresh(); return; } else { context.setAsyncResult("not find!"); ReportAnsnDoneNum++; return; } break; } var sheet = context.ctx.source; sheet.refresh(); ReportAnsnDoneNum++; } }) } //�����ȼ����ʷ��ѯ�IJ�ѯ�ַ��� function createSearchStr(tagNameStr, beginTime, endTime, interval, valueType, count) { beginTime = moment(new Date(beginTime)).format("YYYY-MM-DD H:mm:ss"); endTime = moment(new Date(endTime)).format("YYYY-MM-DD H:mm:ss"); interval = interval || 10; //valueType = valueType || 1; count = Math.floor((new Date(endTime) - new Date(beginTime)) / interval / 1000); var result = ''; var tagsInfo = encodeURIComponent(tagNameStr); result = tagsInfo + '&beginTime=' + beginTime + '&endTime=' + endTime + '&interval=' + interval + '&count=' + count; if (valueType !== '0') { result += '&valueType=' + valueType; } return result; } // �Զ��幫ʽ����ȡ��ȡ��ʷ�ȼ�����ݣ�---------------------------------------------------------------------- // �Զ��幫ʽ����ȡ����ֵ��---------------------------------------------------------------------- function GetTagSnapShort() { this.name = 'GETTAGSNAPSHORT'; this.maxArgs = 2; this.minArgs = 2; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagSnapShort", 0, 0]); this.typeName = "goldenNameSpace.GetTagSnapShort"; } goldenNameSpace.GetTagSnapShort = GetTagSnapShort; GetTagSnapShort.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(); GetTagSnapShort.prototype.defaultValue = function () { return 'loading' }; GetTagSnapShort.prototype.evaluateMode = function () { return 0; }; GetTagSnapShort.prototype.interval = function () { return 1000; }; GetTagSnapShort.prototype.evaluateAsync = function (context) { var args = arguments; if (args.length > 1) tag = args[1]; else { context.setAsyncResult(0); return; } var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName="; var para = tag; str = str + encodeURIComponent(para); $.ajax({ url: str, type: 'GET', dataType: 'json', cache: false, success: function (data) { if (data === null) return; var snapshots = eval(data); //�жϿ����Ƿ�Ϊ�� if (snapshots != null) { var value = 0; if (snapshots.length > 0) value = snapshots[0].Value; var actVal = GetDital(value, 3); context.setAsyncResult(actVal); } }, complete: function (XHR, TS) { XHR = null; } } ); } // �Զ��幫ʽ����ȡ����ֵ��---------------------------------------------------------------------- // �Զ��幫ʽ����ȡ��ʷʱ��ֵ��---------------------------------------------------------------------- function GetTagHisValue() { this.name = 'GETTAGHISVALUE'; this.maxArgs = 3; this.minArgs = 2; GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisValue", 0, 0]); this.typeName = "goldenNameSpace.GetTagHisValue"; } goldenNameSpace.GetTagHisValue = GetTagHisValue; //ͬ����ʽ GetTagHisValue.prototype = new GC.Spread.CalcEngine.Functions.Function(); GetTagHisValue.prototype.defaultValue = function () { return 'loading' }; GetTagHisValue.prototype.evaluateMode = function () { return 0; }; GetTagHisValue.prototype.interval = function () { return 1000; }; GetTagHisValue.prototype.evaluate = function (context) { var args = arguments; var tag = ""; var hisTimeStr = ""; if (args.length > 1) { tag = args[0]; if (tag.indexOf("WT1.") >= 0) { var ssssss = 1; } hisTimeStr = args[1]; if (!hisTimeStr) { //context.setAsyncResult(0); return 0; } hisTimeStr = window[hisTimeStr]; if (!hisTimeStr) { // context.setAsyncResult(0); return 0; } var tempTime = new Date(Date.parse(hisTimeStr)); if (!tempTime) { // context.setAsyncResult(0); return 0; } //偏移秒 var addSec=0; if(args.length>=3) { addSec=parseInt(args[2]); tempTime.setSeconds( tempTime.getSeconds()+addSec); } var vv = GetReportTagHisValue(tempTime, tag); if (!vv) { //context.setAsyncResult(0); return 0; } else { // context.setAsyncResult( vv); return parseFloat(vv); } } else { // context.setAsyncResult(0); return 0; } } /* �첽��ʽ GetTagHisValue.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(); GetTagHisValue.prototype.defaultValue = function () {return 'loading'}; GetTagHisValue.prototype.evaluateMode = function () { return 0; }; GetTagHisValue.prototype.interval = function () { return 1000; }; GetTagHisValue.prototype.evaluateAsync = function (context) { var args = arguments; var tag=""; var hisTimeStr=""; if(args.length>1) { tag=args[1]; if(tag.indexOf("WT1.")>=0) { var ssssss=1; } hisTimeStr=args[2]; if(!hisTimeStr) { context.setAsyncResult(0); return; } hisTimeStr=window[hisTimeStr]; if(!hisTimeStr) { context.setAsyncResult(0); return; } var tempTime=new Date(Date.parse(hisTimeStr)); if(!tempTime) { context.setAsyncResult(0); return; } var vv=GetReportTagHisValue(tempTime,tag); if(!vv) { context.setAsyncResult(0); return; } else context.setAsyncResult( vv); } else { context.setAsyncResult(0); return; } }*/ })(); // ��Date����չ���� Date ת��Ϊָ����ʽ��String // ��(M)����(d)��Сʱ(h)����(m)����(s)������(q) ������ 1-2 ��ռλ���� // ��(y)������ 1-4 ��ռλ��������(S)ֻ���� 1 ��ռλ��(�� 1-3 λ������) // ���ӣ� // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //�·� "d+": this.getDate(), //�� "h+": this.getHours(), //Сʱ "m+": this.getMinutes(), //�� "s+": this.getSeconds(), //�� "q+": Math.floor((this.getMonth() + 3) / 3), //���� "S": this.getMilliseconds() //���� }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } //��Ҫ��ѯ��ʱ��ֵ function TagHisValueInfo() { var time = ""; var tagArray = new Array(); } //��ǩ�ṹ function ReportTagHisValueObj() { var tag = ""; var val = 0; } //��Ҫ��ѯ��ͳ����Ϣ function TagStasticSearchInfo() { var startTime; var endTime; var tagArray = new Array(); } //��ǩ�ṹ function ReportTagStasticObj() { var tag = ""; var Min = ""; var Max = ""; var Diff = ""; var Avg = ""; var Total = ""; var CalcTotal = "";//算术求和 } //��ȡ��ʷʱ��ֵ function GetReportTagHisValue(tTime, tagstr) { for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) { var tagInfo = ReportTagHisValueSearchInfoList[i]; if (tagInfo.time.getTime() == tTime.getTime())//ʱ����ͬ { var ttTag = tagInfo.tagArray[tagstr]; if (!ttTag) return ""; return ttTag.val; } } } //��ȡͳ��ֵ function GetTagStasticSearchValue(sTime, eTime, tag, tagType) { for (var i = 0; i < TagStasticSearchInfoList.length; i++) { var tagInfo = TagStasticSearchInfoList[i]; if (tagInfo.startTime.getTime() == sTime.getTime() && tagInfo.endTime.getTime() == eTime.getTime()) { var tempTag = tag; var dayNum = (tagInfo.endTime.getTime() - tagInfo.startTime.getTime()) / 1000 / 24 / 3600;//���� //if((tagInfo.endTime.getTime()-tagInfo.startTime.getTime())/1000/24/3600>0.5&& if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //����2�죬��ȡ��С�����ƽ��ȡͳ��ֵ { tempTag = tempTag.replace(".", "_"); tempTag = "report." + tempTag + "_" + tagType; } else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ { tempTag = tempTag.replace(".", "_"); tempTag = "report." + tempTag + "_diff"; } var ttTag = tagInfo.tagArray[tempTag]; if (!ttTag) return ""; if (ttTag.tag == tempTag) { if (tagType == "min") return ttTag.Min; else if (tagType == "max") return ttTag.Max; else if (tagType == "diff") return ttTag.CalcTotal;//ƽ��ֵ*��������ʾÿ���ֵ�ĺͣ���Ϊ�ܲ�ֵ else if (tagType == "sub") return ttTag.CalcTotal; else if (tagType == "dif") return ttTag.CalcTotal; else return ttTag.Avg; } } } return ""; } //��Ӱ�ʱ��ֵ��ѯ���� function AddToTagHisValueArray(time, tag) { if (!time) return; if (!tag) return; for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) { var tagInfo = ReportTagHisValueSearchInfoList[i]; if (tagInfo.time.getTime() == time.getTime())//ʱ����ͬ { var tagObj = tagInfo.tagArray[tag]; if (!tagObj) { var tagObj = new ReportTagHisValueObj(); tagObj.tag = tag; tagObj.val = 0; tagInfo.tagArray[tag] = tagObj; } return; } } var tempInfo = new TagHisValueInfo(); tempInfo.time = time; tempInfo.tagArray = new Array(); ReportTagHisValueSearchInfoList.push(tempInfo); var tagObj = new ReportTagHisValueObj(); tagObj.tag = tag; tempInfo.tagArray[tag] = tagObj; } //��Ӳ�ѯ��Ϣ ��������ʼʱ�䣬����ʱ�䣬��ǩ�� function AddToTagStasticSearchArray(sTime, eTime, tag) { for (var i = 0; i < TagStasticSearchInfoList.length; i++) { var tagInfo = TagStasticSearchInfoList[i]; if (tagInfo.startTime.getTime() == sTime.getTime() && tagInfo.endTime.getTime() == eTime.getTime()) { var tagObj = tagInfo.tagArray[tag]; if (!tagObj) { var tagObj = new ReportTagStasticObj(); tagObj.tag = tag; tagObj.Min = 0; tagObj.Max = 0; tagObj.Avg = 0; tagObj.Total = 0; tagObj.Diff = 0; tagInfo.tagArray[tag] = tagObj; } return; } } var tempInfo = new TagStasticSearchInfo(); tempInfo.startTime = sTime; tempInfo.endTime = eTime; tempInfo.tagArray = new Array(); TagStasticSearchInfoList.push(tempInfo); var tagObj = new ReportTagStasticObj(); tagObj.tag = tag; tempInfo.tagArray[tag] = tagObj; } //�������й�ʽ����ӵ����Ե��б� function AnalysisAllFunc(funcArray) { if (!funcArray) return; for (var i = 0; i < funcArray.length; i++) { var calcu = funcArray[i]; if (!calcu) continue; if (calcu.funcName == "GetTagHisValue")//ͳ��ʱ��ֵ������ { var parmArray = calcu.parmList; if (!parmArray) continue; if (parmArray.length >= 2) { var tagStr = parmArray[0]; var timeStr = parmArray[1]; var ReportTime = window[timeStr]; if (!ReportTime) continue; var tempTime = new Date(Date.parse(ReportTime)); if (!tempTime) continue; //偏移秒 var addSec=0; if(parmArray.length>=3) { addSec=parseInt(parmArray[2]); tempTime.setSeconds( tempTime.getSeconds()+addSec); } AddToTagHisValueArray(tempTime, tagStr); } } else if (calcu.funcName == "GetTagTimeStasticValue")//ͳ��ʱ���ֵ����,���£����꣬����ʱ��� { var parmArray = calcu.parmList; if (!parmArray) continue; if (parmArray.length >= 4) { var tagStr = parmArray[0]; var timeStr = parmArray[1]; var ReportTimeType = parmArray[2]; var tagType = parmArray[3]; var ReportTime = window[timeStr]; if (!ReportTime) return 0; var tempStartTime = new Date(Date.parse(ReportTime));; var tempEndTime = new Date(Date.parse(ReportTime));; if (ReportTimeType == 'd' || ReportTimeType == 'D') { tempStartTime.setHours(0); tempStartTime.setMinutes(0); tempStartTime.setSeconds(0); tempEndTime.setHours(23); tempEndTime.setMinutes(59); tempEndTime.setSeconds(59); } else if (ReportTimeType == 'm' || ReportTimeType == 'M') { tempStartTime.setDate(1); tempStartTime.setHours(0); tempStartTime.setMinutes(0); tempStartTime.setSeconds(0); tempEndTime.setMonth(tempEndTime.getMonth() + 1); tempEndTime.setDate(0); tempEndTime.setHours(23); tempEndTime.setMinutes(59); tempEndTime.setSeconds(59); } else if (ReportTimeType == 'y' || ReportTimeType == 'Y') { tempStartTime.setMonth(0); tempStartTime.setDate(1); tempStartTime.setHours(0); tempStartTime.setMinutes(0); tempStartTime.setSeconds(0); var year = tempEndTime.getYear(); tempEndTime.setYear(year + 1 + 1900); tempEndTime.setMonth(0); tempEndTime.setDate(0); tempEndTime.setHours(23); tempEndTime.setMinutes(59); tempEndTime.setSeconds(59); } if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //��С�����ƽ��ȡͳ��ֵ { tagStr = tagStr.replace(".", "_"); tagStr = "report." + tagStr + "_" + tagType; AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr); } else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ { tagStr = tagStr.replace(".", "_"); tagStr = "report." + tagStr + "_diff"; AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr); } } } else if (calcu.funcName == "GetTagTimeStasticValue2")//ͳ��ʱ���ֵ���� { var parmArray = calcu.parmList; if (!parmArray) continue; if (parmArray.length >= 4) { var tagStr = parmArray[0]; var startTimeStr = parmArray[1]; var endTimeStr = parmArray[2]; var tagType = parmArray[3]; tagStr = tagStr.replace("\"", ""); startTimeStr = startTimeStr.replace("\"", ""); endTimeStr = endTimeStr.replace("\"", ""); tagType = tagType.replace("\"", ""); tagStr = tagStr.replace("\"", ""); startTimeStr = startTimeStr.replace("\"", ""); endTimeStr = endTimeStr.replace("\"", ""); tagType = tagType.replace("\"", ""); var ReportStartTime = window[startTimeStr]; var ReportEndTime = window[endTimeStr]; var tempStartTime = new Date(Date.parse(ReportStartTime)); var tempEndTime = new Date(Date.parse(ReportEndTime)); //if((tempEndTime.getTime()-tempStartTime.getTime())/1000/24/3600>0.5&& if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //��С�����ƽ��ȡͳ��ֵ { tagStr = tagStr.replace(".", "_"); tagStr = "report." + tagStr + "_" + tagType; AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr); } else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ { tagStr = tagStr.replace(".", "_"); tagStr = "report." + tagStr + "_diff"; AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr); } } } } } //����spread��ʽ function resetSpread(spread) { var sheet = spread.getSheet(0); sheet.options.colHeaderVisible = false; sheet.options.rowHeaderVisible = false; spread.options.newTabVisible = false; spread.options.tabStripVisible = false; spread.options.showHorizontalScrollbar = true; //���ݱ�����������ʾ����������ֻ�ܻ�����β spread.options.scrollbarMaxAlign = true; //spread.options.scrollbarShowMax=true; spread.verticalScrollBarWidth = 10; } //���뱨���json���� function importJSON(spread, jsonData) { if (!spread) return; var start = new Date(); spread.suspendPaint(); //ApplyCustomFunc(spread); ApplyCustomFunc(spread); spread.fromJSON(jsonData); //var json = spread.toJSON(); //spread.fromJSON(json); resetSpread(spread); spread.resumePaint(); //ResetFormular(spread); var useTime = (new Date() - start); console.log("import use time:" + useTime); } //ˢ�±��� function FreshReport(spread, exportFileName, isWhiteBackBlackFont, jsonFuncData) { if (!spread) return; var fStartTime = new Date(); var curSheet = spread.getActiveSheet(); if (!curSheet) return; TagStasticSearchInfoList = new Array();//����б� ReportTagHisValueSearchInfoList = new Array();////����б� ReportAnsnDoneNum = 0; setInterval(function()//����첽����ȫ����ɺ�ִ�з��Զ���ļ��� { if(parseInt(ReportAnsnDoneNum)>=parseInt(ReportAnsnFuncNum))//����ȫ����� { ReportAnsnDoneNum=0; DoNoCustomFunc(spread); } },500); //spread.resumeCalcService();//ˢ�±�����ִ�����к����� //GetAllTag(spread);//�����ѵĽ��������ٶ�,2018-1-27���޸ģ�������ʱ����������õ��ĺ��� //DoCustomNoAnsnFunc(spread); //������ʽ������ AnalysisAllFunc(jsonFuncData); //û��ͳ�Ʋ�ѯʱ if (TagStasticSearchInfoList.length <= 0 && ReportTagHisValueSearchInfoList.length <= 0) { spread.resumeCalcService();//ˢ�±�����ִ�����к����� ResetFormular(spread) spread.repaint(); if (exportFileName) SpreadExport(spread, exportFileName); isExporting = false; return; } //�ܵIJ�ѯ���� var TotalSearchNum = TagStasticSearchInfoList.length + ReportTagHisValueSearchInfoList.length; var ReceiveNum = 0; //��ȡʱ���ͳ��ֵ������ var midTime = new Date(); console.log("analysis func use time:" + (midTime - fStartTime)); for (var i = 0; i < TagStasticSearchInfoList.length; i++) { (function ()//将请求和返回放入一个函数,保证变量对应 { var tagSearch1 = TagStasticSearchInfoList[i]; if (!tagSearch1) return; var ssTime = tagSearch1.startTime; var eeTime = tagSearch1.endTime; var tagStr = ""; for (var key in tagSearch1.tagArray) { tagStr += key + ","; } var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName="; urlStr += tagStr + "&beginTime=" + ssTime.Format("yyyy-MM-dd hh:mm:ss") + "&endTime=" + eeTime.Format("yyyy-MM-dd hh:mm:ss") + "&dataType=snap"; $.ajax({ type: 'GET', url: urlStr, dataType: 'json', cache: true, error: function (data) { console.log("HistorySummary error!"); }, success: function (data) { if (!data) return; for (var key in data) { //console.log("answer:"+key); var tagData = data[key]; if (!tagData) continue; var ttTag = tagSearch1.tagArray[key]; if (!ttTag) continue; if (ttTag.tag == key) { ttTag.Min = GetDital(tagData.Min, 3); ttTag.Max = GetDital(tagData.Max, 3); ttTag.Avg = GetDital(tagData.CalcAvg, 3); ttTag.Diff = GetDital(tagData.Difference, 3); ttTag.Total = GetDital(tagData.Total, 3); ttTag.CalcTotal = GetDital(tagData.CalcTotal, 3); } } ReceiveNum++; if (ReceiveNum >= TotalSearchNum)//ȫ�����غ�ˢ��ҳ������ { spread.resumeCalcService();//ˢ�±�����ִ�����к����� ResetFormular(spread) spread.repaint(); midTime = new Date(); console.log("get data use time:" + (midTime - fStartTime)); console.log("-----------------------------------"); if (exportFileName) SpreadExport(spread, exportFileName, isWhiteBackBlackFont); isExporting = false; } } }); }()); } //��ȡ��ʷʱ��ֵ for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) { (function ()//将请求和返回放入一个函数,保证变量对应 { var tagSearch = ReportTagHisValueSearchInfoList[i]; if (!tagSearch) return; var ssTime = tagSearch.time; var tagStr = ""; for (var keys in tagSearch.tagArray) { tagStr += keys + ","; } var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/History?tagName="; urlStr += tagStr + "&time=" + ssTime.Format("yyyy-MM-dd hh:mm:ss"); $.ajax({ type: 'GET', url: urlStr, dataType: 'json', cache: true, error: function (data) { console.log("HistorySummary error!"); }, success: function (data) { if (!data) return; for (var key in data) { //console.log("answer:"+key); var tagData = data[key]; if (!tagData) return; var ttTag = tagSearch.tagArray[key]; if (!ttTag) return; if (ttTag.tag == key) { ttTag.val = GetDital(tagData.Value, 3); } } ReceiveNum++; if (ReceiveNum >= TotalSearchNum)//ȫ�����غ�ˢ��ҳ������ { spread.resumeCalcService();//ˢ�±�����ִ�����к����� ResetFormular(spread) spread.repaint(); midTime = new Date(); console.log("get data use time:" + (midTime - fStartTime)); console.log("-----------------------------------"); if (exportFileName) SpreadExport(spread, exportFileName, isWhiteBackBlackFont); isExporting = false; } } }); }()); } var doneFreshTime = new Date(); console.log("done fresh report use time:" + (doneFreshTime - fStartTime)); } function SpreadExport(spread, exportFileName, isChangeBackFont) { var fileName = exportFileName + '.xlsx'; if (fileName.substr(-5, 5) !== '.xlsx') { fileName += '.xlsx'; } var json = spread.toJSON(); sheet1 = spread.getActiveSheet(); var spread2 = new GC.Spread.Sheets.Workbook(); spread2.fromJSON(json); var sheet2 = spread2.getActiveSheet(); var array = sheet1.getArray(0, 0, sheet1.getRowCount(), sheet1.getColumnCount(), false); sheet2.clear(0, 0, sheet2.getRowCount(), sheet2.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data); sheet2.setArray(0, 0, array, false); //����ǿ�ư׵׺��� if (parseInt(isChangeBackFont) > 0) { var colNum = sheet2.getColumnCount(); var rowNum = sheet2.getRowCount(); spread2.options.backColor = "#ffffff"; sheet2.options.colHeaderVisible = true; sheet2.options.rowHeaderVisible = true; //spread2.options.grayAreaBackColor="#ffffff"; var rowstyle = new GC.Spread.Sheets.Style(); rowstyle.backColor = 'white'; rowstyle.foreColor = 'black'; rowstyle.borderColor = 'black'; for (var ii = 0; ii < rowNum; ii++) { sheet2.setStyle(ii, -1, rowstyle, GC.Spread.Sheets.SheetArea.viewport); } sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).backColor("white"); sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).setBorder(new GC.Spread.Sheets.LineBorder("#aaaaaa", GC.Spread.Sheets.LineStyle.thin), { all: true }, 1); sheet2.options.gridline = { color: "#aaaaaa", showVerticalGridline: false, showHorizontalGridline: false }; sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).foreColor('black'); } //sheet2.options.gridline = {color:"#000000", showVerticalGridline: true, showHorizontalGridline: true}; ResetFormular(spread2); json = spread2.toJSON(); // here is excel IO API excelIo = new GC.Spread.Excel.IO(); excelIo.save(json, function (blob) { saveAs(blob, fileName); }, function (e) { // process error alert(e.message); }); }