The ReplaceText method can not do it.
You maybe use the ms word automation to realize it.
The component can get the msword::_Application interface. Then you can do the automation.
For examples in VC:
word::_Application wd;
wd.AttachDispatch(app, FALSE);
if(wd == 0){
wd.DetachDispatch();
return FALSE;
}
BOOL bFindHeader = FALSE;
BOOL bFindBody = FALSE;
BOOL bFindFooter = FALSE;
word::Window win = wd.GetActiveWindow();
word::Pane pane = win.GetActivePane();
word::View vw = pane.GetView();
{
vw.SetSeekView(9);//wdSeekCurrentPageHeader =9
word::Selection sel = wd.GetSelection();
CHECK_NULL_RETURN(sel, FALSE);
word::Find fd = sel.GetFind();
CHECK_NULL_RETURN(fd, FALSE);
VARIANT vText;
vText.vt = VT_BSTR; vText.bstrVal = strText.AllocSysString();
VARIANT vMatchCase;
vMatchCase.vt = VT_BOOL; vMatchCase.boolVal = MatchCase?VARIANT_TRUE:VARIANT_FALSE;
VARIANT vMatchWholeWord;
vMatchWholeWord.vt = VT_BOOL; vMatchWholeWord.boolVal = MatchWholeWord?VARIANT_TRUE:VARIANT_FALSE;
VARIANT vFalse;
vFalse.vt = VT_BOOL; vFalse.boolVal = VARIANT_FALSE;
VARIANT vTrue;
vTrue.vt = VT_BOOL; vTrue.boolVal = VARIANT_TRUE;
VARIANT vWrap;
vWrap.vt = VT_I4; vWrap.lVal = long(1);
VARIANT vRelpaceAll;
vRelpaceAll.vt = VT_I4; vRelpaceAll.lVal = long(2);
VARIANT vReplaceText;
vReplaceText.vt = VT_BSTR; vReplaceText.bstrVal = strReplaceText.AllocSysString();
bFindHeader = fd.Execute(&vText, &vMatchCase, &vMatchWholeWord, &vFalse, &vFalse, &vFalse, &vTrue,
&vWrap, &vFalse, &vReplaceText, &vRelpaceAll);
fd.ReleaseDispatch();
sel.ReleaseDispatch();
Leave a Reply
You must be logged in to post a comment.
Recent Comments