I have a Google sheet with a drawing i.e. shape. What script would move the shape to a designated location on the sheet?
Here is a link to an example where I'd like to click on the blue rectangle and have the script move the green rectangle to cover cell A1.
https://drive.google.com/open?id=1eFCwDiY90ZM5SIMa6C0rSdhG_oC-SWgsk8vAvjIR34s
This is my first script in Google and I can't find a way to select the drawing.
I believe your goal as follows.
For this, how about this answer?
At first, please set the function name of myFunction
to "the blue rectangle". By this, when the blue rectangle is clicked, myFunction
is run.
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
. So using this, the green rectangle is retrieved.myFunction
was set. By this, the green rectangle is moved to the cell "A1".