【问题标题】:Different text color for each collaborator每个协作者的不同文本颜色
【发布时间】:2015-02-04 15:14:49
【问题描述】:

在工作中,我们使用 Google 电子表格进行相互交流。每个人都有自己的文本颜色,允许他们在文档中工作。

但是每个人都忘记自定义文本颜色。由于每次我们想在 Google Spreadsheeds 中工作时选择文本颜色并不方便,因此我们的想法是使用 Google Script Editor 自动执行此操作。

function setFontColor(range, fontc) {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheets()[0];
   var cell = sheet.getRange(range);
   cell.setFontColor(fontc);
 }

function onEdit() {

  var email = Session.getActiveUser().getEmail();

  if (email == "user1@company.com"){
    setFontColor(".getActiveCell()", "#FF8800");
  }

  if (email == "user2@company.com"){
    setFontColor(".getActiveCell()", "#0099CC");
  }

  if (email == "user3@company.com"){
    setFontColor(".getActiveCell()", "#9933CC");
  }

  if (email == "user4@company.com"){
    setFontColor(".getActiveCell()", "#CC0000");
  }

}

我想出了这个脚本,因为我找不到其他任何东西。不幸的是,这不起作用。有人可以帮我让它工作或给我一个现有脚本的链接吗?

这对我很有帮助!可能还有很多其他人。

【问题讨论】:

  • 你调用的 setFontcolor() 是什么样的?

标签: google-apps-script google-sheets collaboration textcolor


【解决方案1】:

您提供的代码中有一些语法错误。尝试改变这种方式并运行代码:

function onOpen() {

  var email = Session.getActiveUser().getEmail();

  if (email == "user1@company.com"){
    setFontcolor("#FF8800");
  }

  if (email == "user2@company.com"){
    setFontcolor("#0099CC");
  }
}

您还必须获取要更改颜色的值范围,然后使用 setFontcolor() 方法。您可以参考此页面了解更多信息:https://developers.google.com/apps-script/reference/spreadsheet/range#setFontColor(String) 希望对您有所帮助!

【讨论】:

  • 我已经更改了原始代码,但它不起作用。我确实调用了 onEdit,然后它应该得到 activecell。
【解决方案2】:

我找到了解决方案,并希望将其分享给任何认为它会有所帮助的人!

  function onEdit() {

  var ActiveSheet = SpreadsheetApp.getActiveSheet();
  var ActiveRow = ActiveSheet.getActiveRange().getRow();
  var ActiveCell = ActiveSheet.getActiveCell();
  var email = Session.getActiveUser().getEmail();

  if (email == "user1@company.com"){
    ActiveCell.setFontColor("#FF8800");
  }

  if (email == "user2@company.com"){
    ActiveCell.setFontColor("#0099CC");
  }

  if (email == "user3@company.com"){
    ActiveCell.setFontColor("#9933CC");
  }

  if (email == "user4@company.com"){
    ActiveCell.setFontColor("#CC0000");
  }
}

【讨论】:

  • onEdit id 确实是一个更好的主意,因为我看不到任何方法可以更改“当前会话”的 fontColor 的全局属性。不错的小程序;)
猜你喜欢
  • 1970-01-01
  • 2021-01-02
  • 2015-08-22
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多