Google电子表格内容清晰

时间:2014-01-22 22:56:09

标签: google-apps-script google-sheets

我第一次尝试使用电子表格函数来清除带有函数的范围,但现在我不太确定它是如何工作的。

我的功能如下:

function clearsheet() {
    var mineralsgas = SpreadsheetApp.getActive().getSheetByName('Minerals/Gas');
    mineralsgas.getRange('E6:E13').clearContent();
}

但是我得到了一个Parse Error。 现在我想我应该把功能放在不在单元格中的某个地方并创建一个按钮来设置它?

1 个答案:

答案 0 :(得分:2)

您的代码很好......根据我在您的问题中的理解,我猜您的问题是“如何在电子表格中调用该函数?”

不能当然会像单元格中的自定义函数那样使用该函数。

您有两种可能:菜单和按钮。

菜单在下面的documentation along with code examples中进行了解释

// The onOpen function is executed automatically every time a Spreadsheet is loaded
 function onOpen() {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var menuEntries = [];
   // When the user clicks on "addMenuExample" then "Menu Entry 1", the function function1 is
   // executed.
   menuEntries.push({name: "Menu Entry 1", functionName: "function1"});
   menuEntries.push(null); // line separator
   menuEntries.push({name: "Menu Entry 2", functionName: "function2"});

   ss.addMenu("addMenuExample", menuEntries);
 }

或者您可以绘制按钮(或插入图像)并将功能分配给它。它只是简化了电子表格界面(无法以编程方式为绘图分配函数),如下图所示:

enter image description hereenter image description here

请注意,新版电子表格中尚未提供此功能。

相关问题