zoukankan      html  css  js  c++  java
  • CLR C++ Set Word CustomDocumentProperties

    1. // WordIssue.cpp : main project file.  
    2.   
    3. #include "stdafx.h"  
    4.   
    5. using namespace System;  
    6. using namespace System::Reflection;  
    7. #define Office Microsoft::Office  
    8. #define Word Office::Interop::Word  
    9. #define Core Office::Core  
    10.   
    11. int main(array<System::String ^> ^args)  
    12. {  
    13.     Word::Application^ wdApp = gcnew Word::Application();  
    14.     wdApp->Visible = true;  
    15.     Object^ missing = Type::Missing;  
    16.     String^% FileName =   
    17.         gcnew String("C:\Users\v-yangxu\Desktop\Work\1212030001.docx");  
    18.     Boolean^% flag = gcnew Boolean(false);  
    19.     Object^ m = Type::Missing;   
    20.     Word::Document^ wdDoc = wdApp->Documents->Open(FileName,m,flag,m,m,m,m,m,  
    21.         m,m,m,m,m,m,m,m);  
    22.     Object^ cps = wdDoc->GetType()->InvokeMember("CustomDocumentProperties",  
    23.         BindingFlags::Default | BindingFlags::GetProperty,  
    24.         nullptr,wdDoc,nullptr);  
    25.     Type^ type = cps->GetType();  
    26.     array<Object^>^ oargs = {"MyAttribute",false,  
    27.         Core::MsoDocProperties::msoPropertyTypeString,"Just a test"};  
    28.     try{  
    29.         type->InvokeMember("Add",  
    30.             BindingFlags::Default | BindingFlags::InvokeMethod, nullptr,   
    31.             cps, oargs );  
    32.     }catch(Exception^ ex){  
    33.         Console::WriteLine(ex->Message);  
    34.     }  
    35.     Console::ReadKey();  
    36.     return 0;  
    37. }  
  • 相关阅读:
    Emoji表情编解码库XXL-EMOJI
    代码生成平台Xxl-Code-Generator
    分布式单点登录框架XXL-SSO
    分布式爬虫框架XXL-CRAWLER
    Java对象和Excel转换工具XXL-EXCEL
    API管理平台XXL-API
    分布式缓存管理平台XXL-CACHE
    不知不觉已经写了多年代码,贴一下12年写的代码,表喷哈
    memcached安装、使用
    MySQL和Redis数据一致性问题
  • 原文地址:https://www.cnblogs.com/Alex80/p/4349775.html
Copyright © 2011-2022 走看看