openxml-sdk 相关问题

Open XML SDK for Microsoft Office构建于System.IO.Packaging API之上,并提供强类型的零件类来操作Open XML文档。

获取节点上可能包含的元素列表

我在验证我的XML时遇到错误:“该元素具有意外的子元素'http://schemas.openxmlformats.org/drawingml/2006/main:p'。预期的可能元素列表:http://模式....

回答 1 投票 0

如何使用openxml在ASP.NET MVC项目中打开docx文件来覆盖某些文本

我已经搜索了很多解决方案,但找不到任何解决方案。我的MVC项目文件夹中有一个.docx文件,我想打开该文件以覆盖一些文本,但是我无法这样做。在我的项目中...

回答 1 投票 1

如何使用OpenXML SDK在Excel中附加.eml文件?

我正在使用此代码。它确实附加了文件,但是如果使用MS Excel应用程序打开文件,我什么也看不到。字符串targetFile =“测试返回tracker.xlsx”;字符串...

回答 1 投票 0



是否可以使用C#和Open XML SDK在Word文档中显示多级列表? [关闭]

我需要使用Word文档中的多级列表来设置文本格式(例如,标题,带编号的段落)。这应该使用Open XML SDK在C#中实现。这是必需的示例...

回答 1 投票 -1

从'WordOpenXML'转换为In-Memory System.IO.Packaging.Package

[使用VSTO 2012操作MS Word文档时,我看到该文档具有WordOpenXML字符串属性,该属性是构成.docx包的所有文件的XML表示,......]

回答 1 投票 2

使用OpenXml API更新Word Customxml部件,但无法更新主文档中的“ document.xml”

我们使用C#代码更新自定义xml部分。我们已成功更新寡妇中的文档。但是我们可以在Linux环境中打开此文档,不能更改它的值。如何实现...

回答 1 投票 -1

如何通过C#通过OpenXML从Word(.Docx)提取OLE文件

我想使用Openxml从“ .docx”文件中提取“ OLE包”。我不知道该怎么做,在官方示例中也找不到任何示例。请帮我。这是我的尝试:1.I ...

回答 1 投票 0

OpenXML DataBinding不适用于名称空间

