本帖最后由 lin123 于 2018-3-30 11:56 编辑
看过以往的帖子,对照着弄怎么单元格就无法选定?
- window.onload = function() {
- var spread = new GC.Spread.Sheets.Workbook($("#sheet")[0], { sheetCount : 1 });
- var sheet = spread.getActiveSheet();
- //非数字禁止输入
- function NumberCellType() {
- }
- NumberCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
- NumberCellType.prototype.paint = function(ctx, value, x, y, w, h,style, options) {
- if (value) {
- GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, options ]);
- }
- };
- NumberCellType.prototype.updateEditor = function(editorContext, cellStyle, cellRect) {
- if (editorContext) {
- $(editorContext).width(cellRect.width);
- $(editorContext).height(100);
- return { height : 100 };
- }
- };
- NumberCellType.prototype.createEditorElement = function(context) {
- var editor = GC.Spread.Sheets.CellTypes.Base.createEditorElement.call(this, context);
- var textarea = editor.firstChild;
- textarea.onkeypress = function(event) {
- return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46
- }
- textarea.onkeyup = function(event) {
- this.value = this.value.replace(/[\u4e00-\u9fa5]/g, '').replace(/\D/g, '');
- }
- textarea.onpaste = function(event) {
- var clipData = event.clipboardData;
- return !clipData.getData('text').match(/\D/);
- }
- textarea.ondragenter = function(event) {
- return false;
- }
- return editor;
- };
- NumberCellType.prototype.getEditorValue = function(editorContext) {
- if (editorContext) {
- var input1 = editorContext.firstChild;
- var value = $(input1).val();
- return value;
- }
- };
- NumberCellType.prototype.setEditorValue = function(editorContext, value) {
- if (editorContext && value) {
- var input1 = editorContext.firstChild;
- $(input1).val(value);
- }
- };
- NumberCellType.prototype.isReservedKey = function(e) {
- return (e.keyCode === GC.Spread.Commands.Key.tab && !e.ctrlKey&& !e.shiftKey && !e.altKey);
- };
- NumberCellType.prototype.isEditingValueChanged = function(oldValue, newValue) {
- if (newValue != oldValue) {
- return true;
- }
- return false;
- };
- var numberCellType = new NumberCellType();
- sheet.getCell(0,3).value("11");
- sheet.getRange(1,3,5,1).cellType(numberCellType);
- }
复制代码
|
|