如何使用 AppsScript 检测 Google 表格单元格中的新行
我正在使用这个 脚本 根据我的电子表格生成 json。
我的一些单元格中有一条新线,在单元格内不可见。
当我运行脚本时,新行显示为 ..mytext \nMytext
等,
我想将 \n
替换为
,所以我把它放在 第 44 行
text.replace('\n', "<br>")
根本不起作用,所以我'已将其更改为:
text.replace(/\n/g, "<br>");
这也不起作用, \n
仍然存在于 输出。
我相信它有不同的代码或其他东西,有什么想法如何解决吗?
Google 表格中的文本是从 Google 文档复制粘贴的
I am using this script to generate json based on my spreadsheet.
Some of my cells have a new line that no visible within a cell.
When I fun a script the new line appears like ..mytext \nMytext
, etc
I want to replace \n
with <br>
, so I placed that at line 44
text.replace('\n', "<br>")
which is didn't work at all, so I've changed it to that:
text.replace(/\n/g, "<br>");
which didn't work either, the \n
is still present within an output.
I believe it has a different code or something, any ideas how to fix?
The text to google sheet is copy-pasted from google docs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
text.replace(/\n/g, "
和");
也不起作用,\n 仍然存在于输出中。
,既然如此,下面的修改如何?From:
To:
From
我想用
,下面的修改如何?替换 \n,所以我把它放在[第 44 行](https://gist.github.com/florentdescroix/9513cfd957f8b2cde7b832cf7170c84a#file-exportjson -js-L44)
当我在
makeJSON_
看到您的展示脚本时,返回var jsonString = JSON.stringify(object, null, 4);
。由此,我认为需要将text.replace(/\n/g, "
修改为")
text.replace(/\\n/g, “
。”)
From
text.replace(/\n/g, "<br>");
andwhich didn't work either, the \n is still present within an output.
, in this case, how about the following modification?From:
To:
From
I want to replace \n with <br>, so I placed that at [line 44](https://gist.github.com/florentdescroix/9513cfd957f8b2cde7b832cf7170c84a#file-exportjson-js-L44)
, how about the following modification?When I saw your showing script, at
makeJSON_
,var jsonString = JSON.stringify(object, null, 4);
is returned. By this, I thought thattext.replace(/\n/g, "<br>")
is required to be modified totext.replace(/\\n/g, "<br>")
.