摘要:使用msword.olb实现获取doc文件的页数
_Application oWordApp; Documents oWordDocs; _Document oWordDoc; Window oWordWindow; Pane oWordPane; Pages oWordPages; COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND,VT_ERROR); BOOL bFlag = TRUE; CString sWordPath("C:\\发文办文单.docx"); if(oWordApp.CreateDispatch(_T("Word.Application"))) { try { oWordApp.SetVisible(TRUE); oWordApp.Activate(); oWordDocs = oWordApp.GetDocuments(); oWordDoc = oWordDocs.Open(COleVariant(sWordPath),vFalse,vFalse,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); oWordWindow = oWordDoc.GetActiveWindow(); oWordPane = oWordWindow.GetActivePane(); oWordPages = oWordPane.GetPages(); int nPageNum=oWordPages.GetCount();<span style="white-space:pre"> </span>//取得页数 } catch(...) { AfxMessageBox(_T("又异常了!!!")); } oWordPages.ReleaseDispatch(); oWordPane.ReleaseDispatch(); oWordWindow.ReleaseDispatch(); oWordDoc.ReleaseDispatch(); oWordDoc.Close(vOpt,vOpt,vOpt); oWordDoc.ReleaseDispatch(); oWordDocs.ReleaseDispatch(); oWordApp.Quit(vOpt,vOpt,vOpt); oWordApp.ReleaseDispatch(); }
时间: 2024-10-05 07:02:25