从驱动器向工作表添加图像 [英] Adding Image to Sheet from Drive
问题描述
我想创建一个保存在G盘中的签名png文件,并将其粘贴到带有菜单项的单元格中.我已将图像设置为公共图像,并尝试使用共享URL,但这在添加= IMAGE或以编程方式执行此操作时不起作用.我已经尝试了来自Internet的各种代码,但迄今为止尚未成功.最后一次尝试列出的代码.
I would like to create a signature png file save in G Drive and have it paste into a cell with a menu item. I have set the image as public and an trying to use the shared URL, but this doesn't work adding =IMAGE or doing this programmatically. I have tried various pieces of code from the interwebs and have not been successful to date. Last attempt at code listed.
function mysig() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var rng = sheet.getRange(34,6);
var url = "https://drive.google.com/file/d/id/view?usp=sharing"
var fetch_img = UrlFetchApp.fetch(url);
var blob = fetch_img.getBlob();
Logger.log(fetch_img.getBlob())
sheet.insertImage(blob, 6, 34);
}
推荐答案
使用Drive App生成Google驱动器映像的Blob.请参考下面的代码.
Use Drive App to generate the blob of the google drive image. Refer the below code.
function insertImage() {
var openSpreadSheet = SpreadsheetApp.openById("spreadSheetID").getSheetByName("Sheet1");
var getImageBlob = DriveApp.getFileById("GooglDriveImageID").getBlob();//0B5JsAY8jN1CoNjlZR2tUUHpISFE
openSpreadSheet.insertImage(getImageBlob,2,2,100,200); //insertImage(blob, column, row, offsetX, offsetY)
}
使用图像公式-匹配单元格大小
function insertImage() {
var openSpreadSheet = SpreadsheetApp.openById("spreadSheetID").getSheetByName("Sheet1");
var url = "https://docs.google.com/uc?export=download&id=0B5JsAY8jN1CoNjlZR2tUUHpISFE";
openSpreadSheet.getRange(5, 3).setFormula('=image("'+url+'",2)')
}
-
= image("URL")–图像保留宽高比,同时增加/减小像元大小
=image("URL") – image retains aspect ratio while increasing / decreasing the cell size
= image("URL",2)–图像拉伸以适合单元格的所有边缘
=image("URL",2) – image stretches to fit all edges of the cell
= image("URL",3)–图片保留其原始大小
=image("URL",3) – image retains its original size
= image("URL",4,50,50)–通过将50,50替换为所需的尺寸来设置图像的大小
=image("URL",4,50,50) – set the size of the image by replacing 50,50 with desired dimensions
这篇关于从驱动器向工作表添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!