[英]Copy value from specific cell in google spreadsheet to another via button
On the click on a Button I want a function to be triggered that copies the value from Sheet1!A6 to
Sheet2!A6 .
在单击按钮时,我希望触发一个将值从Sheet1!A6复制到
Sheet2!A6的函数。 (see template) !
(请参见模板) ! What do I have to add to this to make it work?
我必须添加什么才能使其正常运行?
function CopyPasteA6() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
sheet.getRange('A6').value
???
}
Thanks for help! 感谢帮助!
try like this, it's probably the simplest way to do it. 尝试这样,这可能是最简单的方法。
function CopyPasteA6() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
sheet1.getRange('A6').copyTo(sheet2.getRange('A6'))
}
then insert a drawing or an image in your sheet and assign the function to this image. 然后在图纸中插入图形或图像,然后将功能分配给该图像。
EDIT following your comment : this script copies to the next sheet if it exist. 在您的评论之后进行编辑:如果存在,此脚本将复制到下一张工作表。 you'll have to put a button on each sheet though.... I'd suggest to use a menu instead that will be acessible from anywhere in the spreadsheet.
但是,您必须在每个工作表上放置一个按钮。...我建议您使用菜单,而该菜单可以在电子表格的任何位置使用。
Note that 'A6' or "A6" are just the same ;-) 请注意,“ A6”或“ A6”是相同的;-)
function CopyPasteA6() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sheetidx = sheet.getIndex()-1 ;
var nextSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[sheetidx+1];
sheet.getRange('A6').copyTo(nextSheet.getRange('A6'))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.