Documents myDocs;
_Document myDoc;
Range myRange;
Find fndInDoc;
Replacement rpInDoc;
if(!myApp.CreateDispatch("Word.Application"))
{
AfxMessageBox(_T("failed"));
}
myApp.SetVisible(TRUE);
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant FileName="c:\\doc1.doc";
myDocs=myApp.GetDocuments();
myDoc=myDocs.Add(FileName,vOpt,vOpt,vOpt);
myRange=myDoc.GetContent();
fndInDoc=myRange.GetFind();
fndInDoc.ClearFormatting();
rpInDoc=fndInDoc.GetReplacement();
rpInDoc.ClearFormatting();
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
COleVariant Text(_T("two"));
CComVariant MatchCase(varFalse);
CComVariant MatchWholeWord(varFalse);
CComVariant MatchWildcards(varFalse);
CComVariant MatchSoundsLike(varFalse);
CComVariant MatchAllWordForms(varFalse);
CComVariant Forward(varTrue);
CComVariant Wrap((short)1);///!!!!!!!!!!!!!!!!!
CComVariant format(varFalse);
CComVariant ReplaceWith(_T("*公民"));
CComVariant Replace((short)2);////////!!!!!!!!主要是这里
CComVariant MatchKashida(varstrNull);
CComVariant MatchDiacritics(varstrNull);
CComVariant MatchAlefHamza(varstrNull);
CComVariant MatchControl(varstrNull);
AfxMessageBox(_T("检查1")); //检查错误
fndInDoc.Execute(&Text, &MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike,
&MatchAllWordForms, &Forward, &Wrap, &format, &ReplaceWith,&Replace,&MatchKashida,&MatchDiacritics,
&MatchAlefHamza, &MatchControl);
AfxMessageBox(_T("检查2")); //检查错误
myDoc.Save();
AfxMessageBox(_T("ok!")); //test
myRange.ReleaseDispatch();
fndInDoc.ReleaseDispatch();
rpInDoc.ReleaseDispatch();
myDocs.ReleaseDispatch();
myDoc.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
myApp.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
myApp.ReleaseDispatch();
7 个解决方案
#1
VC,没搞过。VBA就可以做很多事情了。
#2
朋友们,都不会吗?
#3
高手们,帮帮忙吧。我每次结贴都那么的及时啊。好歹帮忙看看啊。
#4
你的这段程序问题很多啊
#5
你的参数给的不正确,所以有问题,
#6
给你看看这个段代码,已经把你说的那个问解决了
CApplication myApp;
CDocuments myDocs;
CDocument0 myDoc;
CRange myRange;
CFind fndInDoc;
CReplacement rpInDoc;
if(!myApp.CreateDispatch("Word.Application"))
{
AfxMessageBox(_T("failed"));
return;
}
myApp.put_Visible(FALSE);
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant FileName="c:\\Hello.doc";
myDocs=myApp.get_Documents();
myDoc=myDocs.Add(FileName,vOpt,vOpt,vOpt);
myRange=myDoc.get_Content();
fndInDoc=myRange.get_Find();
fndInDoc.ClearFormatting();
rpInDoc=fndInDoc.get_Replacement();
rpInDoc.ClearFormatting();
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
COleVariant vInt((long)-1, VT_I4),vIntF((long)0, VT_I4);
COleVariant Text(_T("two"));
CComVariant MatchCase(varFalse);
CComVariant MatchWholeWord(varFalse);
CComVariant MatchWildcards(varFalse);
CComVariant MatchSoundsLike(varFalse);
CComVariant MatchAllWordForms(varFalse);
CComVariant Forward(varTrue);
CComVariant Wrap((short)1);///!!!!!!!!!!!!!!!!!
CComVariant format(varFalse);
CComVariant ReplaceWith(_T("*公民"));
CComVariant Replace((short)2);////////!!!!!!!!主要是这里
CComVariant MatchKashida(varstrNull);
CComVariant MatchDiacritics(varstrNull);
CComVariant MatchAlefHamza(varstrNull);
CComVariant MatchControl(varstrNull);
AfxMessageBox(_T("检查1")); //检查错误
fndInDoc.Execute(&Text, &MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike,
&MatchAllWordForms, &Forward, &Wrap, &format, &ReplaceWith,&Replace,&MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike);//&MatchKashida,&MatchDiacritics,
//&MatchAlefHamza, &MatchControl);
AfxMessageBox(_T("检查2")); //检查错误
//myDoc.Save();
myDoc.Close(vInt,vIntF,vFalse);
AfxMessageBox(_T("ok!")); //test
myRange.ReleaseDispatch();
fndInDoc.ReleaseDispatch();
rpInDoc.ReleaseDispatch();
myDocs.ReleaseDispatch();
myDoc.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
myApp.Quit(&vOpt,&vOpt,&vOpt);
myApp.ReleaseDispatch();
CApplication myApp;
CDocuments myDocs;
CDocument0 myDoc;
CRange myRange;
CFind fndInDoc;
CReplacement rpInDoc;
if(!myApp.CreateDispatch("Word.Application"))
{
AfxMessageBox(_T("failed"));
return;
}
myApp.put_Visible(FALSE);
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant FileName="c:\\Hello.doc";
myDocs=myApp.get_Documents();
myDoc=myDocs.Add(FileName,vOpt,vOpt,vOpt);
myRange=myDoc.get_Content();
fndInDoc=myRange.get_Find();
fndInDoc.ClearFormatting();
rpInDoc=fndInDoc.get_Replacement();
rpInDoc.ClearFormatting();
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
COleVariant vInt((long)-1, VT_I4),vIntF((long)0, VT_I4);
COleVariant Text(_T("two"));
CComVariant MatchCase(varFalse);
CComVariant MatchWholeWord(varFalse);
CComVariant MatchWildcards(varFalse);
CComVariant MatchSoundsLike(varFalse);
CComVariant MatchAllWordForms(varFalse);
CComVariant Forward(varTrue);
CComVariant Wrap((short)1);///!!!!!!!!!!!!!!!!!
CComVariant format(varFalse);
CComVariant ReplaceWith(_T("*公民"));
CComVariant Replace((short)2);////////!!!!!!!!主要是这里
CComVariant MatchKashida(varstrNull);
CComVariant MatchDiacritics(varstrNull);
CComVariant MatchAlefHamza(varstrNull);
CComVariant MatchControl(varstrNull);
AfxMessageBox(_T("检查1")); //检查错误
fndInDoc.Execute(&Text, &MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike,
&MatchAllWordForms, &Forward, &Wrap, &format, &ReplaceWith,&Replace,&MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike);//&MatchKashida,&MatchDiacritics,
//&MatchAlefHamza, &MatchControl);
AfxMessageBox(_T("检查2")); //检查错误
//myDoc.Save();
myDoc.Close(vInt,vIntF,vFalse);
AfxMessageBox(_T("ok!")); //test
myRange.ReleaseDispatch();
fndInDoc.ReleaseDispatch();
rpInDoc.ReleaseDispatch();
myDocs.ReleaseDispatch();
myDoc.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
myApp.Quit(&vOpt,&vOpt,&vOpt);
myApp.ReleaseDispatch();
#7
yongfengzhu_zhu() 谢谢你
#1
VC,没搞过。VBA就可以做很多事情了。
#2
朋友们,都不会吗?
#3
高手们,帮帮忙吧。我每次结贴都那么的及时啊。好歹帮忙看看啊。
#4
你的这段程序问题很多啊
#5
你的参数给的不正确,所以有问题,
#6
给你看看这个段代码,已经把你说的那个问解决了
CApplication myApp;
CDocuments myDocs;
CDocument0 myDoc;
CRange myRange;
CFind fndInDoc;
CReplacement rpInDoc;
if(!myApp.CreateDispatch("Word.Application"))
{
AfxMessageBox(_T("failed"));
return;
}
myApp.put_Visible(FALSE);
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant FileName="c:\\Hello.doc";
myDocs=myApp.get_Documents();
myDoc=myDocs.Add(FileName,vOpt,vOpt,vOpt);
myRange=myDoc.get_Content();
fndInDoc=myRange.get_Find();
fndInDoc.ClearFormatting();
rpInDoc=fndInDoc.get_Replacement();
rpInDoc.ClearFormatting();
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
COleVariant vInt((long)-1, VT_I4),vIntF((long)0, VT_I4);
COleVariant Text(_T("two"));
CComVariant MatchCase(varFalse);
CComVariant MatchWholeWord(varFalse);
CComVariant MatchWildcards(varFalse);
CComVariant MatchSoundsLike(varFalse);
CComVariant MatchAllWordForms(varFalse);
CComVariant Forward(varTrue);
CComVariant Wrap((short)1);///!!!!!!!!!!!!!!!!!
CComVariant format(varFalse);
CComVariant ReplaceWith(_T("*公民"));
CComVariant Replace((short)2);////////!!!!!!!!主要是这里
CComVariant MatchKashida(varstrNull);
CComVariant MatchDiacritics(varstrNull);
CComVariant MatchAlefHamza(varstrNull);
CComVariant MatchControl(varstrNull);
AfxMessageBox(_T("检查1")); //检查错误
fndInDoc.Execute(&Text, &MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike,
&MatchAllWordForms, &Forward, &Wrap, &format, &ReplaceWith,&Replace,&MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike);//&MatchKashida,&MatchDiacritics,
//&MatchAlefHamza, &MatchControl);
AfxMessageBox(_T("检查2")); //检查错误
//myDoc.Save();
myDoc.Close(vInt,vIntF,vFalse);
AfxMessageBox(_T("ok!")); //test
myRange.ReleaseDispatch();
fndInDoc.ReleaseDispatch();
rpInDoc.ReleaseDispatch();
myDocs.ReleaseDispatch();
myDoc.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
myApp.Quit(&vOpt,&vOpt,&vOpt);
myApp.ReleaseDispatch();
CApplication myApp;
CDocuments myDocs;
CDocument0 myDoc;
CRange myRange;
CFind fndInDoc;
CReplacement rpInDoc;
if(!myApp.CreateDispatch("Word.Application"))
{
AfxMessageBox(_T("failed"));
return;
}
myApp.put_Visible(FALSE);
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant FileName="c:\\Hello.doc";
myDocs=myApp.get_Documents();
myDoc=myDocs.Add(FileName,vOpt,vOpt,vOpt);
myRange=myDoc.get_Content();
fndInDoc=myRange.get_Find();
fndInDoc.ClearFormatting();
rpInDoc=fndInDoc.get_Replacement();
rpInDoc.ClearFormatting();
COleVariant varstrNull("");
COleVariant varZero((short)0);
COleVariant varTrue(short(1),VT_BOOL);
COleVariant varFalse(short(0),VT_BOOL);
COleVariant vInt((long)-1, VT_I4),vIntF((long)0, VT_I4);
COleVariant Text(_T("two"));
CComVariant MatchCase(varFalse);
CComVariant MatchWholeWord(varFalse);
CComVariant MatchWildcards(varFalse);
CComVariant MatchSoundsLike(varFalse);
CComVariant MatchAllWordForms(varFalse);
CComVariant Forward(varTrue);
CComVariant Wrap((short)1);///!!!!!!!!!!!!!!!!!
CComVariant format(varFalse);
CComVariant ReplaceWith(_T("*公民"));
CComVariant Replace((short)2);////////!!!!!!!!主要是这里
CComVariant MatchKashida(varstrNull);
CComVariant MatchDiacritics(varstrNull);
CComVariant MatchAlefHamza(varstrNull);
CComVariant MatchControl(varstrNull);
AfxMessageBox(_T("检查1")); //检查错误
fndInDoc.Execute(&Text, &MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike,
&MatchAllWordForms, &Forward, &Wrap, &format, &ReplaceWith,&Replace,&MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike);//&MatchKashida,&MatchDiacritics,
//&MatchAlefHamza, &MatchControl);
AfxMessageBox(_T("检查2")); //检查错误
//myDoc.Save();
myDoc.Close(vInt,vIntF,vFalse);
AfxMessageBox(_T("ok!")); //test
myRange.ReleaseDispatch();
fndInDoc.ReleaseDispatch();
rpInDoc.ReleaseDispatch();
myDocs.ReleaseDispatch();
myDoc.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
myApp.Quit(&vOpt,&vOpt,&vOpt);
myApp.ReleaseDispatch();
#7
yongfengzhu_zhu() 谢谢你