English 中文(简体)
使用Google电子表格访问BigQuery
原标题:Accessing BigQuery with Google Spreadsheet

I look on the internet to see how can I import bigquery data inside google spreadsheet. I found this appscript sample, but it doesn twork API are not at the same level, and I do not find how to query with API2 or API@beta1 in appscript.

function runQuery() {
  var ss = SpreadsheetApp.getActive();
  var range = ss.getRangeByName( query );
  var query = range.getCell(1, 1).getValue();
  //var results = bigquery.query(query);



  var header = ss.getRangeByName( header );
  header.clearContent();
  var output = ss.getRangeByName( output );
  output.clearContent();
  for (var i = 0; i < results.fields.length; i++) {
    var field = results.fields[i];
    header.getCell(1, 1 + i).setValue(field.id);
  }
  for (var i = 0; i < results.rows.length; i++) {
    var row = results.rows[i].f;
    for (var j = 0; j < row.length; ++j) {
      output.getCell(1 + i, 1 + j).setValue(row[j].v);
    }
  }
}

提前感谢您的想法,

GQ

问题回答

I dont have the reputation to comment on hurricaneditka16. Therefore, I posted this answer: This line

queryResults = BigQuery.Jobs.query(projectId, sql);

应替换为

.query(
    resource,
    projectId);

资源是对您之前使用的sql的轻微转换。尝试这种转换,它就会奏效。

function getResource(sql) {
  var resource =  {"query": "sql"} 
  resource = resource.replace( sql , sql);
  return resource
}




相关问题
How to use year counter google app script?

I need an urgent help i have data as follows in a google sheet i need to add a year counter to the column d as follows using google apps script

What is the daily email limit in Google Apps Script?

Can someone tell me if there is a webpage that lists the official Google limit (Quotas) on emails sent from a Google Apps Script? In testing my little script I got an error: Service invoked too many ...

Reference Error for property of Javascript Object

I have built an object in Javascript on the Google Apps Script engine and every time I run my script I get a reference error saying uName is not defined. Here is the relivant code: function DataSet()...

Run Google Apps Script on Google-Spreadsheet event?

If I create a Google apps script, can I hook it up to Google spreadsheet to run based on an event, or must I manually invoke it? I don t know if Google Sheets supports any events. For example: a ...

Google gadget/spreadsheet: Grab spreadsheet key for gadget

So I m working on a google gadget(really only gadgetizing so I can get a datastore for this) that I want to be embeddable in a google spreadsheet (after this point, I m going to skip the word google - ...

热门标签