首页 > 解决方案 > 服务超时电子表格 - 可能在脚本运行时暂停表格刷新?

问题描述

我有一个 MCC Google Ads 脚本,它针对每个 Google Ads 帐户运行报告并将其放入 Google 电子表格标签中。虽然 Google Ads 脚本运行速度很快,但电子表格服务有 80% 以上的时间会超时。看来问题是由我的电子表格中正在计算的数据透视表/公式驱动的,使广告脚本无法使用电子表格来运行 report.exportToSheet 函数。我可以确认这一点,因为如果我删除所有数据透视表等,脚本就可以完美运行。

我在问是否可以在脚本运行时阻止 Google 工作表计算所有数据透视表/公式,以便它可以导出数据?

function main(){

 // Get the accounts to be processed.
 var accountSelector = AdsManagerApp.accounts()
   .withIds([MY IDs]);

    accountSelector.executeInParallel("processClientAccount");
}

function processClientAccount() {
  var clientAccount = AdsApp.currentAccount();

  // Process your client account here.
  // Generate reports
    generateReports(clientAccount.getName())
}


function generateReports(accountName){


   //Pulls the Report Data
  var report = AdWordsApp.report("SELECT AccountDescriptiveName, CampaignName, Date, HourOfDay, Clicks, Cost FROM CAMPAIGN_PERFORMANCE_REPORT WHERE CampaignName DOES_NOT_CONTAIN_IGNORE_CASE 'BCM' AND Clicks > 0 DURING TODAY");

  //Defines the spreadsheet to put the report data in
 var spreadsheet = SpreadsheetApp.openByUrl('URL');

  //Sets up variable for function to get a specific tab (matching account name) or creating it. 
  var sheet = createOrGetSheet(spreadsheet, accountName, 12);

  //Exports the Report Data To the Google Sheet
  report.exportToSheet(sheet);

}

  //Code for the function to select spreadsheet tab or create a new one

function createOrGetSheet(reportSpreadsheet, name, position) {

 var sheet = reportSpreadsheet.getSheetByName(name);
 if(sheet == null) {
  return reportSpreadsheet.insertSheet(name, position);
 } else {
  return sheet;
 }
}

标签: google-apps-script

解决方案


推荐阅读