<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>VC操作Word 2000</title><link>http://blog.vckbase.com/yingkou/category/750.html</link><description>学习这部分的东西，靠的是感觉。</description><managingEditor>yingkou的Blog</managingEditor><dc:language>zh-chs</dc:language><generator>.Text Version 0.958.2004.214</generator><item><dc:creator>yingkou的Blog</dc:creator><title>随笔之：VC操作Word系列(四) </title><link>http://blog.vckbase.com/yingkou/archive/2004/11/16/1543.html</link><pubDate>Mon, 15 Nov 2004 20:39:00 GMT</pubDate><guid>http://blog.vckbase.com/yingkou/archive/2004/11/16/1543.html</guid><wfw:comment>http://blog.vckbase.com/yingkou/comments/1543.html</wfw:comment><comments>http://blog.vckbase.com/yingkou/archive/2004/11/16/1543.html#Feedback</comments><slash:comments>20</slash:comments><wfw:commentRss>http://blog.vckbase.com/yingkou/comments/commentRss/1543.html</wfw:commentRss><trackback:ping>http://blog.vckbase.com/yingkou/services/trackbacks/1543.html</trackback:ping><description>&lt;img src ="http://blog.vckbase.com/yingkou/aggbug/1543.html" width = "1" height = "1" /&gt;</description></item><item><dc:creator>yingkou的Blog</dc:creator><title>随笔之：VC操作Word系列(三) </title><link>http://blog.vckbase.com/yingkou/archive/2004/11/10/1426.html</link><pubDate>Wed, 10 Nov 2004 00:43:00 GMT</pubDate><guid>http://blog.vckbase.com/yingkou/archive/2004/11/10/1426.html</guid><wfw:comment>http://blog.vckbase.com/yingkou/comments/1426.html</wfw:comment><comments>http://blog.vckbase.com/yingkou/archive/2004/11/10/1426.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://blog.vckbase.com/yingkou/comments/commentRss/1426.html</wfw:commentRss><trackback:ping>http://blog.vckbase.com/yingkou/services/trackbacks/1426.html</trackback:ping><description>&lt;img src ="http://blog.vckbase.com/yingkou/aggbug/1426.html" width = "1" height = "1" /&gt;</description></item><item><dc:creator>yingkou的Blog</dc:creator><title>随笔之：VC操作Word系列(二) </title><link>http://blog.vckbase.com/yingkou/archive/2004/11/06/1301.html</link><pubDate>Fri, 05 Nov 2004 19:35:00 GMT</pubDate><guid>http://blog.vckbase.com/yingkou/archive/2004/11/06/1301.html</guid><wfw:comment>http://blog.vckbase.com/yingkou/comments/1301.html</wfw:comment><comments>http://blog.vckbase.com/yingkou/archive/2004/11/06/1301.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blog.vckbase.com/yingkou/comments/commentRss/1301.html</wfw:commentRss><trackback:ping>http://blog.vckbase.com/yingkou/services/trackbacks/1301.html</trackback:ping><description>大家都应该使用过Word提供的表格功能很是专业，如果在作一些数据库开发之类的软件对汇总的数据进行打印是常见的功能，这个如果用Word来实现个人感觉不错，废话少说说练咱就练。 &lt;PRE&gt;void CWordTestDlg::TestWord2()&lt;/PRE&gt;&lt;PRE&gt;{&lt;/PRE&gt;&lt;PRE&gt;_Application app;&lt;/PRE&gt;&lt;PRE&gt;COleVariant vTrue((short)TRUE),	vFalse((short)FALSE);&lt;/PRE&gt;&lt;PRE&gt;app.CreateDispatch(_T("Word.Application"));&lt;/PRE&gt;&lt;PRE&gt;app.SetVisible(FALSE);&lt;/PRE&gt;&lt;PRE&gt;//Create New Doc&lt;/PRE&gt;&lt;PRE&gt;Documents docs=app.GetDocuments();&lt;/PRE&gt;&lt;PRE&gt;CComVariant tpl(_T("")),Visble,DocType(0),NewTemplate(false);&lt;/PRE&gt;&lt;PRE&gt;docs.Add(&amp;amp;tpl,&amp;amp;NewTemplate,&amp;amp;DocType,&amp;amp;Visble);&lt;/PRE&gt;&lt;PRE&gt;//Add Content:Text&lt;/PRE&gt;&lt;PRE&gt;Selection sel=app.GetSelection();&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("\t\t\t\t\t\t\t情况汇总\r\n"));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("\t\t\t\t\t\t\t\t----------*******跨国公司\r\n"));&lt;/PRE&gt;&lt;PRE&gt;COleDateTime dt=COleDateTime::GetCurrentTime();&lt;/PRE&gt;&lt;PRE&gt;CString strDT=dt.Format("%Y-%m-%d");&lt;/PRE&gt;&lt;PRE&gt;CString str("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");&lt;/PRE&gt;&lt;PRE&gt;str+=strDT;&lt;/PRE&gt;&lt;PRE&gt;str+="\r\n";&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(str);&lt;/PRE&gt;&lt;PRE&gt;//Add Table&lt;/PRE&gt;&lt;PRE&gt;_Document saveDoc=app.GetActiveDocument();&lt;/PRE&gt;&lt;PRE&gt;Tables tables=saveDoc.GetTables();&lt;/PRE&gt;&lt;PRE&gt;CComVariant defaultBehavior(1),AutoFitBehavior(1);&lt;/PRE&gt;&lt;PRE&gt;tables.Add(sel.GetRange(),6,11,&amp;amp;defaultBehavior,&amp;amp;AutoFitBehavior);&lt;/PRE&gt;&lt;PRE&gt;Table table=tables.Item(1);&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test1"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short&lt;/PRE&gt;(0)));&lt;PRE&gt;&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test2"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test3"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test4"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short&amp;lt;(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test5"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test6"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test7"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test8"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test9"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test10"));&lt;/PRE&gt;&lt;PRE&gt;sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));&lt;/PRE&gt;&lt;PRE&gt;sel.TypeText(_T("Test11"));  &lt;/PRE&gt;&lt;PRE&gt;app.SetVisible(TRUE);&lt;/PRE&gt;&lt;PRE&gt;table.ReleaseDispatch();&lt;/PRE&gt;&lt;PRE&gt;tables.ReleaseDispatch();&lt;/PRE&gt;&lt;PRE&gt;sel.ReleaseDispatch();&lt;/PRE&gt;&lt;PRE&gt;docs.ReleaseDispatch();&lt;/PRE&gt;&lt;PRE&gt;saveDoc.ReleaseDispatch();&lt;/PRE&gt;&lt;PRE&gt;app.ReleaseDispatch();&lt;/PRE&gt;&lt;PRE&gt;}&lt;/PRE&gt;&lt;img src ="http://blog.vckbase.com/yingkou/aggbug/1301.html" width = "1" height = "1" /&gt;</description></item><item><dc:creator>yingkou的Blog</dc:creator><title>随笔之：VC操作Word系列(一)</title><link>http://blog.vckbase.com/yingkou/archive/2004/11/01/1212.html</link><pubDate>Mon, 01 Nov 2004 15:47:00 GMT</pubDate><guid>http://blog.vckbase.com/yingkou/archive/2004/11/01/1212.html</guid><wfw:comment>http://blog.vckbase.com/yingkou/comments/1212.html</wfw:comment><comments>http://blog.vckbase.com/yingkou/archive/2004/11/01/1212.html#Feedback</comments><slash:comments>42</slash:comments><wfw:commentRss>http://blog.vckbase.com/yingkou/comments/commentRss/1212.html</wfw:commentRss><trackback:ping>http://blog.vckbase.com/yingkou/services/trackbacks/1212.html</trackback:ping><description>近日作一个小东西涉及到对汇总结果的打印，由于打印只在一台特定的机器进行所以考虑使用Word来实现，这样比较简单而且很专业。开始的时候这个东西没有这项功能后来我闲的无聊看看是否可以实现(以前从来没有做过这方面的东西)，于是乎搞了一下也不是很难，一点心得大家给指点一二，使用的是Office2000，工程类型是MFC的对话框。
先看看需要使用到的东东：
1.View-&gt;ClassWizard-&gt;Automation-&gt;Add Class From Library:定位到你安装Office的目录找到MSWord9.Olb
2.打开后把所有的类都选中倒入到你的工程(反正也是搞一回彻底一点:P)
3.在你的对话框头文件中加上#include"msword9.h"
  OK了准备工作搞定之后就可以玩儿转Word了,先来一个简单的
