zoukankan      html  css  js  c++  java
  • [转]how to programatically access builtin properties of open xml word doc(如何读取open xml格式文档属性)

     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();
  • 相关阅读:
    jedisPool.returnBrokenResource 弃用
    错误,各种错误
    Spring加载resource时classpath*:与classpath:的区别
    Embedded database support
    IDEA 中 显示 *.properties 为中文
    Key promoter IDEA 快捷键 提示 插件
    Win7系统怎么删除今日热点【系统天地】
    win10深度清理c盘垃圾的方法【系统天地】
    win7系统如何清理注册表残留
    win10系统文件无法复制到u盘怎么办【系统天地】
  • 原文地址:https://www.cnblogs.com/kxlf/p/2233365.html
Copyright © 2011-2022 走看看