【问题标题】:Unable to insert text with soft return \v characters无法插入带有软返回 \v 字符的文本
【发布时间】:2019-06-13 14:46:00
【问题描述】:

当使用 insertText 命令通过 office.js (Word Online) 插入文本时,软返回字符 (char 11) 将呈现为正方形,而不是正确的换行符。

我试过 char(11)。 \r 和 \n 产生分节符。而我想要一个换行符,这样它就不会增加项目符号列表的编号

text = 'This is a\vline break test';
Word.run(context => {
    context.document.getSelection().insertText(text, Word.InsertLocation.end);
    return context.sync();
});

\v 应该呈现与最终用户键入 SHIFT+ENTER 相同的效果。相反,它只是渲染方形字符

【问题讨论】:

  • 我无法使用Script Lab 工具重现此内容。您的代码有效,\v 产生换行符并且没有正方形。尝试在 Script Lab 中运行它,看看会发生什么。
  • 我也很好奇。也无法产生软回报:JavaScript String fromCharCode() Method

标签: javascript ms-word office-js


【解决方案1】:

这种方法对我有用。可能会帮助别人

const lines = text.split('\n');
const { Word } = window;
Word.run(context => {
    for (let i = lines.length - 1; i >= 0; i -= 1) {
        let line = lines[i];
        context.document.getSelection().insertText(line, Word.InsertLocation.end);

        if (i !== 0) {
            context.document.getSelection().insertBreak(Word.BreakType.line, 'After');
        }
    }

    return context.sync();
});

【讨论】:

    猜你喜欢
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多