2016-04-02 16 views
0

İlk kez google apps komut dosyasını denemek. Bu komut dosyasını bir google e-tablosunda bir api anahtarı ile kurdum ve komut dosyasındaki url değişkenine ekledim. Komut dosyası hatasız çalışır, ancak belirli hücrelerde belirli değişkenlerin nasıl görüntüleneceğini anlayamıyorum. Belgelere baktım ama henüz benzer örneklerle karşılaşmadım.google elektronik tablo görüntüleme değerlerini çoklu hücrelerdeki komut dosyasından kullanma

ISBN'leri A sütununda varsa, başlığı görüntülemek için B sütununa ne koyayım?

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"]); 
} 

} 

cevap

0

bu ürün nedir?

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); 
+0

Müthiş Serge, o çalışıyor! Sonunda kodunda küçük bir yazım hatası vardı. Değişkenleri ayarlamak için stevalentleri değiştirdim. – dean2020

+0

oups ... thx ;-) –

+0

Bir sorun olsa da, betikteki örnek isbn numarasını görüntüler, ancak A1'de bir ISBN numaram olduğunda ve A2 hücresine = getBookDetails (A1) koyduğumda, bir hata alıyorum: setValues ​​(satır 32) aramak için izin yok. – dean2020

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); 
} 
} 
İlgili konular