简体   繁体   English

如何更改已编辑单元格上方单元格的背景颜色(Javascript,Google Spreadsheets)

[英]How to change the background colour of the cell above the edited cell (Javascript, Google Spreadsheets)

I apologize in advance for this question - it seems so basic but I just can't figure it out myself, or find anything anywhere on the internet that answers my question. 我提前为这个问题道歉 - 这似乎是如此基本但我无法自己解决,或在互联网上找到任何可以回答我问题的地方。

My Background 我的背景

I'm generally used to using excel until very recently, when I moved jobs to a department that uses Google Docs. 直到最近,当我将工作转移到使用Google Docs的部门时,我通常习惯使用excel。 My knowledge of Javascript is very basic, based on the stuff I've come across during the past 4 weeks trying to do some basic code. 我对Javascript的了解非常基础,基于我在过去4周内遇到的尝试编写基本代码的内容。

Background of the sheet I'm working on 我正在研究的工作表背景

We have a large sheet of names with associated info, input onto each row. 我们有一大堆带有相关信息的名称,输入到每一行。 So 1 row = 1 person. 所以1排= 1人。 Each row goes from Column A to Column T. 每行从A列到T列。

My boss would like any historical data kept, very much like a database. 我的老板希望保留任何历史数据,非常像数据库。 I'm aware Spreadsheets isn't the best place for this, but my knowledge of database software is less than that of Javascript. 我知道Spreadsheets不是最好的地方,但我对数据库软件的了解比Javascript少。 What I've managed to do, as a temporary solution, is create an additional column (Column U: Archive) which cuts and pastes the entire row into a sheet named ARCHIVE when 'yes' is input. 作为临时解决方案,我设法做的是创建一个额外的列(列U:存档),当输入“是”时,该列将整行剪切并粘贴到名为ARCHIVE的工作表中。 It also then deletes the empty row left behind, keeping the table nice and tidy. 然后它还会删除留下的空行,保持表格整洁。

See code here (sheet name changed to Sheet 1 for example purposes): 请参阅此处的代码(工作表名称更改为工作表1以用于示例目的):

function onEdit(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

if(s.getName() == "Sheet1" && r.getColumn() == 21 && r.getValue() == "yes") {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("Archive");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }
}

What I would like to do now (and what I need the code for) 我现在想做什么(以及我需要的代码)

My colleagues would like to be able to view the archive sheet and see, at-a-glance, which cell was changed. 我的同事希望能够查看存档表,并一目了然地看到哪个单元格已被更改。 We thought the best and simplest way to do this would be to highlight the cell. 我们认为最好和最简单的方法是突出细胞。

However, before we archive the row, we're having to copy it, insert a line below and paste the copied data. 但是,在我们归档行之前,我们必须复制它,在下面插入一行并粘贴复制的数据。 Then we change whichever cell has incorrect data, before archiving the row with the old data (so we have a record of all data held at any point during the sheet's life). 然后我们在使用旧数据归档行之前更改具有不正确数据的单元格(因此我们记录了在工作表生命期间的任何点保留的所有数据)。 In Column T, before archiving, we're also inputting today's date, so we know when the info was changed. 在T列中,在归档之前,我们还输入了今天的日期,因此我们知道信息何时被更改。

So - I need a code that can change the cell below the one that is being edited (this will contain the old data), but not for columns T or U (so A:S). 所以 - 我需要一个代码,可以更改正在编辑的单元格下面的单元格(这将包含旧数据),但不需要更改列T或U(所以A:S)。

Like I said before, I apologise for what is likely a cack-handed way of doing things and asking a beginner question! 就像我之前说过的那样,我为可能是一种笨拙的做事方式并提出初学者问题而道歉!

Many thanks in advance. 提前谢谢了。

Isn't the revision history that is build in google spreadsheets a better solution to your problem? 在Google电子表格中构建的修订历史记录不是更好的解决方案吗? https://support.google.com/docs/answer/190843?hl=en . https://support.google.com/docs/answer/190843?hl=en

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM