void CmdeskDlg::OnBnClickedTestbutton()
{
// TODO: Add your control notification handler code here
//WriteDB();
// TODO: Add your control notification handler code here
CApplication oApp;
CDocuments oDocs;
CDocument0 oDoc;
if (!oApp.CreateDispatch(_T("Word.Application"), NULL))
{
AfxMessageBox(_T("启动Word程序失败!"));
exit(1);
}
//查看自动化过程
oApp.put_Visible(true);
oDocs = oApp.get_Documents();
COleVariant varOPt(DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant varStartLine, varEndLine;
varStartLine.intVal = 2;
varEndLine.intVal = 50;
//添加一个新文档
oDoc = oDocs.Add(varOPt, varOPt, varOPt, varOPt);
//获取文档区域
CRange range = oDoc.Range(varStartLine, varEndLine);
UpdateData(TRUE);
range.put_Text(_T("DDD
msword 写入word内容
最新推荐文章于 2024-09-07 18:37:03 发布