Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 将单个工作表复制到Google Drive中的多个工作簿_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 将单个工作表复制到Google Drive中的多个工作簿

Google apps script 将单个工作表复制到Google Drive中的多个工作簿,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我正在尝试将一个工作表复制到Google Drive中的多个工作簿中。就在一个多月前,这段代码运行良好,但现在不行了,因为我认为代码中的DocsList命令已经被Google弃用(请参阅)。我听说新命令是DriveApp,但我不太确定。当我写代码的时候,我是一个完全的新手,所以我希望有人能修复这个代码 function onOpen(){ var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries =

我正在尝试将一个工作表复制到Google Drive中的多个工作簿中。就在一个多月前,这段代码运行良好,但现在不行了,因为我认为代码中的DocsList命令已经被Google弃用(请参阅)。我听说新命令是DriveApp,但我不太确定。当我写代码的时候,我是一个完全的新手,所以我希望有人能修复这个代码

function onOpen(){
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [];
  menuEntries.push({name: "Copy Active Sheet to Other Spreadsheets", functionName: "doGet"});
  spreadsheet.addMenu("Copy Sheet", menuEntries);
}

function doGet()
{
  var app = UiApp.createApplication();
  app.setTitle("Kishan - Copy Sheet in Multiple Spreadsheets");

  var form = app.createFormPanel();
  var flow = app.createFlowPanel();

  var label = app.createLabel("Select Spreadsheet where you want to copy the current sheet:").setId('selectLabel');
  flow.add(label);
  var allfiles =  DocsList.getAllFiles();

  var verticalPanel = app.createVerticalPanel().setId('verticalPanel');

  for(var i=0;i<allfiles.length;i++)
  {
    var temp = app.createCheckBox(allfiles[i].getName()).setName('cb'+i).setId('cb'+i);
    var tempvalue = app.createHidden('cbvalue'+i, allfiles[i].getId());
    verticalPanel.add(temp);
    verticalPanel.add(tempvalue);
  }

  var scrollPanel = app.createScrollPanel().setId('scrollPanel');
  scrollPanel.add(verticalPanel);
  scrollPanel.setSize("400", "250")
  flow.add(scrollPanel);

  var buttonsubmit = app.createSubmitButton("Copy");
  flow.add(buttonsubmit);

  form.add(flow);
  app.add(form);

  SpreadsheetApp.getActiveSpreadsheet().show(app);
}

function doPost(eventInfo) {
  var app = UiApp.getActiveApplication();
  var allfiles =  DocsList.getAllFiles();
  var tempSsId = "";

  for(var i=0;i<allfiles.length;i++)
  {
    var temp = eventInfo.parameter['cb'+i];
    if(temp == 'on')
    {
      tempSsId = eventInfo.parameter['cbvalue'+i];
      var activeSheet = SpreadsheetApp.getActiveSheet().copyTo(SpreadsheetApp.openById(tempSsId));
      activeSheet.setName(SpreadsheetApp.getActiveSheet().getSheetName());
    }
  }

  var label = app.createLabel('statusLabel');
  label.setText("Copied Active sheet in all selected Spreadsheets...");
  label.setVisible(true);
  app.add(label);
  return app;
}
函数onOpen(){ var电子表格=SpreadsheetApp.getActiveSpreadsheet(); var指数=[]; push({name:“将活动工作表复制到其他电子表格”,functionName:“doGet”}); 电子表格。添加菜单(“复印表”,菜单); } 函数doGet() { var app=UiApp.createApplication(); app.setTitle(“Kishan-多份电子表格中的副本”); var form=app.createFormPanel(); var flow=app.createFlowPanel(); var label=app.createLabel(“选择要复制当前工作表的电子表格:”).setId(“选择标签”); 添加(标签); var allfiles=DocsList.getAllFiles(); var verticalPanel=app.createVerticalPanel().setId('verticalPanel'); 对于(var i=0;我以前对我很好,但现在不行。有人能帮我吗?

试试这个

function doGet()
{
  var app = UiApp.createApplication();
  app.setTitle("Kishan - Copy Sheet in Multiple Spreadsheets");

  var form = app.createFormPanel();
  var flow = app.createFlowPanel();

  var label = app.createLabel("Select Spreadsheet where you want to copy the current sheet:").setId('selectLabel');
  flow.add(label);
  var allfiles =  DriveApp.getFiles();

  var verticalPanel = app.createVerticalPanel().setId('verticalPanel');
  var i = 0;
  while (allfiles.hasNext())
  {
    var file = allfiles.next();
    var temp = app.createCheckBox(file.getName()).setName('cb'+i).setId('cb'+i);
    var tempvalue = app.createHidden('cbvalue'+i, file.getId());
    verticalPanel.add(temp);
    verticalPanel.add(tempvalue);
    i++;
  }

  var scrollPanel = app.createScrollPanel().setId('scrollPanel');
  scrollPanel.add(verticalPanel);
  scrollPanel.setSize("400", "250")
  flow.add(scrollPanel);

  var buttonsubmit = app.createSubmitButton("Copy");
  flow.add(buttonsubmit);

  form.add(flow);
  app.add(form);

  SpreadsheetApp.getActiveSpreadsheet().show(app);
}

function doPost(eventInfo) {
  var app = UiApp.getActiveApplication();
  var allfiles =  DriveApp.getFiles();
  var tempSsId = "";

  var i = 0;
  while (allfiles.hasNext())
  {
    var temp = eventInfo.parameter['cb'+i];
    if(temp == 'on')
    {
      tempSsId = eventInfo.parameter['cbvalue'+i];
      var activeSheet = SpreadsheetApp.getActiveSheet().copyTo(SpreadsheetApp.openById(tempSsId));
      activeSheet.setName(SpreadsheetApp.getActiveSheet().getSheetName());
    }
    i++;
  }

  var label = app.createLabel('statusLabel');
  label.setText("Copied Active sheet in all selected Spreadsheets...");
  label.setVisible(true);
  app.add(label);
  return app;
}