谷歌电子表格在多个单元格中显示脚本中的值
google spreadsheet display values from script in multiple cells
第一次尝试谷歌应用程序脚本。我用谷歌电子表格中的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"]);
}
}
这就是您想要的吗?
var resultRow = [[isbn,title,subtitle,authors,printType,pageCount,publisher,publishedDate,webReaderLink]];
var sh = SpreadsheetApp.getActiveSheet();
sh.getRange(sh.getLastRow()+1,1,resultRow.length,resultRow[0].length).setValues(resultRow);
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);
}
}
相关文章:
- 不显示带有本地json文件数据的谷歌地图脚本
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- 显示时间的脚本
- 使用服务器端includes检查当前页面是否为主页——如果是,则显示脚本标记
- 谷歌电子表格在多个单元格中显示脚本中的值
- 有没有一个简单的脚本可以向美国/加拿大游客显示脚本1,向其他游客显示脚本2
- JavaScript var 分配一个动态可为空的值显示脚本错误
- 在电子邮件中显示<脚本>标记
- 如何使用 jQuery 将变量从隐藏字段发送到远程 PHP 文件,并在引导模式中显示脚本的结果,而无需刷新
- 重复显示脚本 UI 窗口
- Dreamweaver在PHP文件中显示脚本标签附近的红线
- jQuery显示脚本errorObject预期
- ie8.0显示脚本错误
- 修改显示脚本,使其隐藏子关卡
- 没有显示脚本输出
- Chrome用户代理不显示脚本- CSS修复
- 使用jQueryAjax成功显示脚本
- 在父级顶部显示脚本
- 如何在 HTML 中显示脚本标记而不执行它