我看过Google的产品论坛,但找不到任何东西。帮助文本字段是为简短文本设计的,但是我想插入多段文章。没有段落中断,我会看到一堆很难阅读的文字。
这一直困扰着我很长时间,我想出了一个基于 Apps Script 的不太优雅但有效的解决方案。Pavel Agarkov 也有同样的想法!我的版本也适用于多次出现,如果 Google 表单在您编辑文本时删除了换行符,则可以重新运行。
创建一个新脚本,用下面的代码替换内容。保存并返回到您的表单。
重新加载页面。您会注意到主菜单中有一个新选项,如下所示

“脚本”菜单是由我们的脚本添加的。暂时不要使用它,它不会有太大作用。
从脚本菜单运行脚本。现在庆祝???
一些值得注意的事情:
第一次运行脚本时,您将收到权限请求。没关系,阅读邮件,做你该做的。
一旦出现换行符,谷歌表单,上帝保佑它的心脏,每次编辑字段时都会删除它们。轻微的令人恼火。只需再次运行脚本。
您需要使用的脚本是:
// From https://stackoverflow.com/questions/22207368/
function onOpen() {
var ui = FormApp.getUi();
ui.createMenu('Scripts')
.addItem('Replace 4+ spaces with line breaks in Title and Description', 'addLineBreaks')
.addToUi();
}
function addLineBreaks() {
var theForm = FormApp.getActiveForm();
var theQuestions = theForm.getItems();
var thePlaceholder = new RegExp(/\s{4,99}|\n/, 'gi');
for (i = 0; i < theQuestions.length; i++) {
var theText = theQuestions[i].getHelpText();
if (theText.search(thePlaceholder) > 0 ) {
theQuestions[i].setHelpText(theText.replace(thePlaceholder,' \n'));
}
theText = theQuestions[i].getTitle();
if (theText.search(thePlaceholder) > 0 ) {
theQuestions[i].setTitle(theText.replace(thePlaceholder,' \n'));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我发现您无法通过编辑器完成此操作,但是可以通过脚本来完成。进入主菜单->脚本编辑器;将以下代码传递给编辑器;
function addLineBreaks()
{
var form = FormApp.getActiveForm();
// find form items you need
var questions = form.getItems(FormApp.ItemType.MULTIPLE_CHOICE);
for(i = 0; i < questions.length; i++)
{
var title = questions[i].getTitle();
// if no replacement has been done yet
if(title.indexOf("\n") < 0)
{
// in my case I always need line break before "B:"
// you can replace your special symbol
// for example: "<br>" or "<p>"
questions[i].setTitle(title.replace("B:", "\nB:"));
}
}
}Run Code Online (Sandbox Code Playgroud)
然后设置触发器以在打开表单时启动此方法。
| 归档时间: |
|
| 查看次数: |
19550 次 |
| 最近记录: |