是否可以在 Word api 中获取带换行符的文本?
Is it possible to get text with line breaks via Word api?
似乎 context.document.body.text(或 paragraph.text 或 whatever.text)总是有没有换行符的文本值。获取带有换行符的文本的唯一可能方法是解析 ooxml 或 html。 ooxml 解析是行不通的,因为对于办公室在线 ooxml 是在服务器端计算的,通常需要 3 秒才能完成。 Html 检索也很慢,一页文件最多需要 500 毫秒。奇怪的是,您可以插入包含换行符 (/n) 的文本,但无法取回此文本。
所以问题是:是否可以通过 Word api 获取带换行符的文本?
包含换行符。如果仔细查看检索到的文本,会在文本中返回一个“\r”,这是一个换行符或段落标记。
换行符也包括在内(如果用户执行 Shift+Enter,则会插入换行符)。
这是获取context.document.body.text 属性后返回的示例文字字符串。那个文档有很多段落,我加粗了te \r 补充说:
"Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.\rTo make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.\rThemes and styles also help keep your document coordinated. When you click Design and choose a new Theme, the pictures, charts, and SmartArt graphics change to match your new theme. When you apply styles, your headings change to match the new theme.\rSave time in Word with new buttons that show up where you need them. To change the way a picture fits in your document, click it and a button for layout options appears next to it. When you work on a table, click where you want to add a row or a column, and then click the plus sign.\rReading is easier, too, in the new Reading view. You can collapse parts of the document and focus on the text you want. If you need to stop reading before you reach the end, Word remembers where you left off - even on another device.\r"
似乎 context.document.body.text(或 paragraph.text 或 whatever.text)总是有没有换行符的文本值。获取带有换行符的文本的唯一可能方法是解析 ooxml 或 html。 ooxml 解析是行不通的,因为对于办公室在线 ooxml 是在服务器端计算的,通常需要 3 秒才能完成。 Html 检索也很慢,一页文件最多需要 500 毫秒。奇怪的是,您可以插入包含换行符 (/n) 的文本,但无法取回此文本。
所以问题是:是否可以通过 Word api 获取带换行符的文本?
包含换行符。如果仔细查看检索到的文本,会在文本中返回一个“\r”,这是一个换行符或段落标记。
换行符也包括在内(如果用户执行 Shift+Enter,则会插入换行符)。
这是获取context.document.body.text 属性后返回的示例文字字符串。那个文档有很多段落,我加粗了te \r 补充说:
"Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.\rTo make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.\rThemes and styles also help keep your document coordinated. When you click Design and choose a new Theme, the pictures, charts, and SmartArt graphics change to match your new theme. When you apply styles, your headings change to match the new theme.\rSave time in Word with new buttons that show up where you need them. To change the way a picture fits in your document, click it and a button for layout options appears next to it. When you work on a table, click where you want to add a row or a column, and then click the plus sign.\rReading is easier, too, in the new Reading view. You can collapse parts of the document and focus on the text you want. If you need to stop reading before you reach the end, Word remembers where you left off - even on another device.\r"