Database Reference
In-Depth Information
To create a Spreadsheet script, you should first open Google Spreadsheets;
then select Script Editor from the tools menu. This creates a new script
that can access your spreadsheet. You get a pop-up asking you what kind
of script to create. Just select Blank Project. You might want to try running
something on your script to verify that it works. Try entering this in your
script:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Set project", functionName:
"setProject"});
ss.addMenu("BigQuery", menuEntries);
}
function setProject() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var value = cell.getValue();
if (value) {
projectId = String(value);
UserProperties.setProperty('PROJECT_ID',
projectId);
Logger.log('Project id set to %s', projectId);
} else {
Logger.log('Project id not set');
}
}
This installs a BigQuery menu when you open your spreadsheet and adds
a Set Project menu item. Save the script, go back to the spreadsheet, and
reload the page in your browser. You should now see a BigQuery menu item.
Enter your project ID in a cell. With it selected, run the Set Project item
from the BigQuery menu. This saves your project ID as a per-user property.
This project ID will be used when talking to BigQuery, so you don't have to
indicate it every time you want to run a query or hard-code it in the script.
After you set your project ID, you can delete it from the spreadsheet—it has
been saved and you won't need to use it again.
Search WWH ::




Custom Search