我有一个带有图纸(即形状)的Google表格。什么脚本可以将形状移动到图纸上的指定位置?
这里是一个示例的链接,在该示例中,我想单击蓝色矩形,并使脚本将绿色矩形移动到覆盖单元格A1。
https://drive.google.com/open?id=1eFCwDiY90ZM5SIMa6C0rSdhG_oC-SWgsk8vAvjIR34s
这是我在Google中的第一个脚本,我找不到选择图形的方法。
答案 0 :(得分:1)
我相信您的目标如下。
为此,这个答案如何?
首先,请将myFunction
的函数名称设置为“蓝色矩形”。这样,当单击蓝色矩形时,将运行myFunction
。
function myFunction() {
// 1. Retrieve sheet.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
// 2. Retrieve "the green rectangle".
const drawing = sheet.getDrawings().filter(e => e.getOnAction() != "myFunction")[0];
// 3. Move "the green rectangle".
drawing.setPosition(1, 1, 0, 0);
}
myFunction
。因此,使用它可以检索绿色矩形。myFunction
的蓝色矩形。这样,绿色矩形将移动到单元格“ A1”。