W
wjl_my
Unregistered / Unconfirmed
GUEST, unregistred user!
错误为:由于文件许可权错误,Word无法完成保存操作
代码如下:
procedure TFrmFile_Situation.SpeedButton1Click(Sender: TObject);
var
newdoc:variant;
vlevariant;
filenametemp:string;
filename:string;
begin
if fileexists('c:/zzqjcy.doc') then deletefile('c:/zzqjcy.doc');
copyfile(Pchar(ExtractFilePath(Application.Exename)+'document/情况反映.doc'),pchar('c:/zzqjcy.doc'),false);
opendocument(olefilename);
wordapplication.Disconnect;
//---------------以下将WORD文档写入到RICHEDIT控件中去 -----------------------
if fileexists('c:/zzqjcy.doc') then
begin
try
filenametemp:='c:/zzqjcy.doc';
v:=createoleobject('word.application');
newdoc:=v.documents.open(filenametemp);
newdoc.saveas(filename:='c:/temp.rtf',fileformat:=3);
newdoc.close;
v.quit;
richedit4.Lines.clear;
richedit4.Lines.LoadFromFile('c:/temp.rtf');
deletefile('c:/temp.rtf');
except
on E:Exception do
showmessage(e.message);
end;
end;
end;
代码如下:
procedure TFrmFile_Situation.SpeedButton1Click(Sender: TObject);
var
newdoc:variant;
vlevariant;
filenametemp:string;
filename:string;
begin
if fileexists('c:/zzqjcy.doc') then deletefile('c:/zzqjcy.doc');
copyfile(Pchar(ExtractFilePath(Application.Exename)+'document/情况反映.doc'),pchar('c:/zzqjcy.doc'),false);
opendocument(olefilename);
wordapplication.Disconnect;
//---------------以下将WORD文档写入到RICHEDIT控件中去 -----------------------
if fileexists('c:/zzqjcy.doc') then
begin
try
filenametemp:='c:/zzqjcy.doc';
v:=createoleobject('word.application');
newdoc:=v.documents.open(filenametemp);
newdoc.saveas(filename:='c:/temp.rtf',fileformat:=3);
newdoc.close;
v.quit;
richedit4.Lines.clear;
richedit4.Lines.LoadFromFile('c:/temp.rtf');
deletefile('c:/temp.rtf');
except
on E:Exception do
showmessage(e.message);
end;
end;
end;