[转]how to programatically access built-in properties of open xml word doc(如何读取open xml格式文档属性)
2011-11-02 17:35
941 查看
WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filePath, true);
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
String message = string.Empty;
ExtendedFilePropertiesPart appPart = wordprocessingDocument.ExtendedFilePropertiesPart;
Manager = appPart.Properties.Manager.InnerText;
if (Manager != null)
message = "Manager : " + Manager + "\n";
//Access company property
Company = appPart.Properties.Company.Text;
if (Company != null)
message += "Company : " + Company + "\n";
CoreFilePropertiesPart corePart = wordprocessingDocument.CoreFilePropertiesPart;
XmlDocument xmlProperties = new XmlDocument();
xmlProperties.Load(corePart.GetStream());
//Access Title property
Title = xmlProperties.GetElementsByTagName("title",DC).Item(0).InnerText;
if (Title != null)
message += "Title : " + Title + "\n";
//Access Subject property
Subject = xmlProperties.GetElementsByTagName("subject", DC).Item(0).InnerText;
if (Subject != null)
message += "Subject : " + Subject + "\n";
//Access Author property
Author = xmlProperties.GetElementsByTagName("creator", DC).Item(0).InnerText;
if (Author != null)
message += "Author : " + Author + "\n";
//Access Keywords property
KeyWords = xmlProperties.GetElementsByTagName("keywords", CP).Item(0).InnerText;
if (KeyWords != null)
message += "KeyWords : " + KeyWords + "\n";
//Access Comments property
Comments = xmlProperties.GetElementsByTagName("description", DC).Item(0).InnerText;
if (Comments != null)
message += "Comments : " + Comments + "\n";
//Access Category property
Category = xmlProperties.GetElementsByTagName("category", CP).Item(0).InnerText;
if (Category != null)
message += "Category : " + Category + "\n";
MessageBox.Show(message, "Built-In Properties", MessageBoxButtons.OK, MessageBoxIcon.Information);
wordprocessingDocument.Close();
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
String message = string.Empty;
ExtendedFilePropertiesPart appPart = wordprocessingDocument.ExtendedFilePropertiesPart;
Manager = appPart.Properties.Manager.InnerText;
if (Manager != null)
message = "Manager : " + Manager + "\n";
//Access company property
Company = appPart.Properties.Company.Text;
if (Company != null)
message += "Company : " + Company + "\n";
CoreFilePropertiesPart corePart = wordprocessingDocument.CoreFilePropertiesPart;
XmlDocument xmlProperties = new XmlDocument();
xmlProperties.Load(corePart.GetStream());
//Access Title property
Title = xmlProperties.GetElementsByTagName("title",DC).Item(0).InnerText;
if (Title != null)
message += "Title : " + Title + "\n";
//Access Subject property
Subject = xmlProperties.GetElementsByTagName("subject", DC).Item(0).InnerText;
if (Subject != null)
message += "Subject : " + Subject + "\n";
//Access Author property
Author = xmlProperties.GetElementsByTagName("creator", DC).Item(0).InnerText;
if (Author != null)
message += "Author : " + Author + "\n";
//Access Keywords property
KeyWords = xmlProperties.GetElementsByTagName("keywords", CP).Item(0).InnerText;
if (KeyWords != null)
message += "KeyWords : " + KeyWords + "\n";
//Access Comments property
Comments = xmlProperties.GetElementsByTagName("description", DC).Item(0).InnerText;
if (Comments != null)
message += "Comments : " + Comments + "\n";
//Access Category property
Category = xmlProperties.GetElementsByTagName("category", CP).Item(0).InnerText;
if (Category != null)
message += "Category : " + Category + "\n";
MessageBox.Show(message, "Built-In Properties", MessageBoxButtons.OK, MessageBoxIcon.Information);
wordprocessingDocument.Close();
相关文章推荐
- How to access the properties of an object in Javascript
- magento如何获取产品属性值 How to Obtain Custom Attribute Values in Magento
- 如何操作 Office Open XML 格式文档
- How To Verify the Word Size (32bit vs 64bit) of the Oracle Binary on MS Windows systems (文档 ID 46506
- 如何使用th:each属性迭代模板-原标题:How To Use th:each For Iteration In Thymeleaf Template?
- [转]How to set the control word of FPU in delphi
- How To Automate Cleanup Of Dead Connections And INACTIVE 【如何自动清理ORACLE中的死连接和非活动会话】
- magento如何获取产品属性值 How to Obtain Custom Attribute Values in Magento
- How to set globe layer cache properties(如何设置globe图层的缓存属性)
- How to access database using ADO in VB6 - 在 VB6 中用ADO对象如何访问数据库
- [GuanRui]How to open Path browse dialog in VBA of ArcGIS Desktop ?
- How to create a zip file in NetSuite SuiteScript 2.0 如何在现有SuiteScript中创建和下载ZIP压缩文档
- [Office 2010 易宝典]什么是OpenDocument格式?如何将Word文档保存为该格式?
- How to collect the full path name of the files in ASM diskgroups (文档 ID 888943.1)
- How to access body of Custom tags in JSP tutorial
- 如何将一篇文章导入Endnote并将引用插入Word(How to Cite a Paper in Word Using Endnote)
- 如何访问Azure上的SharePoint 网站(How to access the SharePoint site of Azure)
- How to get access to edit/get pixel values of Mat in OpenCV
- Preview Word files (docx) in HTML using ASP.NET, OpenXML and LINQ to XML
- How to convert Word table into Excel using OpenXML