//var columnCount = sheet.getColumnCount(); //var rowCount = sheet.getRowCount(); //sheet.deleteRows(1,1); 删除行 //var menuData = spread.contextMenu.menuData; //workArea :工作区域,“复制”操作的可用区域为viewport + colHeader + rowHeader + slicer + corner。 $(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); } spread.options.newTabVisible = false;//取消新增sheet按钮 spread.options.allowExtendPasteRange =true;//扩展粘贴区域 bindEvent(spread); var sheet = spread.getActiveSheet(); var setting = sheet.tag(); addContextMenu(spread); addDataCellMenu(spread) setMenuView(spread); // sheet.frozenRowCount(headRowCount);//冻结头部 // sheet.options.frozenlineColor = 'red';//冻结线颜色 setDefaultLock(sheet); // sheet.selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);//不让多选 spread.resumePaint(); } function bindEvent(spread){ bindCheckNum(spread); spread.bind(GC.Spread.Sheets.Events.EnterCell, function (event, data) {//点击cell事件 var row = data.row; var col = data.col; var sheet = data.sheet; var cellTag = sheet.getTag(row,col); disableBindButton(true); if(readOnly=='false') { $('#rowInfo').show(); $('#colInfo').show(); $('#info3').show(); $('#info2').hide(); if(cellTag) { var bindDirection=cellTag.bindDirection; if(bindDirection){//表头 if(bindDirection=='row'){ $('#rowTimeInput').val(cellTag.periodDetailName); if(cellTag.measureName) { $('#rowGoalsInput').val(cellTag.customCode + " " + cellTag.measureName); } $('input[name="includeTaxRow"][value=' + cellTag.includeTax + ']').attr('checked', 'checked'); $('input[name="expectRow"][value=' + cellTag.expect + ']').attr('checked', 'checked'); }else if(bindDirection=='col'){ $('#colTimeInput').val(cellTag.periodDetailName); if(cellTag.measureName){ $('#colGoalsInput').val(cellTag.customCode+" "+cellTag.measureName); } $('input[name="includeTaxCol"][value=' + cellTag.includeTax + ']').attr('checked', 'checked'); $('input[name="expectCol"][value=' + cellTag.expect + ']').attr('checked', 'checked'); } }else {//非表头 showCellBindInfo(sheet,row,col); } } }else if(readOnly=='true'){ showCellBindInfo(sheet,row,col); } //单元格属性 if(cellTag){ var datatype =cellTag.datatype; var datatypeValue= measureDataTypeList[datatype]; if(!datatypeValue) datatypeValue=''; $('#goalsDataType').html(datatypeValue); if(cellTag.readOnly==1){ $('#readOnly').html('是'); }else { $('#readOnly').html('否'); } var showFuntionTxt = $('#showFuntionTxt'); if(cellTag.functionId){ showFuntionTxt.show(); showFuntionTxt.find('span').html(cellTag.functionTxt); }else{ showFuntionTxt.hide(); } var controlFlagNameDiv = $('#controlFlagName'); if(cellTag.controlFlagName){ controlFlagNameDiv.show(); controlFlagNameDiv.find('span').html(cellTag.controlFlagName); }else { controlFlagNameDiv.hide(); } }else { $('#readOnly').html(''); $('#showFuntionTxt').hide(); } // sheet.startEdit(false); //单击修改 }); /* spread.bind(GC.Spread.Sheets.Events.ButtonClicked, function (e, args) {//点击按钮事件 var sheet = args.sheet, row = args.row, col = args.col; var cellType = sheet.getCellType(row, col); });*/ spread.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) { // console.log(info) if(info.sheetArea === GC.Spread.Sheets.SheetArea.viewport){ var sheet =info.sheet; var row = info.row; var col = info.col; if(info.propertyName=='value'){//值变化 } if(info.propertyName=='formula'){//公式 if(info.newValue==null){ sheet.getCell(row,col).backColor('white'); }else{ sheet.getCell(row,col).backColor('yellow'); } } } }); // alert("Cell index (" + info.row + "," + info.col + ")"); } function setDefaultLock(sheet){ var option = { allowSelectLockedCells:true, allowSelectUnlockedCells:true, allowFilter: true, allowSort: false, allowResizeRows: true, allowResizeColumns: true, allowEditObjects: false, allowDragInsertRows: false, allowDragInsertColumns: false, allowInsertRows: true, allowInsertColumns: true, allowDeleteRows: true, allowDeleteColumns: true }; sheet.options.protectionOptions = option; sheet.options.isProtected = true; var defaultStyle = sheet.getDefaultStyle() //默认的样式, defaultStyle.locked=false; sheet.setDefaultStyle(defaultStyle); } function addContextMenu(){ for(var i=0;i< spread.contextMenu.menuData.length;i++){ var menu = spread.contextMenu.menuData[i]; var menuName=menu.name; if(menuName=='gc.spread.filter' || menuName=='gc.spread.sort' ){//去掉过滤、排序 delete spread.contextMenu.menuData[i]; } } // command: showLoginDialog, } //固定后 右键菜单 function addDataCellMenu(spread){ var sheet=spread.getActiveSheet(); /*var controlFlag ={text: '预算控制方案',name: 'controlFlag',workArea: 'viewport',dataCellMenu:1}; controlFlag.subMenu=[]; if(budgetControlArray.length>0) { spread.contextMenu.menuData.push(controlFlag); 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){ var o = {}; //inst 会用到 显示行表头 或 列表头 if(type=='row'){ o[_vars.rowHeader]='true'; }else if(type=='col'){ o[_vars.colHeader]='true'; } setSelectionTagValue(sheet,'cell',o); } function disableBindButton(clearValue){ if(clearValue){ $('#rowTimeInput').val(''); $('#colTimeInput').val(''); $('#rowGoalsInput').val(''); $('#colGoalsInput').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){ if(type=='row'){ clearRowBindInput(); }else { clearColBindInput(); } sheet.setTag(row,col,{}); } function clearRowBindInput(){ $('#rowTimeInput').val(''); $('#rowGoalsInput').val(''); $('input[name="includeTaxRow"]').removeAttr('checked'); $('input[name="expectRow"]').removeAttr('checked'); } function clearColBindInput(){ $('#colTimeInput').val(''); $('#colGoalsInput').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); } 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