var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
//var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));//获取spread对象 //spread.options.tabStripVisible = false;//是否显示表单栏 //spread.options.tabNavigationVisible = false;//是否显示导航栏 //spread.options.newTabVisible = false;//是否显示新增按钮 //spread.options.scrollbarMaxAlign = true;//是否对齐表单最后的行列 //spread.options.allowUserResize = false;//是否可调整列和行的大小 //spread.options.allowSheetReorder = false;//是否可拖拽排序 //spread.options.allowUserDragMeerge = true;//是否可拖拽合并单元格 //spread.options.tabEditable = false;//是否可双击编辑 //spread.options.allowCellOverflow = true;//是否允许单元格溢出 //spread.options.allowUserZoom = false;//是否在按住Ctrl键的同时滚动鼠标滚轮来缩放显示 ////拖动滚动条给出提示 //spread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;//竖直 ////背景色 //spread.options.backColor = '#a079e8';//所有单元格 //spread.options.grayAreaBackColor = 'red';//灰色部分 //spread.options.backgroundImage = '地址';//所有单元格 ////复制粘贴 //spread.options.allowCopyPasteExcelStyle = true;//允许粘贴样式 //spread.options.allowExtendPasteRange = true;//允许扩展粘贴区域 //spread.options.copyPasteHeaderOptions = 0;//粘贴(0:不含表头/ 1:仅含行头/ 2:仅含列头/ 3:含行头列头) //spread.suspendEvent();//停止监听 //spread.resumeEvent();//恢复监听 //spread.refresh()//???
var sheet = spread.getSheet(0);
//var sheet = spread.getActiveSheet();//获取活动表单 //新增表单 //var nsheet = new GC.Spread.Sheets.Worksheet('新表单'); //spread.addSheet(0, nsheet); //sheet.suspendPaint();//停止绘制 //sheet.resumePaint();//恢复绘制 //sheet.options.sheetTabColor = 'red';//设置标签颜色 //sheet.options.rowHeaderVisible = false;//是否显示行头 //sheet.options.colHeaderVisible = false;//是否显示列头 //sheet.options.gridline.showHorizontalGridline = true;//是否显示横向网格线 //sheet.options.gridline.showVerticalGridline = false;//是否显示竖向网格线 //sheet.options.gridline = { color: "#FF2235", showVerticalGridline: false, showHorizontalGridline: true };//设置网格线 //sheet.options.frozenlineColor = 'red';//设置冻结线颜色 //列头设置 //var spreadNS = GC.Spread.Sheets;//列头(colHeader)/行头(rowHeader)/单元格(viewport) //sheet.setRowCount(3, spreadNS.SheetArea.colHeader);//3行列头 //sheet.addSpan(0, 0, 3, 3, spreadNS.SheetArea.colHeader);//第1行第1列,合并1行3列(合并列头) //sheet.setValue(0, 0, '值', spreadNS.SheetArea.colHeader);//赋值 //sheet.setArray(0, 0, [['1', '2'], ['3', '4']]);//赋值 //sheet.copyTo(0, 0, 2, 2, 1, 1, spreadNS.CopyToOptions.all);//从第1行1列开始,给到第3行3列开始,复制1行1列 //sheet.getArray(0, 0, 2, 2);//获取值 //sheet.setRowCount(10, spreadNS.SheetArea.viewport);//行 //sheet.setColumnCount(20, spreadNS.SheetArea.viewport);//列 //sheet.addRows(0, 1);//从第0行开始,增加1行 //sheet.deleteRows(0, 1);//删除行 //是否允许用户调整列和行的大小 //sheet.setColumnResizable(0, false);//单列 //sheet.setRowResizable(0, false);//单行 //sheet.setRowVisible(0, false);//隐藏行 //sheet.setRowHeight(0, 20);//设置行高 //sheet.getRowHeight(0);//获取行高 //sheet.autoFitColumn(0);//自适应列宽 //sheet.frozenRowCount(1);//固定行 //sheet.frozenColumnCount(1);//固定列 //尾部 //sheet.frozenTrailingRowCount(1);//固定行 //sheet.frozenTrailingColumnCount(1);//固定列 //合并单元格 //sheet.addSpan(1, 1, 3, 3);//第2行第2列,合并3行3列 //单元格赋值 //sheet.setValue(1, 1, '值'); //sheet.getCell(1, 1).value('值'); //sheet.defaults.rowHeight = 40;//行高40 //活动表单改变事件 //var aa = GC.Spread.Sheets.Events.ActiveSheetChanged; //spread.bind(aa, function (sender, args) { // sogModal.openAlertDialog("提示", "1111"); // //args.cancel = true;//事件取消 //}); //SelectionChanging//选中内容正在改变 //SelectionChanged//选中内容改变 //CellClick//单元格被点击 //EditStarting//开始编辑 //EditEnded//结束编辑
//公式应用 //sheet.setFormula(3, 3, '=SUM(A1,B1)'); //字体样式.font('样式 大小 字体'); //sheet.getCell(0, 0) //.font('bold 15px normal')//加粗 //.font('italic 15px normal');//倾斜 //.textDecoration(GC.Spread.Sheets.textDecorationType.underline);//下划线(underline)/双下划线(doubleUnderline)/中划线(lineThrough)/上划线(overline) //.vAlign(GC.Spread.Sheets.VerticalAlign.top)//竖直对齐 //.hAlign(GC.Spread.Sheets.HorizontalAlign.left)//水平对齐 //.foreColor('red')//字体颜色 //.backColor('red')//背景颜色 //.wordWrap(true)//换行 //.textIndent(2)//缩进 //.shrinkToFit(true)//字号自动匹配 //.watermark('请输入姓名:');//标签 //.cellPadding('1,1,1,1')//内边距 //.labelOptions({ // foreColor: '', // margin: '' //}); //初始化样式通用 //var style = GC.Spread.Sheets.Style(); //style.foreColor = ''; //style.backColor = ''; //style.isVerticalText = 'true';//竖直显示 //sheet.setStyle(0, 0, style, GC.Spread.Sheets.SheetArea.viewport);//视图区域 //sheet.setStyle(0, 0, style, GC.Spread.Sheets.SheetArea.colHeader);//列头区域 //sheet.setRowHeight(0, 100);//行高 //sheet.setColumnnWidth(0, 100);//列宽 //最小选择 //sheet.selectionUnit(0);//单元格 //sheet.selectionUnit(1);//行 //sheet.selectionUnit(2);//列 //可选择 //sheet.selectionPolicy(0);//单元格 //sheet.selectionPolicy(1);//区域 //sheet.selectionPolicy(2);//多区域(Ctrl) //快捷键 //var comm = spread.commandManager();//命令管理器 ////按'W'键向上 //comm.register( // 'customNavigationUp',//行为名称 // GC.Spread.Sheets.Commands.navigationUp,//行为 // 'W'.charCodeAt(0),//对应按键 // false, // false, // false, // false //);//name, command, key, ctrl, shift, alt, meta(windows) //表单保护 //var option = { // allowSelectLockedCells: false,//选择被锁定单元格 // allowSelectUnlockedCells: true,//选择未被锁定单元格 // allowFilter: false,//排序 // allowSort: false,//过滤 // allowResizeRows: false,//调整行高 // allowResizeColumns: false,//调整列宽 // allowEditObjects: false,//编辑对象 // allowDragInsertRows: false, // allowDragInsertColumns: false, // allowInsertRows: false, // allowInsertColumns: false, // allowDeleteRows: false, // allowDeleteColumns: false //}; //var option = { // allowInsertRows: false, // allowInsertColumns: false, // allowDeleteRows: false, // allowDeleteColumns: false //}; //sheet.options.protectionOptions = option; //sheet.options.isProtected = true;//表单保护 //表单保护下,某些单元格可编辑 //sheet.getRange(1, 2, 1, 2, GC.Spread.Sheets.SheetArea.viewport).locked(false); //表单保护下,所有单元格可编辑 //var def = sheet.getDefaultStyle(GC.Spread.Sheets.SheetArea.viewport);//获取默认样式 //def.locked = false; //sheet.setDefaultStyle(def, GC.Spread.Sheets.SheetArea.viewport); //分组列 //var data = [ // { name: '001', level: 1 }, // { name: '002', level: 1 }, // { name: '003', level: 2 }, // { name: '004', level: 2 }, // { name: '005', level: 2 }, //]; //for (var i = 0; i < data.length; i++) { // sheet.getCell(i, 0).textIndent(data[i].level);//缩进 //} //sheet.outlineColumn.options({ // columnIndex: 0, // showImage: false, // showCheckBox: true, // maxLevel: 3 //}); //sheet.setDataSource(data); //sheet.setColumnCount(1); //sheet.setColumnWidth(0, 500);
//自定义函数 //function calcuArea() { // this.name = 'area';//函数名称 // this.maxArgs = 2;//最大参数量 // this.minArgs = 2;//最小参数量 //} //calcuArea.prototype = new GC.Spread.CalcEngine.Functions.Function();//继承 //calcuArea.prototype.evaluate = function (arg1, arg2) {//重写 // if (arguments.length == 2 && !isNaN(parseInt(arg1)) && !isNaN(parseInt(arg2))) { // return (arg1 * arg2) / 2; // } // return "#value"; //}; //var area = new calcuArea();//初始化 //sheet.addCustomFunction(area);//添加自定义函数 //sheet.setArrayFormula(0, 2, 3, 1, '=(A1:A3*B1:B3)/2');//区域使用函数 //sheet.removeCustomFunction('area');//删除 //sheet.clearCustomFunction();//清空
////数据绑定 //sheet.setDataSource($scope.viewModel.spreadJSModel);//数据源绑定//表单绑定//自动生成绑定列 ////自定义格式 //function CustomNumberFormat() { }; //CustomNumberFormat.prototype = new GC.Spread.Formatter.FormatterBase();//继承 //CustomNumberFormat.prototype.format = function (obj, formattedData) {//重新 // if (obj == 1) { // return "男"; // } // if (obj == 2) { // return "女"; // } // return ""; //}; //var data2 = [ // { name: 'name', displayName: '姓名', size: 100, visible: true }, // { name: 'age', displayName: '年龄', size: 50 }, // { name: 'sex', displayName: '性别', formatter: new CustomNumberFormat(), size: 50 }, // { name: 'date', displayName: '日期', formatter: 'yyyy-MM-dd', size: 130 }, // { name: 'isShow', displayName: '是否显示', cellType: new GC.Spread.Sheets.CellTypes.CheckBox(), size: 100 } //]; //sheet.bindColumns(data2); ////添加/删除行 //sheet.autoGenerateColumns = true;//自动生成列 //$scope.AddRow = function () { // var rowCount = sheet.getRowCount(); // sheet.addRows(rowCount, 1); // var dataSource = sheet.getDataSource(); // dataSource[rowCount] = {}; // sheet.repaint();//重新绘制表单 //} //$scope.DelRow = function () { // var rowCount = sheet.getRowCount(); // for (var i = rowCount - 1; i >= 0; i--) { // if ($scope.viewModel.spreadJSModel[i].isShow == true) { // sheet.deleteRows(i, 1); // } // } // sheet.repaint();//重新绘制表单 //} //var data = $scope.viewModel.spreadJSModel; //var source = new GC.Spread.Sheets.Bindings.CellBindingSource(data[0]);//表单绑定和单元格绑定的,需要重新包装 //sheet.setBindingPath(0, 0, 'name'); //sheet.setDataSource(source); //表格绑定 //var table = sheet.tables.add('myTable', 1, 1, 5, 6); //var data = { // name: 'Jones', rgion: '西北地区', sales: [ // { 时间: '2022/7/1', 项目: '项目1', 数量: 1, 话费: 1.99 }, // { 时间: '2022/7/2', 项目: '项目2', 数量: 2, 话费: 2.99 }, // { 时间: '2022/7/3', 项目: '项目3', 数量: 3, 话费: 3.99 } // ] //}; //table.bindingPath('sales'); //var source = new GC.Spread.Sheets.Bindings.CellBindingSource(data); //sheet.setDataSource(source); //var _aa = { // ignoreFormula: false,//忽略公式(否) // ignoreStyle: false,//忽略样式 // rowHeadersAsFrozenColumns: false,//行头作为冻结列 // columnHeadersAsFrozenRows: false,//列头作为冻结行 // includeBindingSource: true//***setDataSource绑定数据时 //}; //var jsonStr = JSON.stringify(spread.toJSON(_aa));//转JSON //var _bb = { // ignoreFormula: false, // ignoreStyle: false, // frozenColumnsAsRowHeaders: false, // frozenRowsAsColumnHeaders: false, // doNotRecalculateAfterLoad: false//不重新计算公式(否) //}; //var newSpread = new GC.Spread.Sheets.Workbook(document.getElementById('sss'), { sheetCount: 1 }); //newSpread.fromJSON(JSON.parse(jsonStr), _bb); //绑定数据源 //var examdata = [{ '': '', '': '' }], //var nsheet = new GC.Spread.Sheets.Worksheet('新表单'); //nsheet.setDataSource(examdata); //spread.addSheet(0, nsheet); //var _aa = { // includeBindingSource: true//*** //}; //var jsonStr = JSON.stringify(spread.toJSON(_aa));//转JSON //newSpread.fromJSON(JSON.parse(jsonStr));
1 //sheet.getSelections();//获取选中的区域 2 //sheet.getInsertRows();//获取插入行 3 //sheet.getDeletedRows();//获取删除行 4 //sheet.clearPendingChanges()//清除脏数据 5 6 ////以下操作默认清除脏数据 7 //setRowCout() / setColumnCount() 8 //fromJSON() 9 //setDataSource() 10 11 //获取单元格脏数据 12 //var cells = sheet.getDirtyCells()//参数:行,列,行数,列数 13 //cells.map(function (item) { 14 // return item.row;//item.col//item.oldValue//item.newValue 15 //}).join('\n'); 16 17 ////获取整行脏数据 18 //var rows = sheet.getDirtyRows(); 19 //rows.map(function (item) { 20 // return item.row; 21 //}).join(',');
//自定义格式 //创建一个基于FormatterBase的类 //function CustomNumberFormat() { }; //CustomNumberFormat.prototype = new GC.Spread.Formatter.FormatterBase(); ////重新方法(值, 颜色) //CustomNumberFormat.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; //}; //function formatNumber(obj, formattedData) { // if (isFinite(obj) && formattedData) {//有限数据 // formattedData.conditionalForeColor = 'red'; // } // return obj.toString(); //} ////绑定 //var data = [ // { name: '', displayName: '', formatter: new CustomNumberFormat() } //]; //sheet.bindColumns(data);
//单元格类型 ////button按钮 //var spreadNS = GC.Spread.Sheets; //var btn = new spreadNS.CellTypes.Button();//创建单元格类型对象(按钮) //btn.text('添加'); //btn.marginLeft(0); //btn.buttonBackColor('red'); //sheet.setCellType(0, 0, btn, spreadNS.SheetArea.viewport);//将单元格类型设置到单元格上 //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); // if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) { // alert("Button Clicked"); // } //}); ////checkbox复选框 //var check = new spreadNS.CellTypes.CheckBox(); //check.isThreeState(true);//是否为3种状态(不确定/选中/未选中) //check.textTrue('');//选中时显示文本 //check.textFalse('');//未选中时显示文本 //check.textIndeterminate('');//不确定时显示文本 //check.textAlign(spreadNS.CellTypes.CheckBoxTextAlign.right);//文本位置 //sheet.setCellType(0, 0, check, spreadNS.SheetArea.viewport); ////单选框 //var radio = new GC.Spread.Sheets.CellTypes.RadioButtonList(); //radio.items([ // { text: "sample1", value: "1" }, // { text: "sample2", value: "2" }, // { text: "sample3", value: "3" }, //]); //sheet.setCellType(3, 2, radio, GC.Spread.Sheets.SheetArea.viewport); ////复选列表 //var c = new GC.Spread.Sheets.CellTypes.CheckBoxList(); //c.items([{ text: "a", value: 1 }, { text: "b", value: 2 }, { text: "c", value: 3 }]); //sheet.setCellType(3, 2, c, GC.Spread.Sheets.SheetArea.viewport); ////按钮列表 //var cellType = new GC.Spread.Sheets.CellTypes.ButtonList(); //cellType.items([{ text: "a", value: 1 }, { text: "b", value: 2 }, { text: "c", value: 3 }]); //activeSheet.getCell(2, 2).cellType(cellType); ////日期框 //var style = new GC.Spread.Sheets.Style(); //style.cellButtons = [ // { // imageType: GC.Spread.Sheets.ButtonImageType.dropdown, // command: "openDateTimePicker", // useButtonStyle: true, // } //]; //style.dropDowns = [ // { // type: GC.Spread.Sheets.DropDownType.dateTimePicker, // option: { // showTime: true, // } // } //]; //sheet.setStyle(2, 5, style); ////combobox下拉框 //var combo = new spreadNS.CellTypes.ComboBox(); //combo.items([ // { text: '显示值1', value: '1' }, // { text: '显示值2', value: '2' }, // { text: '显示值3', value: '3' }, //]); //combo.editorValueType(spreadNS.CellTypes.EditorValueType.text);//text/value/index//显示选中数据 //combo.editable(true).editorValueType(spreadNS.CellTypes.EditorValueType.text);//是否可编辑 //combo.itemHeight(20);//下拉选项高度 //sheet.getCell(0, 0, spreadNS.SheetArea.viewport).cellType(combo).value('显示值1');//设置单元格类型//赋默认值 ////超链接 //var hl = new spreadNS.CellTypes.HyperLink(); //hl.text('链接');//显示文本 //hl.linkToolTip('111');//鼠标悬浮显示文本 //hl.linkColor('red');//默认颜色 //hl.visitedLinkColor('blue');//点击后的颜色 //sheet.setCellType(0, 0, hl, spreadNS.SheetArea.viewport)//设置单元格类型 //sheet.getCell(0, 0, spreadNS.SheetArea.viewport).value("");//添加链接 ////回调超链接 //hl.activeOnClick(true);//点击后, 当前单元格是否为活动单元格 //hl.onClickAction(function () {//回调方法 // spread.commandManager().execute({ cmd: 'aa' });//命令 //}) ////自定义命令 //spread.commandManager().register('aa', { // canUndo: true, // execute: function (context,options,isUndo) { // sheet.name('111');//改表单名称 // sheet.options.sheetTabColor = 'red';//改表单颜色 // } //}, null, false, false, false, false); //var source = [ // { money: -100000, person: { firstName: '张展博', lastName: 'zhangzhanb' } }, // { money: -5000, person: { firstName: '崔海波', lastName: 'cuihaib' } }, // { money: 0, person: { firstName: '付登峰', lastName: 'fudf' } }, // { money: 0.05, person: { firstName: '刘肖肖', lastName: 'liuxiaoxiao' } }, // { money: 10000, person: { firstName: '王瑶', lastName: 'wangyao6' } } //]; //sheet.setDataSource(source); ////自定义单元格类型 //function FullNameCellType() { }; //FullNameCellType.prototype = new spreadNS.CellTypes.Base();//继承 //FullNameCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {//重写 // if (value) { // spreadNS.CellTypes.Base.prototype.paint.apply(this, [ctx, value.firstName + "." + value.lastName, x, y, w, h, style, options]); // } //}; //FullNameCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {//修改编辑器,定义宽高 // if (editorContext) { // editorContext.style.width = cellRect.width; // editorContext.style.height = 100; // return { height: 100 }; // } //}; //FullNameCellType.prototype.createEditorElement = function () {//创建div // var div = document.createElement("div"); // div.setAttribute("gcUIElement", "gcEditingInput"); // div.style.backgroundColor = "white"; // div.style.overflow = "hidden"; // var span1 = document.createElement("span"); // span1.style.display = "block"; // var span2 = document.createElement("span"); // span2.style.display = "block"; // var input1 = document.createElement("input"); // var input2 = document.createElement("input"); // var type = document.createAttribute("type"); // type.nodeValue = "text"; // var clonedType = type.cloneNode(true); // input1.setAttributeNode(type); // input2.setAttributeNode(clonedType); // div.appendChild(span1); // div.appendChild(input1); // div.appendChild(span2); // div.appendChild(input2); // return div; //} //FullNameCellType.prototype.getEditorValue = function (editorContext) {//参数是返回的div // if (editorContext && editorContext.children.length === 4) { // var input1 = editorContext.children[1]; // var firstName = input1.value; // var input2 = editorContext.children[3]; // var lastName = input2.value; // return { firstName: firstName, lastName: lastName }; // } //}; //FullNameCellType.prototype.setEditorValue = function (editorContext, value) { // if (editorContext && editorContext.children.length === 4) { // var span1 = editorContext.children[0]; // span1.innerHTML = "First Name:"; // var span2 = editorContext.children[2]; // span2.innerHTML = "Last Name:"; // if (value) { // var input1 = editorContext.children[1]; // input1.value = value.firstName; // var input2 = editorContext.children[3]; // input2.value = value.lastName; // } // } //}; //FullNameCellType.prototype.isReservedKey = function (e) {//释放快捷键tab // return (e.keyCode === GC.Spread.Commands.key.tab && !e.ctrlKey && !e.shiftKey); //} //FullNameCellType.prototype.isEditingValueChanged = function (oldValue, newValue) { // if (newValue.firstName != oldValue.firstName || newValue.lastName != oldValue.lastName) { // return true; // } // return false; //} //var columnInfo = [ // { name: 'person', displayName: '姓名', cellType: new FullNameCellType(), size: 170 }, // { name: 'money', displayName: '金额', formatter: '_(¥* #,##0.00_)', size: 170 } //]; //sheet.bindColumns(columnInfo); ////排序 //function SortHyperlinkCellType() { // spreadNS.CellTypes.HyperLink.apply(this); // this.text("排序"); //}; //SortHyperlinkCellType.prototype = new spreadNS.CellTypes.HyperLink();//继承 超链接 ////获取包含碰撞信息的对象(处理鼠标事件,提供信息) //SortHyperlinkCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) { // if (context) { // return { // x: x, // y: y, // row: context.row, // col: context.col, // cellRect: cellRect, // cellStyle: cellStyle, // sheetArea: context.sheetArea, // isReservedLocation: true, // sheet: context.sheet // }; // } // return null; //} //SortHyperlinkCellType.prototype.processMouseUp = function (hitInfo) {//监听鼠标抬起事件 // var sheet = hitInfo.sheet; // var sheetArea = hitInfo.sheetArea; // var row = hitInfo.row; // var col = hitInfo.col; // var tag = !(sheet.getTag(row, col, sheetArea) || false); // sheet.setTag(row, col, tag, sheetArea);//标记 是否点击 // sheet.sortRange(0, 0, sheet.getRowCount(), sheet.getColumnCount(), true, [ //排序 // { // index: col, // ascending: tag // } // ]); //}; //sheet.setCellType(0, 1, new SortHyperlinkCellType(), spreadNS.SheetArea.colHeader);