Thread: C# основной форум/C# app: Reading and modifying MS Office document meta data

C# app: Reading and modifying MS Office document meta data

bytes.com/topic/c-sharp/answers/757466-c-app-reading-modifying-ms-office-document-meta-data



        
  1. object GetWordDocumentPropertyValue(Word.Document document, string propertyName)

  2.     
  3. {

  4.     
  5.   object builtInProperties = document.BuiltInDocumentProperties;

  6.     
  7.   Type builtInPropertiesType = builtInProperties.GetType();

  8.     
  9.   object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

  10.     
  11.   Type propertyType = property.GetType();

  12.     
  13.   object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });

  14.     
  15.   return propertyValue;

  16.     
  17. }

  18.     
  19.  

  20.     
  21. object GetExcelWorkbookPropertyValue(Excel.Workbook workbook, string propertyName)

  22.     
  23. {

  24.     
  25.   object builtInProperties = workbook.BuiltinDocumentProperties;

  26.     
  27.   Type builtInPropertiesType = builtInProperties.GetType();

  28.     
  29.   object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

  30.     
  31.   Type propertyType = property.GetType();

  32.     
  33.   object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });

  34.     
  35.   return propertyValue;

  36.     
  37. }

  38.     
  39.  

  40.     
  41. object GetPowerPointPresentationPropertyValue(PowerPoint.Presentation presentation, string propertyName)

  42.     
  43. {

  44.     
  45.   object builtInProperties = presentation.BuiltInDocumentProperties;

  46.     
  47.   Type builtInPropertiesType = builtInProperties.GetType();

  48.     
  49.   object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

  50.     
  51.   Type propertyType = property.GetType();

  52.     
  53.   object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });

  54.     
  55.   return propertyValue;

  56.     
  57. }

  58.     
  59.  

  60.     
  61. void SetWordDocumentPropertyValue(Word.Document document, string propertyName, string propertyValue)

  62.     
  63. {

  64.     
  65.   object builtInProperties = document.BuiltInDocumentProperties;

  66.     
  67.   Type builtInPropertiesType = builtInProperties.GetType();

  68.     
  69.   object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

  70.     
  71.   Type propertyType = property.GetType();

  72.     
  73.   propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue });

  74.     
  75.   document.UpdateSummaryProperties();

  76.     
  77.   document.Save();

  78.     
  79. }

  80.     
  81.  

  82.     
  83. void SetExcelWorkbookPropertyValue(Excel.Workbook workbook, string propertyName, string propertyValue)

  84.     
  85. {

  86.     
  87.   object builtInProperties = workbook.BuiltinDocumentProperties;

  88.     
  89.   Type builtInPropertiesType = builtInProperties.GetType();

  90.     
  91.   object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

  92.     
  93.   Type propertyType = property.GetType();

  94.     
  95.   propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue });

  96.     
  97.   workbook.Save();

  98.     
  99. }

  100.     
  101.  

  102.     
  103. void SetPowerPointPresentationPropertyValue(PowerPoint.Presentation presentation, string propertyName, string propertyValue)

  104.     
  105. {

  106.     
  107.   object builtInProperties = presentation.BuiltInDocumentProperties;

  108.     
  109.   Type builtInPropertiesType = builtInProperties.GetType();

  110.     
  111.   object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

  112.     
  113.   Type propertyType = property.GetType();

  114.     
  115.   propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue });

  116.     
  117.   presentation.Save();

  118.     
  119. }


 





Re: C# app: Reading and modifying MS Office document meta data

Understanding the Word Object Model from a .NET Developer's Perspective


msdn.microsoft.com/en-us/library/aa192495(office.11).aspx





Re: C# app: Reading and modifying MS Office document meta data

2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies


www.microsoft.com/downloads/details.aspx





Re: C# app: Reading and modifying MS Office document meta data

PIA for office 2003:


www.microsoft.com/downloads/details.aspx





Re: C# app: Reading and modifying MS Office document meta data
Office Primary Interop Assemblies

msdn.microsoft.com/en-us/library/15s06t57.aspx





Re: C# app: Reading and modifying MS Office document meta data

www.java2s.com/Code/CSharp/Office/ModifyWordDocumentProperties.htm


using System;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Reflection;

using Word;





namespace Client.Chapter_19___Office_Integration

{

  public class ModifyDocumentProperties

  {

    [STAThread]

    static void Main(string[] args)

    {

      object Missing = Missing.Value;

      object BuiltInProps;

      object CustomProps;

      Word._Document Doc;

      Word.ApplicationClass MyWord = new Word.ApplicationClass();



      MyWord.Visible = true;

      Doc = MyWord.Documents.Add(ref Missing, ref Missing, ref Missing, ref Missing);

      BuiltInProps = Doc.BuiltInDocumentProperties;



      Type TypeBuiltingProp = BuiltInProps.GetType();



      //Setting abuilt-in property

      string Prop = "Author";

      string PropValue;

      object AuthorProp = TypeBuiltingProp.InvokeMember("item", BindingFlags.Default | BindingFlags.GetProperty, null, BuiltInProps, new Object[] { Prop });

      Type TypeAuthorProp = AuthorProp.GetType();



      PropValue = TypeAuthorProp.InvokeMember("Value", BindingFlags.Default | BindingFlags.GetProperty, null, AuthorProp, new Object[]{}).ToString();

      System.Windows.Forms.Application.Run();

    }

  }



}


 





Re: C# app: Reading and modifying MS Office document meta data

Considerations for server-side Automation of Office


support.microsoft.com/default.aspx





Re: C# app: Reading and modifying MS Office document meta data

The Dsofile.dll files lets you edit Office document properties when you do not have Office installed


support.microsoft.com/kb/224351


blogs.msdn.com/vsod/archive/2009/06/30/word-2003-excel-2003-vsto-customization-added-using-serverdocument-addcustomization-method-does-not-add-customization-if-your-document-contained-an-embedded-vsto-customized-document-workbook.aspx


 


 

-- 27/08/2009 12:29:02: post edited by sergey.





Re: C# app: Reading and modifying MS Office document meta data

Microsoft Developer Support OLE File Property Reader 2.1 Sample (KB 224351)


www.microsoft.com/downloads/details.aspx