AppsScript-复制“在选定单元格中放置图像"在Google表格上 [英] AppsScript - Replicate "put image in selected cell" on Google Sheets

查看:95
本文介绍了AppsScript-复制“在选定单元格中放置图像"在Google表格上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在通过AppsScript函数 InsertImage

I am currently inserting multiple images in a Google Sheets via AppsScript function InsertImage

该功能可将图像插入到单元格上方(而不是单元格内). 我可以通过单击三个点按钮,然后选择将图像放入所选单元格",将该图像插入到单元格中.像这样的链接.

With it the function inserts the image but above the cell (not inside the cell). I can insert that image into the cell by clicking the three dots button and then selecting "put image in selected cell" like in this link.

这里的问题是如何将复制的图像放入所选单元格"中.通过AppsScript(或其他编码/脚本方法)进行操作,这样我就可以自动执行此操作.

The question here is how to replicate this "put image in selected cell" behaviour via AppsScript (or other coding/scripting methods) so I can automate this action.

我不能选择使用IMAGE公式,因为该公式不允许我在使用iOS表格应用时看到插入的图像...

It is not an option for me to use the formula IMAGE as that formula doesn't allow me to see the inserted images when using iOS sheets apps...

推荐答案

IssueTracker:

应用程序脚本中目前没有方法可以在单元格中插入图像.有一个打开的此处的功能请求.考虑在其上添加一个星号(在左上角),以便Google优先考虑该问题.

IssueTracker:

There is currently no method in apps script to insert a image in cell. There is a open feature request here. Consider adding a star(on top left) to it for Google to prioritize the issue.

在这里,我们使用=IMAGE()公式插入图像,并仅复制粘贴值以获取原始图像.我在此处 a>,并在issuetracker的评论#65 中.

Here we use =IMAGE() formula to insert a image and copy paste values only to get the raw image. This is mentioned by me here and in comment#65 of the issuetracker.

const insertInCellImage_ = (url, rg) => {
  rg.setValue(`=IMAGE("${url}")`);
  SpreadsheetApp.flush();
  rg.copyTo(rg, { contentsOnly: true });
};

/*Inserts Google logo in Sheet1!A1*/
const test1 = () =>
  insertInCellImage_(
    'https://www.google.com/images/srpr/logo3w.png',
    SpreadsheetApp.getActive()
      .getSheetByName('Sheet1')
      .getRange(1, 1)
  );

这篇关于AppsScript-复制“在选定单元格中放置图像"在Google表格上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