谁知道 知道在VC中调用WORD,怎么样才能得到打开文档共有多少页,在WORD的哪个类中可能得到呢?
解决方案 »
- 求 ocr sdk(可以识别简体中文)
- 我还没有走,公司最近又新改革,一周6天工作制,从A8:30到P5:30,中午休息一个小时,事假100%扣除工资,病假50%扣除当天工资
- VC+MYSQL奇怪问题,请高手解答。谢谢
- 关于编辑控制的问题
- GetClientRect对应的SetClientRect是什么
- 急!求用VC++做一个被VB调用的DLL例子及相关注意事项!
- 菜问题:用什么API可以得到显示器的名字就像"Plus And Play Monitor"?
- vc 6 安装不上!?
- 高分!求解关于钩子的问题
- CRectTracker中画的图像,移动这个图像时其它所有图像都不见了,求解
- 在位图上画画
- 急!!!!!!!!!!!!!
//remember to call AfxOleInit
//get page numbers of a document
//theory:insert pages field to header, read the value, then delete the field
//by masterz
_Application wordapp;
BOOL bret=wordapp.CreateDispatch("Word.Application");
wordapp.SetVisible(TRUE);
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND,
VT_ERROR);
Documents oDocs(wordapp.GetDocuments()); // Use the Constructor
// for Documents.
_Document oDoc;
oDoc.AttachDispatch(oDocs.Open(COleVariant("C:\\Test.doc",VT_BSTR),
covFalse, //Confirm Conversions.
covFalse, // Not read only.
covTrue, // Add to recent documents.
covOptional, // PassWordDocument.
covOptional, // PassWordTemplate.
covFalse, // Revert.
covOptional, // WritePasswordDocument.
covOptional, // WritePasswordTemplate.
covOptional, // Format, e.g., WordOpenFormat.
covOptional, // New with Word 9 - Encoding
covOptional, // Visible - Ditto
// covOptional, // New with Word 10 - OpenConflictDocument
covOptional, // Ditto - OpenAndRepair
covOptional, //(long) 0, // Ditto - DocumentDirection - Left to Right
covOptional // Ditto - NoEncodingDialog
)
);
LPDISPATCH lpdisp;//=oDoc.GetSections();
Sections oSecs;
lpdisp=oDoc.GetSections();
oSecs.AttachDispatch(lpdisp);
lpdisp=oSecs.GetFirst();
Section oSec;
oSec.AttachDispatch(lpdisp);
lpdisp=oSec.GetFooters();
HeadersFooters hfs;
hfs.AttachDispatch(lpdisp);
lpdisp=hfs.Item(1);
HeaderFooter hf;
hf.AttachDispatch(lpdisp);
Range rg=hf.GetRange();
Fields fds;
lpdisp=oDoc.GetFields();
fds.AttachDispatch(lpdisp);
lpdisp=fds.Add(rg,COleVariant(long(26)),covOptional,covOptional);
Field fd;
fd.AttachDispatch(lpdisp);
fd.Select();
Selection oSelection = wordapp.GetSelection();
rg=oSelection.GetRange();
CString msg;
rg=oSelection.GetRange();
msg=rg.GetText();
rg.Delete(covOptional,covOptional);
AfxMessageBox(msg);
wordapp.Quit(covFalse,covOptional,covOptional);