TNB Library
TnbOfsWord.h
[詳解]
1#pragma once
11#include "TnbDef.h"
12
13#error
14
15
16#include <comutil.h>
17#ifndef _TnbDOXYGEN //Document作成用シンボル
18//Wordを操作するためのタイプライブラリを読みこむ(Word2000用)
19//#import "C:\Program Files\Microsoft Office\Office\Mso9.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesDOC")
20#import "C:\Program Files\Microsoft Office\Office\MSO9.DLL"
21#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
22#import "C:\Program Files\Microsoft Office\Office\Msword9.olb" rename("ExitWindows", "ExitWindowsDOC")
23#endif // _TnbDOXYGEN
24
25
26//TNB Library
27namespace TNB
28{
29
30
31
33{
34public:
35 void Test(void)
36 {
37 HRESULT hRes = ::CoInitialize(NULL);
38 using namespace Word;
39 _ApplicationPtr pDOC;
40
41 if (0)
42 {
43 //Wordの起動
44 pDOC.CreateInstance(L"Word.Application");
45 pDOC->Visible = TRUE;
46
47 //新規 Word document を追加する
48 DocumentsPtr pDocments = pDOC->GetDocuments();
49 _DocumentPtr pDocment = pDocments->Add();
50
51// ::MessageBox(NULL,"動作確認のために一時停止","",MB_OK);
52
53 //Wordの終了
54 pDOC->Quit();
55 pDOC = NULL;
56 }
57
58 _variant_t v;
59
60 try
61 {
62 //Wordの起動
63 pDOC.CreateInstance(L"Word.Application");
64 pDOC->Visible = TRUE;
65
66 //既存の Word document を開く
67 DocumentsPtr pDocuments = pDOC->GetDocuments();
68// oleFName.SetString(_T("c:\\ななな.doc"),VT_BSTR);
69// _DocumentPtr pDocment = pDocments->OpenOld(oleFName);
70 v.SetString("c:\\ななな.doc");
71 _DocumentPtr pDocument = pDocuments->Open(&v);
72
73// ::MessageBox(NULL,"動作確認のために一時停止","",MB_OK);
74
75
76 pDOC->ActiveDocument->Content->Text = "aaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbb";
77
78 pDocument->Application->Selection->Range->Text = "TEST";
79
80 pDocument->Range(&_variant_t((short)2), &_variant_t((short)6))->Text = "TEST";
81
82 //Tableを作成
83 TablePtr pTable = pDOC->ActiveDocument->Tables->Add(pDocument->Range(),5,6);
84
85 //Tableへ文字を出力
86 pTable->Cell(2,2)->Range->Text = "Test Data";
87
88 //Wordの終了
89 pDOC->Quit();
90 }
91 catch(_com_error& e)
92 {
94 CString s;
95 }
96 catch(...)
97 {
98 CString s;
99 }
100
101 }
102};
103
104
105
106}; // TNB
TNBライブラリの定義ヘッダ
void IgnoreUnusedValue(const T &value)
[宣言] 参照しない値宣言.
Definition: TnbDef.h:434
TNB Library
Definition: TnbDoxyTitle.txt:2