谷歌电子表格显示多个单元格中脚本的值

时间:2016-04-02 21:50:48

标签: javascript google-apps-script google-sheets

首次尝试谷歌应用脚​​本。我在google电子表格中使用api密钥设置了此脚本,并将其添加到脚本中的url变量中。该脚本运行没有错误,但我无法弄清楚如何在单个单元格中显示特定变量。我看过文档,但还没有看到类似的例子。

如果我在A栏中有ISBN,我会在B栏中放置什么来显示标题?

function getBookDetails(isbn) {

// Query the book database by ISBN code.
isbn = isbn || "9781451648546"; // Steve Jobs book 

var url = "https://www.googleapis.com/books/v1/volumes?key=myAPI&q=isbn:" + isbn;

var response = UrlFetchApp.fetch(url);
var results = JSON.parse(response);

if (results.totalItems) {

// There'll be only 1 book per ISBN
var book = results.items[0];

var title = (book["volumeInfo"]["title"]);
var subtitle = (book["volumeInfo"]["subtitle"]);
var authors = (book["volumeInfo"]["authors"]);
var printType = (book["volumeInfo"]["printType"]);
var pageCount = (book["volumeInfo"]["pageCount"]);
var publisher = (book["volumeInfo"]["publisher"]);
var publishedDate = (book["volumeInfo"]["publishedDate"]);
var webReaderLink = (book["accessInfo"]["webReaderLink"]);
 }

}

2 个答案:

答案 0 :(得分:0)

这就是你要找的东西吗?

virtual_mailbox_domains

答案 1 :(得分:0)

function getBookDetails(isbn) {

// Query the book database by ISBN code.

if (isbn !== "") { 

var url = "https://www.googleapis.com/books/v1/volumes?key=AIzaSyAsTRXP0Eqy0Q4mQ1A00xQWYVzcgHyBKiM&q=isbn:" + isbn;

var response = UrlFetchApp.fetch(url);
var results = JSON.parse(response);

if (results.totalItems) {

// There'll be only 1 book per ISBN
var book = results.items[0];

var title = (book["volumeInfo"]["title"]);
var subtitle = (book["volumeInfo"]["subtitle"]);
var authors = (book["volumeInfo"]["authors"]);
var printType = (book["volumeInfo"]["printType"]);
var pageCount = (book["volumeInfo"]["pageCount"]);
var publisher = (book["volumeInfo"]["publisher"]);
var publishedDate = (book["volumeInfo"]["publishedDate"]);
var webReaderLink = (book["accessInfo"]["webReaderLink"]);

// For debugging
Logger.log(book);

}
var resultRow = [[title,authors]];


return resultRow;

// var sh = SpreadsheetApp.getActiveSheet();
// sh.getRange(sh.getLastRow()+1,1,resultRow.length,resultRow[0].length).setValues(resultRow);  
 }
}