var headerCount=2;//头部行高 var nextDataRowIndex;//下条数据所在行 var bgColor1 = 'rgb(210,218,228)'; var bgColor2 = 'rgb(255,242,203)'; var bgColor3 = 'rgb(194,214,155)';//绿的 $(function(){ spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 }); initSpread(); }); function initSpread(){ spread.suspendPaint(); if(dbJson){//数据库 // spread.fromJSON(JSON.parse(dbJson)); spread.fromJSON(dbJson); }else { nextDataRowIndex = headerCount; initData(); } var sheet = spread.getActiveSheet(); var setting = sheet.tag(); if(setting){ if(setting.nextDataRowIndex){ nextDataRowIndex = setting.nextDataRowIndex; } } if(!nextDataRowIndex){ nextDataRowIndex = headerCount; } spread.options.newTabVisible = false;//取消新增sheet按钮 spread.options.allowExtendPasteRange =true;//扩展粘贴区域 bindEvent(spread); addContextMenu(spread); addDataCellMenu(spread) setMenuView(spread); // sheet.frozenRowCount(headRowCount);//冻结头部 // sheet.options.frozenlineColor = 'red';//冻结线颜色 setDefaultLock(sheet); // sheet.selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);//不让多选 spread.bind(GC.Spread.Sheets.Events.RowChanging, function (e, info) { //info.propertyName="deleteRows" //删除行 if(info.propertyName="deleteRows"){ var deleteRow = info.row; var deleteCount = info.count; var sheetTag = sheet.tag(); var ids = sheetTag.ids; for(var i=deleteRow;iheaderCount) nextDataRowIndex--; // delete ids[j]; ids.splice(j,1); } } } addSheetTagValue(sheet,{ids:ids,nextDataRowIndex:nextDataRowIndex}); } }); sheet.frozenRowCount(2); sheet.frozenColumnCount(5); spread.resumePaint(); } function initData() { var jsonHeader ; if(actualStaKind!='main'){ jsonHeader = actual_sta_branch; }else { jsonHeader =actual_sta_main; } spread.fromJSON(jsonHeader); var sheet = spread.getActiveSheet(); if(actualStaKind=='main'){ initMainHeadData(sheet); }else { var budgetTitle ; if(actualStaKind=='labor'){ budgetTitle='人工成本年度预算数'; }else if(actualStaKind=='pu'){ budgetTitle='采购成本年度预算数'; }else if(actualStaKind=='maintain'){ budgetTitle='维保费用年度预算数'; }else if(actualStaKind=='other'){ budgetTitle='其他费用年度预算数'; }else if(actualStaKind=='manage'){ budgetTitle='管理费用年度预算数'; } initBranchHeadData(sheet); if(budgetTitle){ sheet.setValue(0,2,budgetTitle); } } // actual_sta_branch for(var i=0;i0){ setSheetTag(sheet,{fix:true}) $.messager.alert('信息','操作成功'); }else{ $.messager.alert('信息','请选择单元格'); } } function setControlFlag(spread,options){ var sheet = spread.getActiveSheet(); setSelectionTagValue(sheet,'cell',options); } function setSheetTag(sheet,value) { var setting = sheet.tag(); if(!setting){ setting = new SheetSetting(); } $.extend(setting,value); sheet.tag(setting); } function setDataStartIndex(sheet,type,row,col){ } function setReadonly(spread,options){ var sheet = spread.getActiveSheet(); var selections = sheet.getSelections(); var select = selections[0]; var row = select.row; var col = select.col; if(options.readOnly==1){ sheet.getCell(row,col).backColor('grey'); }else { sheet.getCell(row,col).backColor('white'); } setSelectionTagValue(sheet,'cell',options); } function setHeader(sheet,type,objValue){ var o = {}; //inst 会用到 显示行表头 或 列表头 if(type=='row'){ o[_vars.rowHeader]='true'; loopSelection(sheet,function(row,col){ addCellTagValue(sheet,row,-1,{dimValue:objValue}); }); }else if(type=='col'){ o[_vars.colHeader]='true'; loopSelection(sheet,function(row,col){ addCellTagValue(sheet,-1,col,{dimValue:objValue}); }); } setSelectionTagValue(sheet,'cell',o); } function disableBindButton(clearValue){ if(clearValue){ $('#rowTimeInput').val(''); $('#colTimeInput').val(''); $('#rowGoalsInput').val(''); $('#colGoalsInput').val(''); $('#rowEntityInput').val(''); $('#colEntityInput').val(''); $('input[name="includeTaxRow"]').removeAttr('checked'); $('input[name="includeTaxCol"]').removeAttr('checked'); $('input[name="expectRow"]').removeAttr('checked'); $('input[name="expectCol"]').removeAttr('checked'); } /* $('#rowTimeBind').hide(); $('#rowGoalsBind').hide(); $('input[name="includeTaxRow"]').attr('disabled','disabled'); $('input[name="expectRow"]').attr('disabled','disabled'); $('#colTimeBind').hide(); $('#colGoalsBind').hide(); $('input[name="includeTaxCol"]').attr('disabled','disabled'); $('input[name="expectCol"]').attr('disabled','disabled'); */ } function clearBind(sheet,type,row,col){ var cellTag = sheet.getTag(row,col); if(type=='row'){ removeDimValue(sheet,row,-1,cellTag); clearRowBindInput(); }else { removeDimValue(sheet,-1,col,cellTag); clearColBindInput(); } sheet.setTag(row,col,null); } function clearRowBindInput(){ $('#rowTimeInput').val(''); $('#rowGoalsInput').val(''); $('#rowEntityInput').val(''); $('input[name="includeTaxRow"]').removeAttr('checked'); $('input[name="expectRow"]').removeAttr('checked'); } function clearColBindInput(){ $('#colTimeInput').val(''); $('#colGoalsInput').val(''); $('#colEntityInput').val(''); $('input[name="includeTaxCol"]').removeAttr('checked'); $('input[name="expectCol"]').removeAttr('checked'); } function setExpectRow(){ setExpect('row'); } function setExpectCol(){ setExpect('col'); } function setExpect(type){ var sheet = spread.getActiveSheet(); var itemName=''; disableBindButton(); if(type=='row'){ itemName="expectRow" }else { itemName="expectCol" } $('input[name="'+itemName+'"]').removeAttr('disabled'); var expect = $('input[name="'+itemName+'"]:checked').val(); beforeBindDim(sheet,type); setSelectionTagValue(sheet,'cell',{expect:expect}); setSelectionTagValue(sheet,'cell',{bindDirection:type}); setHeader(sheet,type,{expect:expect}); } function dimMatchRow(spread,options){ dimMatch(spread,options,'row') } function dimMatchCol(spread,options){ dimMatch(spread,options,'col') } function dimMatch(spread,options,type) { var sheet = spread.getActiveSheet(); var selections = sheet.getSelections(); var select = selections[0]; var row = select.row; var col = select.col; var rowCount = select.rowCount; var colCount = select.colCount; var params= {}; var totalCol = col + colCount; var c = 0; for(var i=row;i