谷歌表应用程序脚本截断列值 [英] google sheet apps script truncate column value

查看:37
本文介绍了谷歌表应用程序脚本截断列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表:

我只是想编写一个Google Apps脚本,以将".Upload"之前的B列中的所有内容插入E列.因此,在表格列E = 20ba4a5c .

我认为我应该能够使用 split()函数来执行此操作,但是我遇到了一些困难.

ss.getRange('E'+ lastRow).setFormula('SPLIT(B'+ lastRow +'.Upload')[0]');

解决方案

  • 您应该使用

    I have the following table:

    I am simply trying to write a Google apps script to insert into column E everything in column B prior to '.Upload'. So in the table column E = 20ba4a5c.

    I think I should be able to use the split() function to do that but I'm having some difficulty.

    ss.getRange('E'+lastRow).setFormula('SPLIT(B'+lastRow+'.Upload')[0]');

    解决方案

    • You should use REGEXEXTRACT to build a simple regex in order to achieve your goal.

    • It is also a better practice to use template literals when dealing with multiple concatenations.

    Solution:

    Replace:

    setFormula('SPLIT(B'+lastRow+'.Upload')[0]');
    

    with:

    setFormula( `REGEXEXTRACT(B${lastRow},"^(.*?).Upload")`)
    

    Output:

    这篇关于谷歌表应用程序脚本截断列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