简体   繁体   English

在编辑谷歌表中的一行时,对设置行的数据执行公式,并将公式的结果粘贴到设置行的第一列

[英]On edit of a row in google sheet execute a formula on the data of set row and paste the result of the formula in the first column of set row

I am making a database of items .我正在制作一个项目数据库 As items will be edited by many people I would like formulas to be hidden so people would not manipulate them easily compromising the database.由于项目将被许多人编辑,我希望隐藏公式,这样人们就不会轻易地操纵它们而损害数据库。

I tried to edit a script that recognizes any edit within a row and execute a formula on column values of set row pasting the result of the formula in column A of set row.我试图编辑一个脚本,该脚本识别行内的任何编辑,并在设置行的列值上执行一个公式,将公式的结果粘贴到设置行的 A 列中。

As I am very new to google app script I don't know how to proceed and many examples I have looked through don't do what I want.由于我对谷歌应用脚本非常陌生,我不知道如何继续,而且我浏览过的许多示例都没有达到我想要的效果。

I hope what I have written is clear.我希望我写的很清楚。

Thanks in advance for any help!提前感谢您的帮助!

Here is the code I wrote:这是我写的代码:

function onEdit(e) {
  // Your sheet params
  var sheetName = "Sheet1";
  var ModifiedColumnIndex = 1;
  var ModifiedColumnLetter = 'A';


  var range = e.range; // range just edited
  var sheet = range.getSheet();
  if (sheet.getName() !== sheetName) {
    return;
  }

  // If the column isn't our source column
  if (range.getColumn() != ModifiedColumnIndex) { 
    var row = range.getRow();
  // Formula to be executed on the edited rows cells  
    var formula = sheet + row [lower[trim(B&" "&C&" "&D&" "&E&" "&F&" "&G&" ["&I&"]"]])
    var ModifiedRange = sheet.getRange(ModifiedColumnLetter + row.toString());
  //Inserting formula into column A                               
    ModifiedRange.setValue(formula);
  };
 };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Arrayformula 应用于显示行的最后一个单元格的公式(Google 表格) - Apply Arrayformula to formula that shows the last cell of a row (Google Sheet) 使用Google表格中的数据查询最后一行,并将空单元格设置为“文本” - Query last row with data in Google Sheet and set empty cells to “text” 如何使函数在最后一行执行公式? - How to Make Function Execute Formula on Last Row? 如何使用其他Google工作表设置公式 - How to set formula using a different google sheet 谷歌脚本将数据从工作表 1 复制到第一个空行工作表 2 - google script copy data from sheet 1 to first empty row sheet 2 将单元格复制并粘贴到特定列谷歌表格中的第一个空行 - Copy and Paste a Cell to First Empty Row in Specific Column google sheets 将公式插入具有适当行的单元格(Google 脚本) - Inserting a formula into a cell with the appropriate row (Google Scripts) Google表格公式-适用于每一行的arrayformula - Google sheets formula - arrayformula to apply to each row 谷歌表格复制公式并插入一行 - Google Sheets Copy down formula with inserting a row 如何将最后一行谷歌工作表单元格公式值转换为变量并替换谷歌文档占位符 - How to get last row google sheet cell formula value into variable and replace the google doc place holder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM