??xml version="1.0" encoding="utf-8" standalone="yes"?>
_ApplicationPtr word_app;
HRESULT hr = word_app.CreateInstance("Word.Application", NULL);
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
DocumentsPtr docs;
_DocumentPtr oDoc;
docs = word_app->GetDocuments();
doc = docs->Add(vOpt, vOpt, vOpt, vOpt);
PageSetupPtr page_setup = doc->GetPageSetup();
page_setup->PutTopMargin(0);
page_setup->PutBottomMargin(0);
page_setup->PutRightMargin(0);
page_setup->PutLeftMargin(0);
SelectionPtr selection;
selection = word_app->GetSelection();
_ParagraphFormatPtr parafmt = selection->GetParagraphFormat();
parafmt->PutLineSpacingRule(wdLineSpaceExactly);
parafmt->PutLineSpacing(50);
_FontPtr font;
font = oSel->GetFont();
font->PutBold(1);
font->PutColor(wdColorGreen);
font->PutSize(20);
font->PutName(_T("宋体"));
selection->TypeText("ABC");
oSel->TypeParagraph();
oSel->TypeText("12345678901234567890");
oSel->TypeParagraph();
ShapesPtr shapes = doc->GetShapes();
ShapePtr textbox = shapspp->AddTextbox(Office::msoTextOrientationHorizontal, 1, 1, 100, 100);
ShapesPtr shapes = doc->GetShapes();
2
ShapePtr textbox = shapspp->AddTextbox(Office::msoTextOrientationHorizontal, 1, 1, 100, 100);
3
TextFramePtr textframe = textbox->GetTextFrame();
4
RangePtr range = textframe->GetTextRange();
5
long insert_before_count = range->Characters->GetCount();
6
range->InsertAfter("TEXT");
7
if (insert_before_count != 1)
8
range->MoveStart(COleVariant((long)Word::wdCharacter), COleVariant(insert_before_count-1));
9
if(range != 0)
10

{
11
_FontPtr font = range->GetFont();
12
font->PutBold(isBold);
13
font->PutItalic(isItalic);
14
font->PutColor((Word::WdColor)FontColor());
15
font->PutSize(FontSize);
16
font->PutName(FontType().c_str());
17
}
textbox->GetTextFrame()->PutAutoSize(Office::msoAutoShape);
2
textbox->GetTextFrame()->PutMarginBottom(0);
3
textbox->GetTextFrame()->PutMarginTop(0);
4
textbox->GetTextFrame()->PutMarginLeft(0);
5
textbox->GetTextFrame()->PutMarginRight(0);
6
textbox->GetLine()->PutVisible(Office::msoFalse);
7
textbox->GetFill()->PutTransparency(1);
ShapesPtr shapes = m_WordDoc->GetShapes();
2
InlineShapesPtr inline_shapes = selection_doc->GetRange()->GetInlineShapes();
3
InlineShapePtr inline_shape = inline_shapes->AddPicture(“picture_path”, COleVariant((long)0), COleVariant((long)1));
4
ShapePtr shape = inline_shape->ConvertToShape();
5
shape->PutWidth(width);
6
shape->PutHeight(hehight());
7
shape->PutTop(Y);
8
shape->PutLeft(X);
9
if(shape->GetType() == Office::msoPicture)
10

{
11
Word::WrapFormatPtr wrapp = shape->GetWrapFormat();
12
wrapp->PutType(Word::wdWrapBehind);
13
}
14
ShapesPtr shapes = doc->GetShapes();
2
Word::ShapePtr line = shapes->AddLine(x1,y1, x2,y2);
3
if (line->GetType() == Office::msoLine)
4

{
5
Word::LineFormatPtr LineFmt = line->GetLine();
6
LineFmt->PutWeight(lr->weight_);
7
}
selection->InsertBreak(COleVariant((long)wdColumnBreak));
selection->InsertBreak(COleVariant((long)wdSectionBreakContinuous));
selection->InsertBreak(COleVariant((long)wdPageBreak));
?1】设|栏目个数和栏目的宽?br>q里一定要注意add函数的逻辑
SectionsPtr word_sections = doc->GetSections();
2
long num = word_sections->GetCount();
3
SectionPtr word_section = word_sections->Item(num-1);
4
PageSetupPtr page_setup = word_section->GetPageSetup();
5
TextColumnsPtr text_cols = page_setup>GetTextColumns();
6
text_cols->PutEvenlySpaced(0);
7
text_cols->Add(COleVariant(col_width), COleVariant((long)0), COleVariant((long)false));
TablesPtr tables = oSel->GetTables();
2
TablePtr table = tables->Add(oSel->GetRange(), 2, 5);
3
4
BordersPtr bords = table->GetBorders();
5
bords->PutOutsideLineStyle(wdLineStyleSingle);
6
bords->PutInsideLineStyle(wdLineStyleSingle);
7
for (int i = 1; i<=2; i++)
8