我有一个Word文档,其中包含一个内容控件XML。这是来自document.xml的内容控件的代码: [[[[]]]] 下面的单元测试表明,只有在使用命名空间前缀(例如“ ex”)的情况下,您才能将w:sdt元素绑定到具有XML命名空间(例如“ http://example.com”)的自定义XML元素。 )放在w:prefixMappings元素的w:xpath和w:dataBinding属性中。 不过,您的自定义XML元素不需要名称空间前缀。因此,以下两个XML文档都将起作用: <?xml version="1.0" encoding="utf-8"?> <ex:Root xmlns:ex="http://example.com"> <ex:Node>VALUE1</ex:Node> </ex:Root> <?xml version="1.0" encoding="utf-8"?> <Root xmlns="http://example.com"> <Node>VALUE1</Node> </Root> 这里是单元测试: using System; using System.Xml.Linq; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.CustomXmlDataProperties; using DocumentFormat.OpenXml.Packaging; using OpenXmlPowerTools; using Xunit; namespace CodeSnippets.Tests.OpenXml.Wordprocessing { public class DataBoundContentControlTests { private const WordprocessingDocumentType Type = WordprocessingDocumentType.Document; private const string NsPrefix = "ex"; private const string NsName = "http://example.com"; private static readonly XNamespace Ns = NsName; private static string CreateCustomXmlPart(MainDocumentPart mainDocumentPart, XElement rootElement) { CustomXmlPart customXmlPart = mainDocumentPart.AddCustomXmlPart(CustomXmlPartType.CustomXml); customXmlPart.PutXDocument(new XDocument(rootElement)); return CreateCustomXmlPropertiesPart(customXmlPart); } private static string CreateCustomXmlPropertiesPart(CustomXmlPart customXmlPart) { XElement rootElement = customXmlPart.GetXElement(); if (rootElement == null) throw new InvalidOperationException(); string storeItemId = "{" + Guid.NewGuid().ToString().ToUpper() + "}"; // Create a ds:dataStoreItem associated with the custom XML part's root element. var dataStoreItem = new DataStoreItem { ItemId = storeItemId, SchemaReferences = new SchemaReferences() }; if (rootElement.Name.Namespace != XNamespace.None) { dataStoreItem.SchemaReferences.AppendChild(new SchemaReference {Uri = rootElement.Name.NamespaceName}); } // Create the custom XML properties part. var propertiesPart = customXmlPart.AddNewPart<CustomXmlPropertiesPart>(); propertiesPart.DataStoreItem = dataStoreItem; propertiesPart.DataStoreItem.Save(); return storeItemId; } [Fact] public void CanDataBindBlockLevelSdtToCustomXmlWithNsPrefixIfNsPrefixInPrefixMapping() { // The following root element has an explicitly created attribute // xmlns:ex="http://example.com": // // <ex:Root xmlns:ex="http://example.com"> // <ex:Node>VALUE1</ex:Node> // </ex:Root> // var customXmlRootElement = new XElement(Ns + "Root", new XAttribute(XNamespace.Xmlns + NsPrefix, NsName), new XElement(Ns + "Node", "VALUE1")); using WordprocessingDocument wordDocument = WordprocessingDocument.Create("SdtBlock_NsPrefix_WithNsPrefixInMapping.docx", Type); MainDocumentPart mainDocumentPart = wordDocument.AddMainDocumentPart(); string storeItemId = CreateCustomXmlPart(mainDocumentPart, customXmlRootElement); mainDocumentPart.PutXDocument(new XDocument( new XElement(W.document, new XAttribute(XNamespace.Xmlns + "w", W.w.NamespaceName), new XElement(W.body, new XElement(W.sdt, new XElement(W.sdtPr, new XElement(W.dataBinding, // Note the w:prefixMapping attribute WITH a namespace // prefix and the corresponding w:xpath atttibute. new XAttribute(W.prefixMappings, $"xmlns:{NsPrefix}='{NsName}'"), new XAttribute(W.xpath, $"{NsPrefix}:Root[1]/{NsPrefix}:Node[1]"), new XAttribute(W.storeItemID, storeItemId))), new XElement(W.sdtContent, new XElement(W.p))))))); // Note that we just added an empty w:p to the w:sdtContent element. // However, if you open the Word document created by the above code // in Microsoft Word, you should see a single paragraph saying // "VALUE1". } [Fact] public void CanDataBindBlockLevelSdtToCustomXmlWithoutNsPrefixIfNsPrefixInPrefixMapping() { // The following root element has an implicitly created attribute // xmlns='http://example.com': // // <Root xmlns="http://example.com"> // <Node>VALUE1</Node> // </Root> // var customXmlRootElement = new XElement(Ns + "Root", new XElement(Ns + "Node", "VALUE1")); using WordprocessingDocument wordDocument = WordprocessingDocument.Create("SdtBlock_DefaultNs_WithNsPrefixInMapping.docx", Type); MainDocumentPart mainDocumentPart = wordDocument.AddMainDocumentPart(); string storeItemId = CreateCustomXmlPart(mainDocumentPart, customXmlRootElement); mainDocumentPart.PutXDocument(new XDocument( new XElement(W.document, new XAttribute(XNamespace.Xmlns + "w", W.w.NamespaceName), new XElement(W.body, new XElement(W.sdt, new XElement(W.sdtPr, new XElement(W.dataBinding, // Note the w:prefixMapping attribute WITH a namespace // prefix and the corresponding w:xpath atttibute. new XAttribute(W.prefixMappings, $"xmlns:{NsPrefix}='{NsName}'"), new XAttribute(W.xpath, $"{NsPrefix}:Root[1]/{NsPrefix}:Node[1]"), new XAttribute(W.storeItemID, storeItemId))), new XElement(W.sdtContent, new XElement(W.p))))))); // Note that we just added an empty w:p to the w:sdtContent element. // However, if you open the Word document created by the above code // in Microsoft Word, you should see a single paragraph saying // "VALUE1". } [Fact] public void CannotDataBindBlockLevelSdtToCustomXmlWithDefaultNsIfNotNsPrefixInPrefixMapping() { // The following root element has an implicitly created attribute // xmlns='http://example.com': // // <Root xmlns="http://example.com"> // <Node>VALUE1</Node> // </Root> // var customXmlRootElement = new XElement(Ns + "Root", new XElement(Ns + "Node", "VALUE1")); using WordprocessingDocument wordDocument = WordprocessingDocument.Create("SdtBlock_DefaultNs_WithoutNsPrefixInMapping.docx", Type); MainDocumentPart mainDocumentPart = wordDocument.AddMainDocumentPart(); string storeItemId = CreateCustomXmlPart(mainDocumentPart, customXmlRootElement); mainDocumentPart.PutXDocument(new XDocument( new XElement(W.document, new XAttribute(XNamespace.Xmlns + "w", W.w.NamespaceName), new XElement(W.body, new XElement(W.sdt, new XElement(W.sdtPr, new XElement(W.dataBinding, // Note the w:prefixMapping attribute WITHOUT a namespace // prefix and the corresponding w:xpath atttibute. new XAttribute(W.prefixMappings, $"xmlns='{NsName}'"), new XAttribute(W.xpath, "Root[1]/Node[1]"), new XAttribute(W.storeItemID, storeItemId))), new XElement(W.sdtContent, new XElement(W.p))))))); // Note that we just added an empty w:p to the w:sdtContent element. // If you open the Word document created by the above code in Microsoft // Microsoft Word, you will only see an EMPTY paragraph. } } }

回答 1 投票 0

如何在ASP.net中使用Open XML创建多级有序列表?

我花了无数时间试图理解Open XML中的有序列表。这是众多参考文献之一。我在这里找到了一个简单的文档创建者的非常有用的示例。另外,如果我可以...

回答 1 投票 2

Word OpenXml Word找到的不可读内容

我们正在尝试根据某些条件来操纵Word文档以删除段落。但是,当我们尝试打开并出现以下错误时,生成的单词文件总是以损坏的形式出现:Word ...

回答 1 投票 0

克隆Office Open XML文档的最有效方法是什么?

[使用Office Open XML文档(例如自Office 2007发行以来由Word,Excel或PowerPoint创建的文档时,您通常会希望克隆或复制现有文档,然后制作...

回答 1 投票 0

OpenXml SDK-如何在Word文档中唯一标识段落

我需要根据一些唯一的ID或可以识别/区分50-60页word文档中的每个段落的内容(使用TX Text Editor加载它)来提取段落。我将标记这些...

回答 1 投票 1


是否可以使用openxml制作只读段落?

我正在使用OpenXML和C#生成Word文档。我想阻止(只读)文本中的一个段落,以便在用户编辑时无法将其删除。我做了一些不成功的测试,使...

回答 1 投票 0

OpenXML SDK自动测试

我正在使用内容控件和OpenXML SDK来实现ms word文档的生成。我想对该代码进行一些自动化测试(单元测试或一些简单的UI自动化测试)。有人吗...

回答 4 投票 10

OpenXML:如何将工作表复制到另一个工作簿?

我需要将一些工作簿的工作表合并到一个新的工作簿中。我试过的是这个,但是我得到“无法插入OpenXmlElement“ newChild”,因为它是树的一部分。“。使用(var ...

回答 1 投票 0

如何使用Open XML SDK读取xml

如何使用Open XML SDK从.docx获取xml?我的代码WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath,true);正文正文= wordprocessingDocument.MainDocumentPart ....

回答 1 投票 0

C#从Word文档复制表格并将其添加到另一个Word文档中

我想从MS Word文档中获取一个表格,并将该表格以所有格式添加到另一个文档中。我正在使用OOXML来做到这一点。为了标识特定的表,我分配了“替代文本-> ...

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.