// 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; }
原文链接: https://www.cnblogs.com/mksword/archive/2012/12/04/3934023.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/71460
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!