I'm trying to automate a result from query in a google sheets. To do that I'm using a script from Ido Green that he posted on your blog. It works perfectly, but I need to extend his powers, since I need to be able to read a cell and use the value as an argument on my query. The cell value will be a value on where condition. I tried some solutions, but since I'm not an expert on Apps Script, didn't work. A fragment of Ido's script:
var sheet = SpreadsheetApp.getActiveSheet();
var sql = 'select TOP(word, 30), COUNT(*) as word_count from publicdata:samples.shakespeare WHERE LENGTH(word) > 10;';
var queryResults;
// Inserts a Query Job
try {
var queryRequest = BigQuery.newQueryRequest();
queryRequest.setQuery(sql).setTimeoutMs(100000);
queryResults = BigQuery.Jobs.query(queryRequest, projectNumber);
}
catch (err) {
Logger.log(err);
Browser.msgBox(err);
return;
}
Like this for example you can control the minimum length of the word by changing Sheet1!C1
var limit = SpreadsheetApp
.getActiveSpreadsheet()
.getSheetByName("Sheet1")
.getRange("C1")
.getValue();
var sql = 'select TOP(word, 30), COUNT(*) as word_count from publicdata:samples.shakespeare WHERE LENGTH(word) > ' + limit + ';';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.