{
9
for (int j = 1; j<=5; j++)
10
{
11
table->Cell(i,j)->GetRange()->PutText("20");
12
}
13
}
14
15
CellPtr cell = table->Cell(1,1);
16
cell->Merge(table->Cell(1,2));
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
2
_DocumentPtr active_doc;
3
active_doc = word_app->GetActiveDocument();
4
active_doc->SaveAs(COleVariant("D:\\doc1.doc"),
5
COleVariant((short)0),
6
vFalse, COleVariant(""), vTrue, COleVariant(""),
7
vFalse, vFalse, vFalse, vFalse, vFalse);
8
word_app->Quit(vOpt, vOpt, vOpt);
]]>
2 typedef x _ComMapClass; \
3 static HRESULT WINAPI _Cache(void* pv, REFIID iid, void** ppvObject, DWORD_PTR dw) throw()\
4 {\
5 _ComMapClass* p = (_ComMapClass*)pv;\
6 p->Lock();\
7 HRESULT hRes = E_FAIL; \
8 __try \
9 { \
10 hRes = ATL::CComObjectRootBase::_Cache(pv, iid, ppvObject, dw);\
11 } \
12 __finally \
13 { \
14 p->Unlock();\
15 } \
16 return hRes;\
17 }\
18 IUnknown* _GetRawUnknown() throw() \
19 { ATLASSERT(_GetEntries()[0].pFunc == _ATL_SIMPLEMAPENTRY); return (IUnknown*)((INT_PTR)this+_GetEntries()->dw); } \
20 _ATL_DECLARE_GET_UNKNOWN(x)\
21 HRESULT _InternalQueryInterface(REFIID iid, void** ppvObject) throw() \
22 { return InternalQueryInterface(this, _GetEntries(), iid, ppvObject); } \
23 const static ATL::_ATL_INTMAP_ENTRY* WINAPI _GetEntries() throw() { \
24 static const ATL::_ATL_INTMAP_ENTRY _entries[] = { DEBUG_QI_ENTRY(x)
25
26 #ifdef _ATL_DEBUG
27 #define DEBUG_QI_ENTRY(x) \
28 {NULL, \
29 (DWORD_PTR)_T(#x), \
30 (ATL::_ATL_CREATORARGFUNC*)0},
31 #else
32 #define DEBUG_QI_ENTRY(x)
33 #endif //_ATL_DEBUG
34
35 #define COM_INTERFACE_ENTRY_IMPL(x)\
36 COM_INTERFACE_ENTRY_IID(_ATL_IIDOF(x), x##Impl<_ComMapClass>)
37
38 #define _ATL_IIDOF(x) __uuidof(x)
39
40 #define COM_INTERFACE_ENTRY_IID(iid, x)\
41 {&iid,\
42 offsetofclass(x, _ComMapClass),\
43 _ATL_SIMPLEMAPENTRY},
44
45 #define offsetofclass(base, derived) ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)
46
47 #define _ATL_SIMPLEMAPENTRY ((ATL::_ATL_CREATORARGFUNC*)1)
48
49 #define COM_INTERFACE_ENTRY(x)\
50 {&_ATL_IIDOF(x), \
51 offsetofclass(x, _ComMapClass), \
52 _ATL_SIMPLEMAPENTRY},
53
54 #define END_COM_MAP() \
55 __if_exists(_GetAttrEntries) {{NULL, (DWORD_PTR)_GetAttrEntries, _ChainAttr }, }\
56 {NULL, 0, 0}}; return &_entries[1];} \
57 virtual ULONG STDMETHODCALLTYPE AddRef( void) throw() = 0; \
58 virtual ULONG STDMETHODCALLTYPE Release( void) throw() = 0; \
59 STDMETHOD(QueryInterface)(REFIID, void**) throw() = 0;
60 #else
61 #define END_COM_MAP() \
62 __if_exists(_GetAttrEntries) {{NULL, (DWORD_PTR)_GetAttrEntries, _ChainAttr }, }\
63 {NULL, 0, 0}}; return _entries;} \
64 virtual ULONG STDMETHODCALLTYPE AddRef( void) throw() = 0; \
65 virtual ULONG STDMETHODCALLTYPE Release( void) throw() = 0; \
66 STDMETHOD(QueryInterface)(REFIID, void**) throw() = 0;
67 #endif // _ATL_DEBUG
68
69
70 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
71 class d
72 {
73 public:
74 d(){}
75 typedef x _ComMapClass;
76 static HRESULT WINAPI _Cache(void* pv, REFIID iid, void** ppvObject, DWORD_PTR dw) throw()\
77 {
78 _ComMapClass* p = (_ComMapClass*)pv;
79 p->Lock();
80 HRESULT hRes = E_FAIL;
81 __try
82 {
83 hRes = ATL::CComObjectRootBase::_Cache(pv, iid, ppvObject, dw);
84 }
85 __finally
86 {
87 p->Unlock();
88 }
89 return hRes;
90 }
91 IUnknown* _GetRawUnknown() throw()
92 { ATLASSERT(_GetEntries()[0].pFunc == _ATL_SIMPLEMAPENTRY); return (IUnknown*)((INT_PTR)this+_GetEntries()->dw); }
93 _ATL_DECLARE_GET_UNKNOWN(x)
94 HRESULT _InternalQueryInterface(REFIID iid, void** ppvObject) throw()
95 { return InternalQueryInterface(this, _GetEntries(), iid, ppvObject); }
96 const static ATL::_ATL_INTMAP_ENTRY* WINAPI _GetEntries() throw()
97 {
98 static const ATL::_ATL_INTMAP_ENTRY _entries[] =
99 {
100 {NULL, (DWORD_PTR)_T(#x), (ATL::_ATL_CREATORARGFUNC*)0},
101 {&iid, ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING), ((ATL::_ATL_CREATORARGFUNC*)1)},
102 {&__uuidof(x), ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING), ((ATL::_ATL_CREATORARGFUNC*)1)},
103 __if_exists(_GetAttrEntries) {{NULL, (DWORD_PTR)_GetAttrEntries, _ChainAttr }, }
104 {NULL, 0, 0}
105 };
106 return &_entries[1];
107 }
108 virtual ULONG STDMETHODCALLTYPE AddRef( void) throw() = 0;
109 virtual ULONG STDMETHODCALLTYPE Release( void) throw() = 0;
110 STDMETHOD(QueryInterface)(REFIID, void**) throw() = 0;
111 }
]]>