Insert Image into Spresheet Cell from Drive using

2019-02-20 01:25发布

I would like to be able to add an image file into my spreadsheet from Google Drive. I see there is a built-in image function available =image, but this requires a URL and that your image files are shared publicly on the internet, I am working with digital assets and can not share them publicly.

I have the following code, this works but does not add to the required cell, is this at all possible?

function insertImageFromDrive(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  var fileId = '0B5UAkV0avfiKNGYtd1VzUzlsTVk';
  var img = DriveApp.getFileById(fileId).getBlob();


  sheet.insertImage(img, 4, 3)
}

3条回答
Juvenile、少年°
2楼-- · 2019-02-20 02:03

There is a google spreadsheet add-on ImageKit to help insert multiple images from difference sources including Google Drive, check it out > https://chrome.google.com/webstore/detail/imagekit/cnhkaohfhpcdeomadgjonnahkkfoojoc Here you find a screenshot of tool's interface. imagekitAddon

查看更多
仙女界的扛把子
3楼-- · 2019-02-20 02:09

Try using the guide Insert image in a spreadsheet from App Script:

function insertImageOnSpreadsheet() {
  var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';
  // Name of the specific sheet in the spreadsheet.
  var SHEET_NAME = 'INSERT_SHEET_NAME_HERE';

  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);

  var response = UrlFetchApp.fetch(
      'https://developers.google.com/adwords/scripts/images/reports.png');
  var binaryData = response.getContent();

  // Insert the image in cell A1.
  var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName');
  sheet.insertImage(blob, 1, 1);
}

Just replace the necessary values. The part where you indicate which cell you insert the image is in:

sheet.insertImage(blob, 1, 1);
查看更多
该账号已被封号
4楼-- · 2019-02-20 02:11
登录 后发表回答