to lq123:
while not Query1.eof do
begin
i:=i+1;
FindText1 := '<Name'+inttostr(i)+'>';
FindText2 := '<pm'+inttostr(i)+'>';
FindText3 := '<fcon'+inttostr(i)+'>';
FindText4 := '<pcon'+inttostr(i)+'>';
FindText5 := '<rem'+inttostr(i)+'>';
ReplaceWith1 := Query1.fieldbyname('project_name').asstring;
ReplaceWith2 := Query1.fieldbyname('name').asstring;
ReplaceWith3 := Query1.fieldbyname('fcontent').asstring;
ReplaceWith5 := Query1.fieldbyname('remark').asstring;
Query2.Close ;
Query2.ParamByName ('MProject_id2').asstring:=Query1.fieldbyname('project_id2').asstring;
Query2.ParamByName ('M_date').asstring:=FormatDateTime('yyyy"/"mm"/"dd',DateTimePicker2.date);
Query2.Open ;
ReplaceWith4 := Query2.fieldbyname('pcontent').asstring;
Qstaff.Close ;
Qstaff.ParamByName ('MProject_id2').asstring:=Query1.fieldbyname('project_id2').asstring;
Qstaff.ParamByName ('M_serial').asstring:=Query1.fieldbyname('serial').asstring;
Qstaff.Open ;
j:=0;
if Qstaff.RecordCount <>0 then
while not Qstaff.Eof do
begin
j:=j+1;
find1:='<n'+inttostr(i)+inttostr(j)+'>';
find2:='<t'+inttostr(i)+inttostr(j)+'>';
rep1:=Qstaff.fieldbyname('name').asstring;
rep2:=Qstaff.fieldbyname('opinion').asstring;
WordDocument1.Range.Find.Execute( Find1, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, Rep1, Replace );
WordDocument1.Range.Find.Execute( Find2, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, Rep2, Replace );
Qstaff.Next ;
end;
WordDocument1.Range.Find.Execute( FindText1, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith1, Replace );
WordDocument1.Range.Find.Execute( FindText2, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith2, Replace );
WordDocument1.Range.Find.Execute( FindText3, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith3, Replace );
WordDocument1.Range.Find.Execute( FindText4, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith4, Replace );
WordDocument1.Range.Find.Execute( FindText5, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith5, Replace );
Query1.Next ;
end;
Fsumdoc_imp.Close ;
label2.Caption :='';
end;
有的记录替换没问题,有的却报错,是不是与输入的记录格式或长度有关?