// WordIssue. cpp: main project file.
# Include "stdafx. h"
Using namespace System;
Using namespace System: Reflection;
# Define Office Microsoft: Office
# Define Word Office: Interop: Word
# Define Core Office: Core
Int main (array <System: String ^> ^ args)
{
Word: Application ^ wdApp = gcnew Word: Application ();
WdApp-> Visible = true;
Object ^ missing = Type: Missing;
String ^ % FileName =
Gcnew String ("C :\\ Users \ v-yangxu \ Desktop \ Work \ 1212030001.docx ");
Boolean ^ % flag = gcnew Boolean (false );
Object ^ m = Type: Missing;
Word: Document ^ wdDoc = wdApp-> Documents-> Open (FileName, m, flag, m,
M, m );
Object ^ cps = wdDoc-> GetType ()-> InvokeMember ("CustomDocumentProperties ",
BindingFlags: Default | BindingFlags: GetProperty,
Nullptr, wdDoc, nullptr );
Type ^ type = cps-> GetType ();
Array <Object ^> ^ oargs = {"MyAttribute", false,
Core: MsoDocProperties: msoPropertyTypeString, "Just a test "};
Try {www.2cto.com
Type-> InvokeMember ("Add ",
BindingFlags: Default | BindingFlags: InvokeMethod, nullptr,
Cps, oargs );
} Catch (Exception ^ ex ){
Console: WriteLine (ex-> Message );
}
Console: ReadKey ();
Return 0;
}