这是我的代码..还需加哪些呀?
_Application m_App;
Documents m_Docs;
_Document m_Doc;
Selection m_Slection;
Range m_Range;
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR),
vZ((short)0);
COleVariant vFileName(_T("d:\\ca.doc"));
COleVariant vNull(_T(""));
m_Doc.AttachDispatch(m_Docs.Open(
vFileName, // FileName
vTrue, // Confirm Conversion.
vFalse, // ReadOnly.
vFalse, // AddToRecentFiles.
vOpt, // PasswordDocument.
vOpt, // PasswordTemplate.
vOpt, // Revert.
vOpt, // WritePasswordDocument.
vOpt, // WritePasswordTemplate.
vOpt, // Format. // Last argument for Word 97
vOpt, // Encoding // New for Word 2000/2002
vOpt, // Visible
vOpt, // OpenAndRepair
vZ, // DocumentDirection wdDocumentDirection LeftToRight
vOpt, // NoEncodingDialog
vOpt
) // Close Open parameters
); // Close AttachDispatch
//得到selection变量
m_Slection = m_App.GetSelection();
if (!m_Slection.m_lpDispatch)
{
AfxMessageBox("Select获取失败!", MB_OK|MB_ICONWARNING);
}
//得到全部DOC的Range变量
m_Range = m_Doc.Range(vOpt,vOpt);
if(!m_Range.m_lpDispatch)
{
AfxMessageBox("Range获取失败!", MB_OK|MB_ICONWARNING);
}
CString szText;
m_Range.InsertAfter(szText);
m_Slection.InsertFile(
"d:\\ca.doc",
vNull,
vFalse,
vFalse,
vFalse
);
m_Doc.Save();
m_Range.ReleaseDispatch();
m_Slection.ReleaseDispatch(); //释放selection对象
m_Docs.ReleaseDispatch(); //释放Documents对象
m_Doc.Close(vOpt,vOpt,vOpt);
m_Doc.ReleaseDispatch(); //释放Document对象
m_App.Quit(vOpt,vOpt,vOpt);
m_App.ReleaseDispatch(); //释放应用程序类对象
回复 更多评论