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 sheets Google应用程序脚本批处理以意外的时间执行_Google Sheets_Script - Fatal编程技术网

Google sheets Google应用程序脚本批处理以意外的时间执行

Google sheets Google应用程序脚本批处理以意外的时间执行,google-sheets,script,Google Sheets,Script,下面的代码生成一张空白表,可能是由于.clear()最后执行,即使它列在第一位 const ss = SpreadsheetApp.getActiveSpreadsheet(); var contractSheet = ss.getSheetByName(sheetName); contractSheet.clear(); const body = {requests: [{pasteData: {html: true, data

下面的代码生成一张空白表,可能是由于.clear()最后执行,即使它列在第一位

        const ss = SpreadsheetApp.getActiveSpreadsheet();
        var contractSheet = ss.getSheetByName(sheetName);
        contractSheet.clear();

        const body = {requests: [{pasteData: {html: true, data: table[0], coordinate: {sheetId: ss.getSheetByName(sheetName).getSheetId()}}}]};
        Sheets.Spreadsheets.batchUpdate(body, ss.getId());
如果删除.clear(),脚本将正常运行并填充工作表。但在加载来自最终批处理请求的新数据之前,我需要清除该表


任何想法都将不胜感激。:-)

在这种情况下,如何在脚本中使用
SpreadsheetApp.flush()
,如下所示?我认为在运行
clear()
之后,需要反映它并请求Sheets API的batchUpdate方法

修改脚本: 参考:

在这种情况下,在脚本中使用
SpreadsheetApp.flush()
怎么样?我认为在运行
clear()
之后,需要反映它并请求Sheets API的batchUpdate方法

修改脚本: 参考:

完美!多谢各位@Tanaike@Kim米勒欢迎。谢谢你让我知道。我很高兴你的问题解决了。如果您的问题已解决,请按“接受”按钮。与您有相同问题的其他人也可以将您的问题作为可以解决的问题。我认为你的问题和解决方案对他们会有帮助。如果你找不到按钮,尽管告诉我。完美的多谢各位@Tanaike@Kim米勒欢迎。谢谢你让我知道。我很高兴你的问题解决了。如果您的问题已解决,请按“接受”按钮。与您有相同问题的其他人也可以将您的问题作为可以解决的问题。我认为你的问题和解决方案对他们会有帮助。如果你找不到按钮,尽管告诉我。
const ss = SpreadsheetApp.getActiveSpreadsheet();
var contractSheet = ss.getSheetByName(sheetName);
contractSheet.clear();

SpreadsheetApp.flush(); // Added

const body = {requests: [{pasteData: {html: true, data: table[0], coordinate: {sheetId: ss.getSheetByName(sheetName).getSheetId()}}}]};
Sheets.Spreadsheets.batchUpdate(body, ss.getId());