当前位置:软件学习 > Word >>

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{   www.zzzyk.com
  type->InvokeMember("Add",
   BindingFlags::Default | BindingFlags::InvokeMethod, nullptr,
   cps, oargs );
    }catch(Exception^ ex){
        Console::WriteLine(ex->Message);
    }
    Console::ReadKey();
    return 0;
}

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,