• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            JACKY_ZZ[貓貓愛吃魚]

            春風(fēng)拂面兩頰紅,秋葉灑地一片金。 夏荷搖曳一身輕,冬雪覆蓋大地銀。
            posts - 30, comments - 123, trackbacks - 0, articles - 0

            [C/C++] vole使用的簡單例子

            Posted on 2010-12-07 11:02 jacky_zz 閱讀(421) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            stdafx.h
             1 #pragma once
             2 
             3 #include "targetver.h"
             4 
             5 #include <stdio.h>
             6 #include <tchar.h>
             7 #include <windows.h>
             8 #include <string>
             9 
            10 #include <vole/vole.hpp>
            11 #include <comstl/util/initialisers.hpp>
            12 
            13 using vole::object;
            14 using vole::collection;
            vword.cpp
              1#include "stdafx.h"
              2
              3#define HINT _T("please provide a xml file first.\n") \
              4    _T("format is:\n") \
              5    _T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n") \
              6    _T("<bookmarks>\n") \
              7    _T("\t<bookmark name=\"\" value=\"\"/>\n") \
              8    _T("\t\n") \
              9    _T("\t<bookmark name=\"\" value=\"\"/>\n") \
             10    _T("</bookmarks>") \
             11
             12int _tmain(int argc, _TCHAR* argv[])
             13{
             14    if(argc != 2)
             15    {
             16        MessageBox(GetActiveWindow(), HINT, _T("Error"), MB_OK | MB_ICONERROR);
             17        return 0;
             18    }

             19
             20    wchar_t filename[MAX_PATH];
             21
             22#ifdef _UNICODE
             23    // wcscpy_s(filename, MAX_PATH, _T("./1.xml"));
             24    wcscpy_s(filename, MAX_PATH, argv[1]);
             25#else
             26    MultiByteToWideChar(CP_ACP, 0, argv[1], strlen(argv[1]), filename, MAX_PATH);
             27#endif
             28
             29    // initialization vole
             30    comstl::com_init init;
             31
             32    // create xml DOM object
             33    object xml = object::create("Msxml2.DOMDocument");
             34    bool success = xml.invoke_method<bool>(L"load", filename);
             35    if(!success)
             36        return 0;
             37
             38    // get root element
             39    object documentElement = xml.get_property<object>(L"documentElement");
             40
             41    // get child nodes of root element
             42    object childNodes = documentElement.get_property<object>(L"childNodes");
             43    long length = childNodes.get_property<long>(L"length");
             44
             45    // create word automation object
             46    object word = object::create("Word.Application", CLSCTX_LOCAL_SERVER, vole::coercion_level::naturalPromotion);
             47    word.put_property(L"Visible"false);
             48
             49    // open local word file
             50    collection documents = word.get_property<collection>(L"Documents");
             51    object document = documents.invoke_method<object>(L"Open", L"C:\\1.doc");
             52
             53    // retrieve bookmarks in opened document
             54    collection bookmarks = document.get_property<collection>(L"Bookmarks");
             55    int count = bookmarks.get_property<int>(L"Count");
             56
             57    // starting find bookmark, insert value after bookmark if found
             58    for(long i = 0; i < length; i++)
             59    {
             60        object node = childNodes.get_property<object>(L"item", i);
             61        object attributes = node.get_property<object>(L"attributes");
             62        long attribute_length = attributes.get_property<long>(L"length");
             63
             64        object node1 = attributes.invoke_method<object>(L"getNamedItem", L"name");
             65        object node2 = attributes.invoke_method<object>(L"getNamedItem", L"value");
             66
             67        std::string value1 = node1.get_property<std::string>(L"nodeValue");
             68        std::string value2 = node2.get_property<std::string>(L"nodeValue");
             69
             70        for(int j = 1; j <= count; j++)
             71        {
             72            object bookmark = bookmarks.invoke_method<object>(L"Item", j);
             73            std::string name = bookmark.get_property<std::string>(L"Name");
             74
             75            char* name1 = const_cast<char*>(name.c_str());
             76            char* name2 = const_cast<char*>(value1.c_str());
             77
             78            if(strcmp(name1, name2) == 0)
             79            {
             80                char* value = const_cast<char*>(value2.c_str());
             81                size_t len = strlen(value);
             82
             83                wchar_t* w_value = (wchar_t*)malloc(len * 2 + 1);
             84                MultiByteToWideChar(CP_ACP, 0, value, len, w_value, len);
             85
             86                object range = bookmark.get_property<object>(L"Range");
             87                range.invoke_method_v(L"InsertAfter", (LPCWSTR)w_value);
             88
             89                free(w_value);
             90                w_value = NULL;
             91                value = NULL;
             92
             93                break;
             94            }

             95
             96            name1 = NULL;
             97            name2 = NULL;
             98        }

             99    }

            100
            101    document.invoke_method_v(L"Save");
            102    document.invoke_method_v(L"Close"false);
            103    word.invoke_method_v(L"Quit");
            104
            105    system("pause");
            106    return 0;
            107}
            久久久无码精品亚洲日韩软件| 91精品国产91久久久久久蜜臀| 亚洲国产高清精品线久久| 午夜福利91久久福利| 国产成年无码久久久免费| 久久精品天天中文字幕人妻 | 久久精品人人做人人爽97| 欧美久久综合性欧美| 亚洲国产成人久久综合区| 久久夜色精品国产噜噜亚洲AV| 亚洲国产成人久久精品影视| 久久久久国产精品嫩草影院| 久久精品国产只有精品2020| 一本色道久久99一综合| 99久久国产综合精品网成人影院 | 91精品国产综合久久婷婷| 久久久WWW免费人成精品| www.久久热| 日韩久久久久久中文人妻| 久久久国产一区二区三区| 97久久精品人妻人人搡人人玩| 思思久久精品在热线热| 亚洲国产成人久久综合区| 久久久久女人精品毛片| 狠狠精品干练久久久无码中文字幕| 久久久久久久综合狠狠综合| 99热热久久这里只有精品68| aaa级精品久久久国产片| 久久亚洲精品国产精品| 国产成人精品综合久久久久| 色欲综合久久躁天天躁| 亚洲精品国产综合久久一线| 久久亚洲精品无码播放| 国产午夜电影久久| 四虎国产精品成人免费久久| 久久综合伊人77777麻豆| 久久婷婷五月综合色99啪ak| 免费精品久久久久久中文字幕| 一本久久免费视频| 久久天天躁狠狠躁夜夜2020一 | 东方aⅴ免费观看久久av|