程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> CLR C++ Set Word CustomDocumentProperties

CLR C++ Set Word CustomDocumentProperties

編輯:C++入門知識

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved