本帖最后由 nobt 于 2020-11-9 14:22 编辑
- GC.Spread.Sheets.Designer.wrapper.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasted, function (sender, args) {
- var activeSheet = GC.Spread.Sheets.Designer.wrapper.spread.getActiveSheet();
- var row = args.cellRange.row;
- var col = args.cellRange.col;
- // GC.Spread.Sheets.Designer.wrapper.spread.getActiveSheet().getCell(row, col).formatter("0.00");// 0.00 就是将当前单元格不管你是几位,粘贴后都按两位有效数值填充
- var pasteData = args.pasteData.text;
- var pasteDataArray = pasteData.split("\n");
- for (var i = 0; i < args.cellRange.rowCount; i++) {
- for (var j = 0; j < args.cellRange.colCount; j++) {
- var rowNumArray = pasteDataArray[i];
- var colNumArray = rowNumArray.split("\t");
- var num = colNumArray[j].trim();
- if(!isNaN(num)){
- var x = String(num).indexOf(".") + 1;//得到小数点的位置
- var y = String(num).length - x;//小数点的位数
- var formatterStr = "0.";
- if(x == 0){
- activeSheet.getCell(args.cellRange.row + i, args.cellRange.col + j).formatter("0");
- continue;
- }
-
- if(y > 0) {
- for(var k=0;k<y;k++){
- formatterStr += "0";
- }
- activeSheet.getCell(args.cellRange.row + i, args.cellRange.col + j).formatter(formatterStr);
- continue;
- }
- }
- }
- }
- });
复制代码
这个代码能满足需求了,再加个spreadNS.Events.ActiveSheetChanged的事件,切换sheet页也支持这样复制 |