Reputation: 165
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.
Upvotes: 0
Views: 652
Reputation: 73
This is how I did in my sheet and it worked; there may be a better way but at least this is easy to implement:
function placeDrawing(row, col, offsetY, offsetX){
var ss = SpreadsheetApp.getActive().getSheetByName("sheetName");
var drawings = ss.getDrawings(); //This returns an array of all drawings in the sheet
drawings[0].setPosition(row, col, offsetY, offsetX);//for each drawing set the wanted position
}
Of course, you will need some testing to guess the exact index (mine were 0 and 1 of 8 drawings), or you can do a for to iterate them.
Upvotes: 0
Reputation: 201388
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".Upvotes: 1