&lt;PRE&gt;void TestWord1()&lt;/PRE&gt;
&lt;PRE&gt;{&lt;/PRE&gt;
&lt;PRE&gt; _Application app;&lt;/PRE&gt;
&lt;PRE&gt;COleVariant vTrue((short)TRUE),	vFalse((short)FALSE);&lt;/PRE&gt;
&lt;PRE&gt;app.CreateDispatch(_T("Word.Application"));&lt;/PRE&gt;
&lt;PRE&gt;app.SetVisible(FALSE);&lt;/PRE&gt;
&lt;PRE&gt;//Create New Doc&lt;/PRE&gt;
&lt;PRE&gt;Documents docs=app.GetDocuments();&lt;/PRE&gt;
&lt;PRE&gt;CComVariant tpl(_T("")),Visble,DocType(0),NewTemplate(false);&lt;/PRE&gt;
&lt;PRE&gt;docs.Add(&amp;tpl,&amp;NewTemplate,&amp;DocType,&amp;Visble);&lt;/PRE&gt;
&lt;PRE&gt;//Add Content:Text&lt;/PRE&gt;
&lt;PRE&gt;Selection sel=app.GetSelection();&lt;/PRE&gt;
&lt;PRE&gt;sel.TypeText(_T("\t\t\t\t\t第一次玩儿Word\r\n"));&lt;/PRE&gt;
&lt;PRE&gt;sel.TypeText(_T("\t\t\t\t\t\t\t\t----------先来一个简单的\r\n"));&lt;/PRE&gt;

&lt;PRE&gt;sel.ReleaseDispatch();&lt;/PRE&gt;
&lt;PRE&gt;docs.ReleaseDispatch();&lt;/PRE&gt;
&lt;PRE&gt;app.SetVisible(TRUE);&lt;/PRE&gt;
&lt;PRE&gt;app.ReleaseDispatch();&lt;/PRE&gt;	
&lt;PRE&gt;}&lt;/PRE&gt;&lt;img src ="http://blog.vckbase.com/yingkou/aggbug/1212.html" width = "1" height = "1" /&gt;</description></item></channel></rss>