Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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 Sheet脚本将工作表复制到具有值而非公式的新选项卡_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script Google Sheet脚本将工作表复制到具有值而非公式的新选项卡

Google apps script Google Sheet脚本将工作表复制到具有值而非公式的新选项卡,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我目前正在尝试将工作表复制到同一工作簿中的一个新选项卡上,该选项卡工作正常。然而,我似乎无法复制的价值观和格式只和公式不断来与它。我曾尝试使用“{contentsOnly:true}”,但它总是给我各种各样的错误 请问有人能帮忙吗 function onOpen() { var ui = SpreadsheetApp.getUi(); // Or DocumentApp or FormApp. ui.createMenu('SUBMIT') .addItem('SUBMI

我目前正在尝试将工作表复制到同一工作簿中的一个新选项卡上,该选项卡工作正常。然而,我似乎无法复制的价值观和格式只和公式不断来与它。我曾尝试使用“{contentsOnly:true}”,但它总是给我各种各样的错误

请问有人能帮忙吗

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('SUBMIT')
      .addItem('SUBMIT', 'menuItem1')
      .addToUi();
}

function menuItem1() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     moveValuesDown(); 

}
  
function moveValuesDown() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
    ss.getSheetByName('Abandoned Phone Calls')
        .copyTo(ss)
        .setName(Utilities.formatDate(new Date(ss.getSheetByName('Abandoned Phone Calls')
            .getRange(1, 1)
            .getValue()), Session.getScriptTimeZone(), "dd MMM yy" ))

}
我还附上了一份我正在处理的工作表的副本-提前谢谢


不确定您到底尝试了什么,但我在您的电子表格中测试了这一点,它按预期工作:

function moveValuesDown() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source_sheet = ss.getSheetByName('Abandoned Phone Calls')
  var new_sheet =  source_sheet.copyTo(ss).setName(Utilities.formatDate(new Date(source_sheet.getRange(1, 1).getValue()),
                   Session.getScriptTimeZone(), "dd MMM yy" ))
  new_sheet.getDataRange().copyTo(new_sheet.getDataRange(),{contentsOnly:true})

}

在计划再次使用变量时,最好创建变量,而不是将所有变量链接在一起。这可能会造成混乱,但您也可能会多次重复相同的代码。

Fantastitc,感谢您的帮助Marios-工作非常完美!