请问如何利用VC操作word插入表格啊 同上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 _Application m_App; //定义Word提供的应用程序对象; Documents m_Docs; //定义Word提供的文档对象; Selection m_Sel; //定义Word提供的选择对象; _Document m_ActiveDoc; //定义word提供的活动对象 m_Docs.ReleaseDispatch(); m_Sel.ReleaseDispatch(); m_App.ReleaseDispatch(); m_App.m_bAutoRelease = true; if(!m_App.CreateDispatch("Word.Application")) { AfxMessageBox("创建Word2000服务失败!"); exit(1); } strFilePath = strWholePathName+"word\\report.doc"; //定义VARIANT变量; COleVariant varFilePath(strFilePath); COleVariant varstrNull(""); COleVariant varZero((short)0); COleVariant varTrue(short(1),VT_BOOL); COleVariant varFalse(short(0),VT_BOOL); COleVariant vTrue((short)TRUE), vFalse((short)FALSE), vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR); m_Docs.AttachDispatch(m_App.GetDocuments());//将Documents类对象m_Docs和Idispatch接口关联起来; m_Docs.Open(varFilePath,varFalse,varFalse,varFalse,varstrNull, varstrNull,varFalse,varstrNull,varstrNull,varTrue,varTrue,varTrue); //打开Word文档; m_Sel.AttachDispatch(m_App.GetSelection());//将Selection类对象m_Sel和Idispatch接口关联起来; m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(4)),COleVariant(short(0))); for(i=0;i<m_list.GetCount();i++) { pos = m_list.FindIndex(i); m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(1)),COleVariant(short(0))); m_Sel.TypeText(itoa(i+1,buf,10)); m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(1)),COleVariant(short(0))); m_Sel.TypeText(pMangData->strName); m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(1)),COleVariant(short(0))); m_Sel.TypeText(itoa(pMangData->nCount,buf,10)); } //保存文件 m_ActiveDoc = m_App.GetActiveDocument(); strSavePath=strWholePathName+"word\\1.doc"; m_ActiveDoc.SaveAs(COleVariant(strSavePath), COleVariant((short)0), vFalse, COleVariant(""), vTrue, COleVariant(""), vFalse, vFalse, vFalse, vFalse, vFalse); m_Docs.ReleaseDispatch(); m_Sel.ReleaseDispatch(); //退出WORD m_App.Quit(vOpt, vOpt, vOpt); m_App.ReleaseDispatch(); //打开文档 strExePath=_T("D:\\Microsoft Office\\Office\\Winword.exe "); strExePath+=strWholePathName; strExePath+="word\\1.doc"; WinExec(strExePath,SW_SHOW); _Application app; app.CreateDispatch(_T("Word.Application")); app.SetVisible(TRUE); Documents docs=app.GetDocuments(); CComVariant Template(_T("")); //不使用WORD的文档模板 CComVariant NewTemplate(false),DocumentType(0),Visible; _Document doc = docs.Add(&Template,&NewTemplate,&DocumentType,&Visible); //绘制5*6的表格 CComVariant vFalse(false),vTrue(true); Tables tables = doc.GetTables(); _Table table = tables.Add(sel.GetRange(),5,6,&vTrue,&vFalse); //往表格填充文字 .................... //释放资源 table.ReleaseDispatch(); tables.ReleaseDispatch(); doc.ReleaseDispatch(); docs.ReleaseDispatch(); CComVariant SaveChanges(false),OriginalFormat,RouteDocument; app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument); app.ReleaseDispatch(); 插入图片COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);COleVariant varTrue(short(1),VT_BOOL);COleVariant varFalse(short(0),VT_BOOL);InlineShapes shapes = doc.GetInlineShapes();_InlineShape shape = shapes.AddPicture("c:\\001.jpg",&varTrue,&varTrue,covOptional); send发送数据溢出了,求大神解释 调用.exe文件的问题 唉,今天才发觉自己一直被玩。 进程的窗体 请大家帮忙看看下面的代码是哪的问题,多谢! 请高手指点为何ADO连接Excel后无法再连接ACCESS!!! 各位大虾,来说说看,联众是如何实现的? 怎么在程序中知道当前系统用的时大字体,还是小字体阿? 按 WEB 页方式查看文件夹的时候,回收站等文件夹的左边通常都有一些按钮、链接和图片,请问这是如何做的? 谁用过 世纪飞扬 仪表控件 请教一个关于CListCtrl的问题 在CScrollView视图中滚动屏幕后,如何让屏幕上的内容不消失!急,在线等
Documents m_Docs; //定义Word提供的文档对象;
Selection m_Sel; //定义Word提供的选择对象;
_Document m_ActiveDoc; //定义word提供的活动对象
m_Docs.ReleaseDispatch();
m_Sel.ReleaseDispatch();
m_App.ReleaseDispatch();
m_App.m_bAutoRelease = true;
if(!m_App.CreateDispatch("Word.Application"))
{
AfxMessageBox("创建Word2000服务失败!");
exit(1);
}
strFilePath = strWholePathName+"word\\report.doc";
//定义VARIANT变量;
COleVariant varFilePath(strFilePath);
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL); COleVariant vTrue((short)TRUE), vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
m_Docs.AttachDispatch(m_App.GetDocuments());//将Documents类对象m_Docs和Idispatch接口关联起来;
m_Docs.Open(varFilePath,varFalse,varFalse,varFalse,varstrNull,
varstrNull,varFalse,varstrNull,varstrNull,varTrue,varTrue,varTrue);
//打开Word文档;
m_Sel.AttachDispatch(m_App.GetSelection());//将Selection类对象m_Sel和Idispatch接口关联起来;
m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(4)),COleVariant(short(0)));
for(i=0;i<m_list.GetCount();i++)
{
pos = m_list.FindIndex(i);
m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(1)),COleVariant(short(0)));
m_Sel.TypeText(itoa(i+1,buf,10));
m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(1)),COleVariant(short(0)));
m_Sel.TypeText(pMangData->strName);
m_Sel.MoveDown(COleVariant(short(4)),COleVariant(short(1)),COleVariant(short(0)));
m_Sel.TypeText(itoa(pMangData->nCount,buf,10));
}
//保存文件
m_ActiveDoc = m_App.GetActiveDocument();
strSavePath=strWholePathName+"word\\1.doc";
m_ActiveDoc.SaveAs(COleVariant(strSavePath), COleVariant((short)0),
vFalse, COleVariant(""), vTrue, COleVariant(""), vFalse, vFalse, vFalse, vFalse, vFalse); m_Docs.ReleaseDispatch();
m_Sel.ReleaseDispatch(); //退出WORD
m_App.Quit(vOpt, vOpt, vOpt);
m_App.ReleaseDispatch(); //打开文档
strExePath=_T("D:\\Microsoft Office\\Office\\Winword.exe ");
strExePath+=strWholePathName;
strExePath+="word\\1.doc";
WinExec(strExePath,SW_SHOW);
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(TRUE); Documents docs=app.GetDocuments();
CComVariant Template(_T("")); //不使用WORD的文档模板
CComVariant NewTemplate(false),DocumentType(0),Visible;
_Document doc = docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);
//绘制5*6的表格
CComVariant vFalse(false),vTrue(true);
Tables tables = doc.GetTables();
_Table table = tables.Add(sel.GetRange(),5,6,&vTrue,&vFalse);
//往表格填充文字
....................
//释放资源
table.ReleaseDispatch();
tables.ReleaseDispatch();
doc.ReleaseDispatch();
docs.ReleaseDispatch(); CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
app.ReleaseDispatch();
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
InlineShapes shapes = doc.GetInlineShapes();
_InlineShape shape = shapes.AddPicture("c:\\001.jpg",&varTrue,&varTrue,covOptional);