Google表格:如果单元格中包含特定文字,则添加图片或绘图 [英] Google sheets: Add image or drawing if a cell contains specific text

查看:70
本文介绍了Google表格:如果单元格中包含特定文字,则添加图片或绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只想问一下如果单元格中有准确的文字,该如何添加形状或图形(半阴影形状).

Just want to ask if how can I add a shape or drawing (half-shaded shape) if the cell has an exact text.

当我输入字母"t"时是否有可能在单元格中,图像/绘图是否可见?虽然,我认为不能通过公式来完成,因为应该将图像/绘图放置在其上的单元格是字母"t"所在的单元格.应该放置.我有办法通过脚本吗?

Is it possible that when I type the letter "t" in the cell, the image/drawing will be visible? Though, I don't think it can be done through a formula, given that the cell on which the image/drawing should be placed is the cell on which the letter "t" should be placed. Is there a way for me to do it via script?

编辑

在应用 copyTo(目标)的解决方案时,它起作用了.但是,它只能在一个单元上工作.如何在B5:F6或其他单元格上使用它?

As I applied the solution of copyTo(destination), it worked. But, it is only working on one cell. How can I make it work on B5:F6 or other cells?

以下是脚本和示例电子表格.

function onEdit(e) {
  
  var sheet = SpreadsheetApp.getActiveSheet();
  var r  = sheet.getRange("B5").getValues();
  
  if (r == 't'){
    var rangeToCopy = sheet.getRange(5, 9);
    rangeToCopy.copyTo(sheet.getRange(5, 2));
  }
}

推荐答案

为了实现所需的功能,应使用 e 事件对象以检测正在编辑的位置制成.因此,建议您对代码进行以下更改:

In order to achieve what you want, you should make use of the e event object in order to detect where the edit is being made. Therefore, I suggest you make the following changes to your code:

function onEdit(e) {
  let sheet = e.range.getSheet();
  let r = e.range.getValue();
  if (sheet.getName() == "Sheet1" && r == "t") {
    let col = e.range.getColumn();
    let row = e.range.getRow();
    sheet.getRange(5,9).copyTo(sheet.getRange(row,col));
  }
}

说明

上面的脚本检查是否已在 Sheet1 中完成编辑,以及已编辑单元格的值是否为 t .如果此条件得到检查,则使用 getRow getColumn ,它将获取单元格的范围,然后将半阴影形状放置在该范围内.

Explanation

The above script checks if the edit has been done in the Sheet1 and if the value of edited cell is t. If this condition checks, then by using getRow and getColumn, it gets the range of the cell and then later places the half-shaded shape in that range.

Apps脚本onEdit(e).

这篇关于Google表格:如果单元格中包含特定文字,则添加图片或绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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