VC操作Word系列(三)
来源:互联网 发布:重复测量数据分析 编辑:程序博客网 时间:2024/05/17 01:38
上一篇说了如何制作一个简单的表格,在实际应用中会发现表格的种类很多其中对于单元格要求合并的情形很多,这样出来的表格比较专业让客户看起来也很是舒服,不喔喔了看看下面的代码就全明白了。
void CWordTestDlg::TestWord3()
{
_Application app;
COleVariant vTrue((short)TRUE), vFalse((short)FALSE);
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(FALSE);
//Create New Doc
Documents docs=app.GetDocuments();
CComVariant tpl(_T("")),Visble,DocType(0),NewTemplate(false);
docs.Add(&tpl,&NewTemplate,&DocType,&Visble);
//Add Content:Text
Selection sel=app.GetSelection();
sel.TypeText(_T("/t/t/t/t/t/t/t情况汇总/r/n"));
sel.TypeText(_T("/t/t/t/t/t/t/t/t----------*******跨国公司/r/n"));
COleDateTime dt=COleDateTime::GetCurrentTime();
CString strDT=dt.Format("%Y-%m-%d");
CString str("/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t");
str+=strDT;
str+="/r/n";
sel.TypeText(str);
//Add Table
_Document saveDoc=app.GetActiveDocument();
Tables tables=saveDoc.GetTables();
CComVariant defaultBehavior(1),AutoFitBehavior(1);
tables.Add(sel.GetRange(),7,11,&defaultBehavior,&AutoFitBehavior);
Table table=tables.Item(1);
sel.TypeText(_T("Test1"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test2"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test3"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test4"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test5"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test6"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test7"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test8"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test9"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test10"));
sel.MoveRight(COleVariant((short)1),COleVariant(short(1)),COleVariant(short(0)));
sel.TypeText(_T("Test11"));
for(int i=2;i<7;i+=2)
{
Cell c1=table.Cell(i,1);
Cell c2=table.Cell(i+1,1);
c1.Merge(c2);
c1.ReleaseDispatch();
c2.ReleaseDispatch();
}
app.SetVisible(TRUE);
table.ReleaseDispatch();
tables.ReleaseDispatch();
sel.ReleaseDispatch();
docs.ReleaseDispatch();
saveDoc.ReleaseDispatch();
app.ReleaseDispatch();
app.SetVisible(TRUE);
}
运行一下看看合并的效果如何:)
- VC操作Word系列(三)
- VC操作Word系列
- VC操作Word系列
- VC操作Word系列(一)
- VC操作Word系列(二)
- VC操作Word系列(四)
- VC操作Word之(三)
- VC操作操作Word
- vc++操作word
- vc++操作word
- vc中操作WORD
- VC++中操作word
- 用VC操作word
- vc操作word读写
- VC操作word
- VC操作word
- VC操作word
- 用VC操作WORD
- 实体类中做数据验证
- 关于工作与生活--孙振耀
- VC操作Word系列(二)
- DB2 命令行处理器(CLP)中的常用命令
- XHTML CSS 常见问题和解决方案
- VC操作Word系列(三)
- 为 CodeIgniter 增加第三方类库-smarty
- VC操作Word系列(四)
- 窗口之间的传值以及子窗体中实现对其父窗体的刷新
- MSWORD常量定义
- 利用SQL Server 2000 技能来学习 DB2 V8
- Criteria和DetachedCriteria 的区别及运用(1)转
- IoC与DI
- 开始