openxml 相关问题

有关通过直接处理zip包中包含的XML文件或通过Microsoft Office Open XML SDK读取和写入Microsoft Office Open XML文件的问题。

动态创建的Word文档中缺少Open XML部件

我正在使用Open XML SDK在C#中创建WordprocessingDocuments,然后将它们转换为pdf。最初,我是使用Interop将文档保存为PDF格式的,但是现在这不是一个选择。我...

回答 1 投票 0

是否有一种方法可以使用c#使用openxml在Word文档中显示多级列表?

我需要在该项目之一的Word文档中显示多级列表。这必须使用Open XML和C#来实现。以下是所需的示例输出。 1标题1 1.1标题2 1.1.1 ...

回答 1 投票 0

获取用于在OpenXML中创建索引的文本的页码

我正在从c#控制台应用程序生成Microsoft世界文档,在该应用程序中,我看到了在不同位置的Word文档中散布的马匹列表。我想在...

回答 1 投票 0

预览由OpenXML创建的zip文件中的文档时出错

我使用OpenXML工具创建了word和excel文件的字节数组,并使用ZipArchive将其压缩并返回filebyte。 httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK); ...

回答 1 投票 0

使用.NET自动更新Word doc的目录?

在Word 2007中,您可以右键单击目录区域,并告诉它更新其页码以指向该链接的当前页面。我想以编程方式执行此操作,...

回答 2 投票 2

如何使用AddDigitalSignatureOriginPart(DocumentFormat.OpenXml库)保护Excel文件的安全?

[需要创建一个数字签名的excel文件,然后在C#中上传后验证签名。

回答 1 投票 0

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

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

回答 1 投票 0

'对象引用未设置为对象的实例',在使用OpenXML导入数据集中的Excel时

我正在Windows应用程序上工作,我在可能包含多张工作表的数据集文件中一个接一个地导入多个excel文件。我正在为此使用OpenXML,当...

回答 1 投票 0

了解docx文件中的书签

我正在尝试从Docx文件中提取书签,我编写了一段代码,正在某些Docx文件中提取书签,但在某些docx文件中找不到任何书签。我正在使用python -...

回答 1 投票 0

[使用OpenXML复制C#DOCX文件

我正在尝试使用C#中的OpenXML复制docx文件的内容并将其保存在同一文件中,这是代码:using(WordprocessingDocument wordDoc = WordprocessingDocument.Open(...

回答 2 投票 1

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

[使用OpemXML复制C#DOCX文件

我正在尝试使用C#中的OpenXML复制docx文件的内容并将其保存在同一文件中,这是代码:using(WordprocessingDocument wordDoc = WordprocessingDocument.Open(...

回答 2 投票 0

OpenXML显示System.NullReferenceException:'对象引用未设置为对象的实例。'在text.Text

我有一个问题。我正在使用OpenXml将图像以及一些文本放在图像内容控件上。现在我很担心,它会从数据库中提取信息(所有信息似乎都很好)。现在...

回答 1 投票 0

C#.NET检索由特定注释引用的文本的列表号

我正在尝试检索由特定注释引用的一段文本的列表号,如此处所示的示例。在此示例中,应检索3.3.1.1.1.-I。这是一个自定义...

回答 1 投票 0

OpenXML-将书签应用于Word文档中的段落

下面的代码使用OPENXML(asp.net)可以正常工作,并使用HEADING2在Word文档中打印元素...我们如何将书签应用于特定段落。我们试图提取的是...之间的部分]]

回答 1 投票 5

我可以在Flask应用程序中使用OpenXmlPowerTools

是否可以在Flask / Python 3网络应用程序中使用基于C#/。Net的库,例如OpenXmlPowerTools ,?我的研究告诉我,我是否可以通过包装纸?或创建微服务?想...

回答 1 投票 1

在使用OpenXML创建的docx中,可以为使用NoChangeAspect属性添加的图像保留纵横比吗?

我正在创建docx文档并向其中添加图像。我已经通过https://docs.microsoft.com/en-us/office/open-xml/how-to-insert-a-picture-into-a-word-processing-document?redirectedfrom=MSDN I做到了。 ..

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.