下面的示例脚本将获取youtube缩略图并将其显示在表格单元格中。我们如何确保单元宽度/高度适合图像宽度/高度?当前脚本会将图像缩小到单元格,因此它太小了。
我尝试调用autoResizeColumn API,但它似乎不适用于图像。
function searchYoutubeByKeyword() {
var results = YouTube.Search.list('id,snippet', {
q:'Cpp',
order:'date',
maxResults: 20
});
var lr = 1;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("Sheet1");
for (var i = 0; i < results.items.length; i++) {
var item = results.items[i];
Logger.log('[%s] Title: %s', item.id.videoId,item.snippet.publishedAt);
var url = 'http://www.youtube.com/watch?v='+item.id.videoId;
var desc = item.id.videoId;
var link = '=HYPERLINK'+'("' + url+'","'+ desc +'")';
sheet1.getRange(lr, 1).setValue(link);
sheet1.getRange(lr, 2).setValue(item.snippet.publishedAt.substring(0,10));
sheet1.getRange(lr, 3).setValue(item.snippet.title);
var thumbnail = item.snippet.thumbnails["medium"].url;
sheet1.getRange(lr, 4).setValue('=image("'+thumbnail+'")');
lr++;
}
sheet1.getRange(1,1,sheet1.getLastRow(),3).setNumberFormat('@STRING@');
sheet1.autoResizeColumn(4);
}