简体   繁体   English

Google 表格:如何在应用程序脚本中连接字符串?

[英]Google sheets: How do I concat a string in apps script?

How do I concat a value that is being copied over to another sheet?如何连接正在复制到另一个工作表的值?

Sheet 1>> Input Example (column B contains Product Name, and column C contains Color):表 1>> 输入示例(B 列包含产品名称,C 列包含颜色):
Col B |上校 B | Col C上校 C
Shoes |鞋 | Black黑色的

Sheet 2>> Desired Output Example:表 2>> 所需 Output 示例:
Col E (concated values) Col E(连接值)
Shoes - Black鞋子 - 黑色

    function onEdit(e) {
      const sh=e.range.getSheet();
      if(sh.getName()=="Sheet 1" && e.range.columnStart==1 && e.value=="TRUE") {
        const tsh=e.source.getSheetByName('Sheet 2');
        const nr=tsh.getLastRow()+1;

//Concat Shoes with the value below
        sh.getRange(e.range.rowStart,3,1,1).copyTo(tsh.getRange(nr,5,1,1));

     
      }
    }

I believe your goal as follows.我相信你的目标如下。

  • You want to retrieve the values of columns "B" and "C" from the edited row of the column "A" of "Sheet 1", and you want to put the value to the column "E" of "Sheet 2" by merging them.您想从“Sheet 1”的“A”列的编辑行中检索“B”和“C”列的值,并且希望将值放入“Sheet 2”的“E”列合并它们。

In order to achieve this, how about the following modification?为了实现这一点,下面的修改如何?

From:从:

sh.getRange(e.range.rowStart,3,1,1).copyTo(tsh.getRange(nr,5,1,1));

To:至:

const value = sh.getRange(e.range.rowStart, 2, 1, 2).getValues()[0].join(" - ");
tsh.getRange(nr, 5, 1, 1).setValue(value);

References:参考:

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

相关问题 如何通过字符串值选择 Google 表格单元格并在 Google Apps 脚本中将其删除? - How do I select a Google Sheets cell by its string value and delete it in Google Apps Script? 如何将我的应用程序脚本部署到我的谷歌表格中 - How do I deploy my apps script into my google sheets 如何从表格中计算谷歌应用脚​​本中的持续时间? - How do I calculate duration in google apps script from sheets? 如何在我的Google Apps脚本/ Google表格HTML中包含脚本? - How do I include scripts in my Google Apps Script/Google Sheets HTML? 如何使用 Google Apps 脚本将公式添加到 Google 表格? - How do I add formulas to Google Sheets using Google Apps Script? 如何使用Google Apps脚本合并Google表格中的列值 - How do I Merge Column Values in Google Sheets with Google Apps Script 如何使用Google Apps脚本在Google表格中调用函数 - How do I call a function inside Google Sheets using google apps script 如何使用 Google Apps 脚本将 Google 表格单元格中的文本字符串解析为 CSV 文件? - How do I parse text strings in Google Sheets cells to a CSV file with Google Apps Script? 如何以这种格式连接和制作 json - google sheet and js - How do I concat and make json in this format - google sheets and js 您如何在 Google 表格应用程序脚本中强制重新计算公式? - How do you force formula recalculation in Google Sheets apps script?
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM