您好,编辑状态时的粘贴属于单元格的编辑操作,不属于粘贴操作所以ClipboardPasting无法监听,您可以使用自定义单元格来完成功能,像这样
$(document).ready(function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var sheet = spread.getActiveSheet();
sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, function (sender, args) {
args.cancel = true;
});
function NumberCellType(){
}
NumberCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
NumberCellType.prototype.createEditorElement = function(context) {
var editor = GC.Spread.Sheets.CellTypes.Text.prototype.createEditorElement.call(this, context);
//Creates a DOM element then returns it.
//var textarea = editor.firstElementChild;
editor.onpaste = function(event){
var clipData = event.clipboardData ;
if(clipData.getData('text')=="123"){
return false;
}
return clipData.getData('text');
}
return editor;
}
sheet.setCellType(0,0, new NumberCellType());
}); |