![](/img/trans.png)
[英]How do I populate Google Form questions using column A data from different Google Sheets Tabs using Apps Script?
[英]Using Google Sheets, how do I run a script every hour and populate each cell in a column?
我正在使用Google表格,但從未在這里運行過“ cron作業”。 為了給您應得的榮譽,我找到了這個很棒的代碼,以幫助我在此處訪問Speed Insights API: https : //statsravingmad.com/measure/page-speed-insights/
function speed(url,device,filter_third_party_resources,http_secure) {
url = url || 'www.statsravingmad.com';
strategy = 'desktop' || device;
filter_third_party_resources = 'true' || filter_third_party_resources;
http_secure = 'false' || http_secure ;
switch (http_secure) {
case 'false':
http_protocol = 'http://';
break;
case 'true':
http_protocol = 'https://';
break;
}
var key = 'api-key';
var api = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=' + http_protocol + url
+ '&filter_third_party_resources=' + filter_third_party_resources +
'&strategy=' + strategy + '&key=' + key;
var response = UrlFetchApp.fetch(api, {muteHttpExceptions: true });
var result = JSON.parse(response.getContentText());
score = result.ruleGroups.SPEED.score;
return(score);
}
因此,我將這個代碼的功能設為每小時針對我的Google工作表中的特定測試網站觸發一次。
但是,每個位置的數據僅填充一個單元格,即公式指定的單元格。
使用Google表格時,如何修改它以便使其每小時填充一列中的新單元格? 是否修改此代碼,是否必須設置其他功能,或者是否可以選擇將單元格填充到列中?
可以修改此函數以將其寫入Sheet1的C列。 這是結束的方式,而不是return(score)
(如果將值直接寫入電子表格,則無需返回任何內容;該函數不會從電子表格中調用,而是從觸發器調用)。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var values = sheet.getRange("C:C").getValues(); // using column C
var lastRow = 1;
for (var i = 0; i < values.length; i++) {
if (values[i][0] != "") {
lastRow = i + 1;
}
}
sheet.getRange(lastRow + 1, 3).setValue(score); // column = 3 because C
在這里,循環在C列中找到了包含數據的最后一行,並將score
的值置於其下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.