javascript - Word insertOoxml 方法返回错误:所有输入都未知
问题描述
我有一个现有的 Word 加载项解决方案,它已经运行了很长时间,但现在无法将 OOXML 内容插入 Word 文档。试图打破这一点,我无法让 insertOoxml 方法在任何情况下工作。
重现:
await Word.run(async (context) => {
context.document.getSelection().insertOoxml(theOoxml, 'Start');
await context.sync();
});
其中 theOoxml 可以是任何有效的 Ooxml 字符串。我一直在使用的参考示例是:
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
<pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" />
</Relationships>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<pkg:xmlData>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">
<w:body>
<w:p>
<w:r>
<w:t>
Hey there
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>
结果是:
word-web-16.00.debug.js:11162 Uncaught (in promise) 错误:RequestContext.ClientRequestContext.processRequestExecutorResponseMessage (word-web-16.00.debug. js:13713) 在 word-web-16.00.debug.js:13620
已经在不同的租户、浏览器中尝试过,这让我有点发疯。如果这对您有用,请告诉我您的一般配置/设置。
谢谢。
更新:
为了避免有关 XML 本身有效性的问题,以下代码获取当前选择的 OOXML,然后在选择后复制它 - 也会失败并出现相同的错误。
await Word.run(async (context) => {
var sourceRange = context.document.getSelection();
var contentToCopy = sourceRange.getOoxml();
await context.sync();
sourceRange.insertOoxml(contentToCopy.value, 'After');
await context.sync();
});
希望我在这里缺少一些简单的东西。任何插入任何Ooxml 片段的建议/解决方法都值得赞赏。
2018 年9 月 4 日更新: Microsoft 已承认该问题并将修复它。
2018 年 9 月 12 日更新: InsertOoxml 似乎又可以正常工作了——尽管我还没有得到微软关于修复的确认。
解决方案
InsertOoxml 现在似乎又像以前一样工作了。
我尚未从 Microsoft 支持案例中获得有关此修复的确认,但我的所有客户似乎都可以再次正常工作。
感谢Juan Balmori和可扩展性团队的工作人员解决了这个问题。
J。
推荐阅读
- python - Beautifulsoup - 删除 HTML 标签
- ruby-on-rails - Gmail 未收到 ActionMailer 电子邮件
- python - Windows Edge webdriver 失败并出现 WebDriverException:消息:未知错误
- jenkins - 从 bitbucket 存储库推送触发 jenkins 作业
- python - 基于另一个有条件的系列更新系列中的值
- javascript - click(jquery) 在脚本加载后立即执行该函数并且不响应点击
- robotframework - 只有在 RobotFramework 中的第一个测试失败时才开始第二个测试
- javascript - 如何修复 iOS 13.x JavaScript 提示对话框键盘错误(独立于浏览器)
- sql-server - 在 T-SQL 中,如何在每次达到某个条件时创建一个新分区,并保留该分区直到我下次看到该条件?
- parse-server - 为什么 Parse LiveQuery 并不总是触发更新/创建/输入事件?