The code below will complete successfully, but the thumbnails will not be displayed. What's the problem?
function dispThumbnail(){
varsheet=SpreadsheetApp.getActiveSheet();
varfile=DriveApp.getFilesByName("a01.jpg").next();
sheet.getRange(1,1).setValue(file.getThumbnail());
sheet.getRange(1,2).setValue(file.getId());
}
By the way, Google Developers reference Class File getThumbnail() says `Return type=Blob, Brief description says Gets a thumbnail image for the file, or null if no thumbnail exists.
sheet.getRange(1,2).setValue(file.getId());
displays correctly.
google-apps-script
Valid arguments for Range#setValue(value)
are numeric, string, boolean order date
, so return File#getTumbnail(value)
Blob cannot be specified.
Instead, use Spreadsheet#insertImage(blob, column, row)
to
function dispThumbnail(){
varsheet=SpreadsheetApp.getActiveSheet();
varfile=DriveApp.getFilesByName("a01.jpg").next();
sheet.insertImage(file.getThumbnail(), 1,1);
sheet.getRange(1,2).setValue(file.getId());
}
I should be able to write like this, but at this point getThumbnail()
doesn't return Blob.
Issue4344-Google-apps-script-issues-DriveApp file.getThumbnail() always returns null
According to the bug report above, please use Drive Advanced Service for now.
Then, for example, like this.
function myFunction(){
varsheet=SpreadsheetApp.getActiveSheet();
varfile=DriveApp.getFilesByName("a01.png").next();
sheet.insertImage(Drive.Files.get(file.getId()) .thumbnailLink,1,1);
sheet.getRange(1,2).setValue(file.getId());
}
You can specify the URL obtained by thumbnailLink
as =image()
.
© 2024 OneMinuteCode. All rights reserved.