L
lingmao3
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure Tforminstrumentqs.BitBtn11Click(Sender: TObject);
//打单
var
vWord,vDoc,vRange: Variant ;
sText,sReplace : string ;
lReturn : Boolean ;
j,col,i,Index :integer;
docname:string;//文档名
aIndex:OleVariant; //word的index
WordApplication1 : TWordApplication;
WordDocument1 : TWordDocument;
begin //aaaa
vWord := CreateOleObject('Word.Application') ;//创建Word线程
showmessage(inttostr(vword.Documents.Count));/////////////提示1
//*****************判断有无打开lintemp.doc文档,有打开则提示关闭
for i := 1 to vword.Documents.Count do
begin //1
Index := i;
docname:=trim(UpperCase(vWord.Documents.Item(Index).Get_Name));
if docname='LINTEMP.DOC' then //打开的文档全为大写
begin //2
showmessage('与模板lintemp.doc同名的word文档正处于编辑状态,请先关闭!');
vWord.Visible := True;
Exit;
end;//2
end; //1
//*****************
//---写文档
With adoquery1 do
begin//2
Close;
SQL.Clear;
SQL.Add('select * from t_cyclostyleqs ');
try //33
adoquery1.Open;
Except
ShowMessage('没有此模块的打印模板,请联系管理员重新制作');
Exit;
end; //33
end; //2
TBlobField(ADOQuery1.FieldByName('word文档')).SaveToFile(ExtractFilePath(Application.ExeName)+'/ini/lintemp.Doc');
//---写文档
try //000
//打开要操作的文件
vDoc := vWord.Documents.Open(ExtractFilePath(Application.ExeName)+'/ini/lintemp.Doc');
for col:=0 to adoquery2.fieldlist.count-1 do
begin //2
sText := '$$'+trim(adoquery2.Fields[col].FieldName)+'$$' ; //原文字串
sReplace := trim(adoquery2.Fields[col]. AsString) ; //新字串
vDoc.Select ; //选取中整个文档
vRange := vDoc.Range ; //替换范围
lReturn := True ;
while lReturn do
begin //找到并替代成功则返回 True 共11个参数
lReturn := vDoc.Range.Find.Execute(sText,,,,,,,,,sReplace,True) ;
end ;
end; //2
vWord.Visible := True;
finally//000
vDoc.Close(True) ; //关闭文并保存
vWord.Quit(False) ; //退出Word
end ; //000
//showmessage(inttostr(vword.Documents.Count));
end; //aaaa
判断有无打开lintemp.doc文档,有打开则提示关闭这段代码无效,不能做出判断.请高手指教
//打单
var
vWord,vDoc,vRange: Variant ;
sText,sReplace : string ;
lReturn : Boolean ;
j,col,i,Index :integer;
docname:string;//文档名
aIndex:OleVariant; //word的index
WordApplication1 : TWordApplication;
WordDocument1 : TWordDocument;
begin //aaaa
vWord := CreateOleObject('Word.Application') ;//创建Word线程
showmessage(inttostr(vword.Documents.Count));/////////////提示1
//*****************判断有无打开lintemp.doc文档,有打开则提示关闭
for i := 1 to vword.Documents.Count do
begin //1
Index := i;
docname:=trim(UpperCase(vWord.Documents.Item(Index).Get_Name));
if docname='LINTEMP.DOC' then //打开的文档全为大写
begin //2
showmessage('与模板lintemp.doc同名的word文档正处于编辑状态,请先关闭!');
vWord.Visible := True;
Exit;
end;//2
end; //1
//*****************
//---写文档
With adoquery1 do
begin//2
Close;
SQL.Clear;
SQL.Add('select * from t_cyclostyleqs ');
try //33
adoquery1.Open;
Except
ShowMessage('没有此模块的打印模板,请联系管理员重新制作');
Exit;
end; //33
end; //2
TBlobField(ADOQuery1.FieldByName('word文档')).SaveToFile(ExtractFilePath(Application.ExeName)+'/ini/lintemp.Doc');
//---写文档
try //000
//打开要操作的文件
vDoc := vWord.Documents.Open(ExtractFilePath(Application.ExeName)+'/ini/lintemp.Doc');
for col:=0 to adoquery2.fieldlist.count-1 do
begin //2
sText := '$$'+trim(adoquery2.Fields[col].FieldName)+'$$' ; //原文字串
sReplace := trim(adoquery2.Fields[col]. AsString) ; //新字串
vDoc.Select ; //选取中整个文档
vRange := vDoc.Range ; //替换范围
lReturn := True ;
while lReturn do
begin //找到并替代成功则返回 True 共11个参数
lReturn := vDoc.Range.Find.Execute(sText,,,,,,,,,sReplace,True) ;
end ;
end; //2
vWord.Visible := True;
finally//000
vDoc.Close(True) ; //关闭文并保存
vWord.Quit(False) ; //退出Word
end ; //000
//showmessage(inttostr(vword.Documents.Count));
end; //aaaa
判断有无打开lintemp.doc文档,有打开则提示关闭这段代码无效,不能做出判断.请高手指教