- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用以下代码将 xml (openxml) 注入(inject) Word 中的段落范围。问题是我收到一条错误消息,指出“无法将 XML 标记插入到指定位置”
C#代码:
try
{
string oxml = ""; // this contains the xml listed below
// get the first paragraph
Paragraph p = this.Paragraphs[1];
object missing = Type.Missing;
// insert openxml formatted xml into paragraph range
p.Range.InsertXML(oxml, ref missing); // causes the exception
}
catch (Exception ex)
{
//_logger.Error("OpenXml Injection", ex);
}
要注入(inject)的XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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: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 wp14">
<w:p>
<w:r>
<w:t xml:space="preserve">(a) Costs and Expenses</w:t>
</w:r>
<w:del w:id="33350" w:author="Exemplify">
<w:r>
<w:delText xml:space="preserve">. </w:delText>
</w:r>
</w:del>
<w:r>
<w:t xml:space="preserve"> The</w:t>
</w:r>
<w:commentRangeStart w:id="33351" />
<w:del w:id="33352" w:author="Exemplify">
<w:r>
<w:delText xml:space="preserve"> Borrower</w:delText>
</w:r>
</w:del>
<w:commentRangeEnd w:id="33351" />
<w:r>
<w:commentReference w:id="33351" />
</w:r>
<w:r>
<w:t xml:space="preserve"> shall pay (i) all reasonable out-of-pocket expenses incurred by the Administrative Agent and its Affiliates</w:t>
</w:r>
<w:del w:id="33353" w:author="Exemplify">
<w:r>
<w:delText xml:space="preserve">, </w:delText>
</w:r>
</w:del>
<w:ins w:id="33354" w:author="Exemplify">
<w:r>
<w:t xml:space="preserve"> (</w:t>
</w:r>
</w:ins>
<w:r>
<w:t xml:space="preserve">.</w:t>
</w:r>
</w:p>
</w:document>
</pkg:package>
最佳答案
要使用 InsertXML,XML 必须是完整、有效的 Word 2003 WordProcessingML 文档,或者是完整、有效的平面 OPC 格式的 Open Office XML 文档。目前,您拥有的 XML 不是其中任何一个。
要成为一个有效的平面 OPC 包,包必须包含部件,并定义必要的关系部件。
要成为有效的 Word 2003 XML 文档,命名空间声明需要不同,文档元素需要是
<w:wordDocument>
在里面你需要一个
<w:body>
元素。我怀疑您拥有的某些元素对于该 XML 词汇表无效(您可以自己检查)但是例如以下删除了一些元素和属性的 XML 应该注入(inject) OK:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:body>
<w:p>
<w:r>
<w:t>(a) Costs and Expenses</w:t>
</w:r>
<w:r>
<w:t> The</w:t>
</w:r>
<w:r>
</w:r>
<w:r>
<w:t> shall pay (i) all reasonable out-of-pocket expenses incurred by the Administrative Agent and its Affiliates</w:t>
</w:r>
<w:r>
<w:t>.</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument>
对于 Word 2007 和更高版本的 XML,所有内容都需要在包内的某个部分内,并且包必须定义一些关系。在这种情况下,可以执行以下操作(您只需要在 XML 中实际引用的命名空间定义):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<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: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:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:t>(a) Costs and Expenses</w:t>
</w:r>
<w:del w:id="33350" w:author="Exemplify">
<w:r>
<w:delText>. </w:delText>
</w:r>
</w:del>
<w:r>
<w:t> The</w:t>
</w:r>
<w:commentRangeStart w:id="33351" />
<w:del w:id="33352" w:author="Exemplify">
<w:r>
<w:delText> Borrower</w:delText>
</w:r>
</w:del>
<w:commentRangeEnd w:id="33351" />
<w:r>
<w:t> shall pay (i) all reasonable out-of-pocket expenses incurred by the Administrative Agent and its Affiliates</w:t>
</w:r>
<w:del w:id="33353" w:author="Exemplify">
<w:r>
<w:delText>, </w:delText>
</w:r>
</w:del>
<w:ins w:id="33354" w:author="Exemplify">
<w:r>
<w:t> (</w:t>
</w:r>
</w:ins>
<w:r>
<w:t>.</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>
我省略了 xml:space="preserve"属性——您可能需要它们。我还省略了以下 block
<w:r>
<w:commentReference w:id="33351" />
</w:r>
这会导致失败。我猜这是因为它实际上引用了一个带有不存在的 ID 的评论。
关于c# - Word、VSTO、OpenXml - 将 XML 插入段落对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23943844/
我想标记一个字符串,例如 Best Beat Makers,以几乎类似于 NGram 的方式为每个单词生成标记,例如: IN: "Best Beat Makers" OUT: ["Best", "B
这个问题在这里已经有了答案: Is there a way to word-wrap long words in a div? (6 个答案) 关闭 7 年前。
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我有以下正则表达式: ^--([\w|-]+) 我想匹配 --word --no-word 但不是: ---word ----word 最佳答案 将表情更改为 ^--(\w[-\w]*) 这需要在两个
在我的加载项中,我需要为每个打开的文档创建一个任务 Pane 。在加载项的启动方法中,我订阅了 ApplicationEvents4_Event.NewDocument 和 Application.D
我使用 word javascript api 开发了一个 word 插件。我的文档 .docx 文件在服务器上,我需要在加载项中单击按钮打开该 .docx 文档作为新的 Word 文档。 请指导我如
我需要在某个地方修复一些 CSS,因为我的文本没有环绕,如果它是一个非常长的单词,它会无限期地继续下去。 在大多数情况下,我在我的 CSS 文件中尝试了 word-wrap: break-word;
这个问题在这里已经有了答案: What is the difference between "word-break: break-all" versus "word-wrap: break-word
这个问题在这里已经有了答案: What is the differect between word-wrap and overflow-wrap? [duplicate] (1 个回答) Is t
问题详细描述如下: 给定两个单词(beginWord 和 endWord)和字典的单词列表,找出是否存在从 beginWord 到 endWord 的转换序列,这样: 一次只能更改一个字母 每个转换后
我以前没有使用过邮件合并字段,我发现的所有内容都要求您在能够插入合并字段之前选择一个数据源。我想要做的就是将字段放在 word 文档上,并且在代码使用它之前不要将其合并。我基本上是在创建文档模板。这在
将此代码放置在ThisDocument_Startup之外的Word文档级VSTO解决方案中的某个位置(创建带单击事件的功能区按钮): int zero = 0; int divideByZero =
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只能找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,您
当使用 URI 方案从网页上托管的 word 模板打开新文档时不起作用。 https://msdn.microsoft.com/en-us/library/office/dn906146.aspx 这
我的问题: overflow-wrap: break-word 和 word-break: break-word 有区别吗? 非重复: 这里有一些现有的问题,乍一看可能是重复的,但实际上不是。 Wha
我希望使用 WordNet 从一组基本术语中寻找相似术语的集合。 例如,单词'discouraged' - 潜在的同义词可能是:daunted, glum, deterred, pessimistic
部署 Word Add in 时,发布没有错误。复制文件后出现以下错误。 我没有太多事情要做。这是堆栈跟踪。 ************** Exception Text **************
我需要一个 Java 正则表达式来匹配除某个单词之外的任何单词,同时包含另一个单词。 例如字符串中不能包含Apple,但必须有Peach。 Apple and Peach - Not match Pe
我是一名优秀的程序员,十分优秀!