使用openXML获取自定义属性和版本

我有一个特定版本的OpenXML-Excel文档,其中包含一些自定义属性。 当我查看该文件的xml结构时,这些属性存储在.\customXml\item2.xml

(一部分)

 <xsd:all> <xsd:element ref="ns2:Status"/> <xsd:element ref="ns2:Duedate" minOccurs="0"/> <xsd:element ref="ns2:SpId" minOccurs="0"/> <xsd:element ref="ns2:TemplateName" minOccurs="0"/> <xsd:element ref="ns2:MailSent" minOccurs="0"/> <xsd:element ref="ns2:Company" minOccurs="0"/> <xsd:element ref="ns2:WeeklyReminderSent" minOccurs="0"/> <xsd:element ref="ns2:DailyReminderSent" minOccurs="0"/> </xsd:all> 

另外,这个文件也被修改了。

现在我需要使用OpenXML(或ClosedXML)读取这些值

我试图跟随收到这些数据。 ClosedXML:

 var workBook = new ClosedXML.Excel.XLWorkbook("myfile.xlsx"); var props = workBook.Properties; var custProps = workBook.CustomProperties; 

OpenXML的:

 using (FileStream fs = new FileStream("myfile.xlsx", FileMode.Open, FileAccess.Read, FileShare.Read)) { using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fs, false)) { var coreprops = doc.CoreFilePropertiesPart; var custprops = doc.CustomFilePropertiesPart; var extprops = doc.ExtendedFilePropertiesPart; } } 

两种方法都不包含任何对象(props,custprops,coreprops,extrprops)中的任何存储的自定义属性

我怎样才能收集这些信息的OpenXML方式?

使用OpenXML sdk 2.5

你得到的CustomPropertiesPart,但你需要从属性:

 CustomFilePropertiesPart customPropsPart = doc.CustomFilePropertiesPart; DocumentFormat.OpenXml.CustomProperties.Properties props = customPropsPart.Properties; foreach (DocumentFormat.OpenXml.CustomProperties.CustomDocumentProperty prop in props) { //do what you want to do... in my case I have only one Text property... String propName = prop.Name; String value = prop.VTLPWSTR.InnerText; }