将 Google 工作表的 2 个特定页面上的选定文本列转换为大写

问题描述 投票:0回答:1

我们有一个共享工作表,我一直在使用此代码的顶部部分自动将用户输入的文本(在选择列中)更改为大写。从历史上看,我只需在工作表的一页上执行此操作。最近我们必须在工作表中添加第二页。非常相似的功能和布局,但它必须存在于新选项卡上。我尝试将代码复制到新工作表,但该代码仅适用于原始页面 (PDI),不适用于新页面 (Premium_PDI)。有没有一种简单的方法可以让这段代码在两张纸上都工作?

谢谢

function onEdit(e) {

   // Forces column not listed below in the notCols variable to update to all CAPS when edited -     The header row is also excluded
  var as = e.source.getActiveSheet(),
      sheet = 'PDI'
      notCols = [1, 8, 9, 14, 16, 17, 19, 20, 21, 28]
   if (as.getName() !== sheet || notCols.indexOf(e.range.columnStart) > -1 || e.range.rowStart <  2)  return;
e.range.setValue(e.value.toUpperCase());


    // Forces column not listed below in the notCols variable to update to all CAPS when edited -    The header row is also excluded
    var as = e.source.getActiveSheet(),
        sheet = 'Premium_PDI'
        notCols = [1, 8, 9, 14, 16, 17, 19, 20, 21, 28]
    if (as.getName() !== sheet || notCols.indexOf(e.range.columnStart) > -1 || e.range.rowStart < 2)  return;
    e.range.setValue(e.value.toUpperCase());

}

我在原始页面上以小写形式输入了内容,但它仍然将其更新为大写形式。在新选项卡上输入小写文本时,没有任何反应。

google-sheets case
1个回答
0
投票

尝试:

function onEdit(e) {
  // Forces column not listed below in the notCols variable to update to all CAPS when edited
  // The header row is also excluded
  var as = e.source.getActiveSheet();
  var sheets = ['PDI', 'Premium_PDI']; // List of sheets to apply the script to
  var notCols = [1, 8, 9, 14, 16, 17, 19, 20, 21, 28];

  if (sheets.indexOf(as.getName()) === -1 || notCols.indexOf(e.range.columnStart) > -1 || e.range.rowStart < 2) {
    return;
  }

  e.range.setValue(e.value.toUpperCase());
}
© www.soinside.com 2019 - 2024. All rights reserved.