• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
KXLF’s blog
能转的不写
   首页    新随笔    联系   管理     

[转]how to programatically access built-in 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();
posted @ 2011-11-02 17:35  KXLF  阅读(406)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3