[英]In Google Sheets, how do I get the folder name where the current Spreadsheet is located and write it in a cell? (with AppScript possibly)
[英]How do I make a Google Sheets custom formula that gives the current cell the color of the input cell?
我正在嘗試創建一個公式,為當前單元格提供輸入單元格的顏色。
這是我嘗試過的:
function getCellColor(input) {
return input.getBackground();
}
我知道返回該值將不起作用,即使返回該值也只會返回實際值,而不會執行setBackground方法,但是我真的迷失了這個方向,不知道如何進行。
輸入被解析為值而不是“單元格”對象,但我不知道這樣做的正確方法是什么。
如用戶所述,自定義函數具有局限性,其中包括電子表格[1]中的設置方法。 您可以輕松創建一個菜單,該菜單將運行特定功能,您可以在其中使用所有Apps Script方法。
這是一段將創建菜單[3]的代碼,單擊該鍵時,colorCell()函數將從B5單元格獲取背景色並將其設置為活動單元格:
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.createMenu('Actions')
.addItem('Go to Cell', 'colorCell')
.addToUi();
}
function colorCell() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var cell = SpreadsheetApp.getActiveRange();
var color = sheet.getRange("B5").getBackgroundColor();
//Sets color to the cell
cell.setBackground(color);
}
我留給您SpreadsheetApp文檔[2]。
[1] https://developers.google.com/apps-script/guides/sheets/functions#advanced
[2] https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getactiverange
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.