请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

luozhu1986

初级会员

21

主题

73

帖子

451

积分

初级会员

积分
451

活字格认证

luozhu1986
初级会员   /  发表于:2014-8-15 17:43  /   查看:5213  /  回复:2
在工作表中新增一行,想把上一行单元格中的数据类型、样式、公式等信息复制到新增单元格中,请问该怎么做

2 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-8-18 13:45:00
沙发
回复 1楼luozhu1986的帖子

添加行代码:

  1. $(document).ready(function () {
  2.     $("#ss").wijspread();

  3.     //Create a data table manually.
  4.     var sampleTable = [
  5.         {"ID":10, "Text":"Text-10", "Check":true},
  6.         {"ID":20, "Text":"Text-20", "Check":false},
  7.         {"ID":30, "Text":"Text-30", "Check":false},
  8.         {"ID":40, "Text":"Text-40", "Check":true},
  9.         {"ID":50, "Text":"Text-50", "Check":true}
  10.     ];

  11.     //Bind the data table
  12.     $("#ss").wijspread("spread").getActiveSheet().setDataSource(sampleTable);

  13.     $("#button1").click(function(){
  14.         console.log("The number of all rows in the datasource before addition:" + sampleTable.length);

  15.         var activeSheet = $("#ss").wijspread("spread").getActiveSheet();
  16.         var row = activeSheet.getRowCount();

  17.         //Add rows after the last row
  18.         activeSheet.addRows(row, 1);

  19.         //Set data.
  20.         activeSheet.setValue(row, 0, 100);
  21.         activeSheet.setValue(row, 1, "Text-New");
  22.         activeSheet.setValue(row, 2, true);
  23.         activeSheet.getRow(row).backColor("pink");

  24.         //Data table has been updated.
  25.         console.log("The number of all rows in the datasource after addition:" + sampleTable.length);
  26.         console.log("The value of the Text field in the last row of the datasource: " + sampleTable[sampleTable.length - 1].Text);
  27.     });
  28. });
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-8-18 17:00:00
板凳
回复 1楼luozhu1986的帖子

复制格式方法可以参考:


  1.             $("#button1").click(function () {
  2.                 console.log("The number of all rows in the datasource before addition:" + sampleTable.length);

  3.                 var activeSheet = $("#ss").wijspread("spread").getActiveSheet();
  4.                 var row = activeSheet.getRowCount();

  5.                 activeSheet.addRows(row, 1);

  6.                 activeSheet.setValue(row, 0, 100);
  7.                 activeSheet.setValue(row, 1, "Text-New");
  8.                 activeSheet.setValue(row, 2, true);

  9.                 activeSheet.clipBoardOptions($.wijmo.wijspread.ClipboardPasteOptions.Formatting);

  10.                 //获取行列数
  11.                 var columnCount = activeSheet.getColumnCount();
  12.                 var rowCount = activeSheet.getRowCount();

  13.                 //清除选择
  14.                 activeSheet.clearSelection();
  15.                 //添加选择
  16.                 activeSheet.addSelection(rowCount - 2, 0, 1, columnCount);
  17.                 //设置样式
  18.                 activeSheet.getRow(rowCount - 2).backColor("pink");
  19.                 //添加公式
  20.                 activeSheet.getCell(rowCount - 2, 2).formula("=SUM(A1:B1)");
  21.                 //添加样式


  22.                 //复制
  23.                $.wijmo.wijspread.SpreadActions.copy.call(activeSheet);

  24.                // //再次升级
  25.                activeSheet.clearSelection();
  26.                activeSheet.addSelection(rowCount-1, 0, 1, columnCount);
  27.                $.wijmo.wijspread.SpreadActions.paste.call(activeSheet);
  28.                activeSheet.repaint();
  29.             });
复制代码


如果希望复制公式需要设置以下方法在重新复制:

  1. activeSheet.clipBoardOptions($.wijmo.wijspread.ClipboardPasteOptions.Formulas);
复制代码


或者您直接把样式设置在 Column 上,在添加行时样式会自动添加,这时只复制公式即可。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部