CLR C++ Set Word CustomDocumentProperties
// 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,m,m, m,m,m,m,m,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{ type->InvokeMember("Add", BindingFlags::Default | BindingFlags::InvokeMethod, nullptr, cps, oargs ); }catch(Exception^ ex){ Console::WriteLine(ex->Message); } Console::ReadKey(); return 0; }
征诛志异,三让两家王朝;功同开辟,一桮万古江南。