参考:https://www.cnblogs.com/yeyuqian/p/10750441.html
核心代码:
//例子:复制第一行(10列) 复制到 第二行
var fromRanges = new GC.Spread.Sheets.Range(0, 0, 1, 10); var pastedRange = new GC.Spread.Sheets.Range(1, 0, 1, 10); spread.commandManager().execute({ cmd: "clipboardPaste", sheetName: activeSheet.name(), fromSheet: activeSheet, fromRanges: [fromRanges], pastedRanges: [pastedRange], isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all });
粘贴时候的配置项:
粘贴所有:GC.Spread.Sheets.ClipboardPasteOptions.all
粘贴样式(不粘贴值哦):GC.Spread.Sheets.ClipboardPasteOptions.formatting
全部代码:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <meta charset="utf-8" /> <!-- css --> <link href="js/gc.spread.sheets.excel2013white.11.0.0.css" rel="stylesheet" /> <!-- js --> <script src="js/jquery-1.8.2.min.js"></script> <!-- 核心文件 --> <script src="js/gc.spread.sheets.all.11.0.0.min.js"></script> <!-- 图表 --> <script src="js/gc.spread.sheets.charts.11.0.0.min.js"></script> <!-- excel的导入导出 --> <script src="js/gc.spread.excelio.11.1.0.min.js"></script> <!-- 打印 --> <script src="js/gc.spread.sheets.print.11.0.0.min.js"></script> <!-- 文件保存 正式文件不能引用,测试demo可以引用 因为没有key吧 --> <script src="js/FileSaver.js"></script> <script type="text/javascript"> window.onload = function () { // 获得Spread 对象 var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 3 }); // 获得当前激活的标签页 var activeSheet = spread.getActiveSheet(); for (var i = 0; i < 10; i++) { activeSheet.getCell(0, i).value(i).font("12pt 宋体").backColor("#00ff00");; } //合并单元格 并 设置样式 activeSheet.addSpan(0, 0, 1, 2, GC.Spread.Sheets.SheetArea.viewport); activeSheet.getRange(0, 0, 1, 2).backColor("#ffff00"); //粘贴项 //console.log(GC.Spread.Sheets.CopyToOptions); console.log(GC.Spread.Sheets.ClipboardPasteOptions); setTimeout(function () { //例子:把 第一行(10列) 复制到 第二行 var fromRanges = new GC.Spread.Sheets.Range(0, 0, 1, 10); var pastedRange = new GC.Spread.Sheets.Range(1, 0, 1, 10); spread.commandManager().execute({ cmd: "clipboardPaste", sheetName: activeSheet.name(), fromSheet: activeSheet, fromRanges: [fromRanges], pastedRanges: [pastedRange], isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.formatting }); console.log('copy ok'); }, 1000); }; </script> </head> <body> <div id="ss" style="100%; height:500px"></div> </body> </html>