我使用Server里的控件TWordApplication,TExcelApplication. Offcie97
有以下些问题存在 客户环境中开启了很多个Excel和Word后 在运行我的程序经常报Ole Error 800..
Normal.dot是否替换。TWordApplication,TExcelApplication 可不可以单独开启个独立的进程?
原来使用:
WordApp.Connection;
以下Word程序:
function TBPR_RmlPrint00_Option_Frm.PrintDoc: integer;
var
Template,NewTemplate,DocType,Visiable,ItemIndex:OleVariant;
SaveChanges,OriginalFormat,RouteDocument: OleVariant;
i,j:integer;
sOldFooterText :String;
begin
Template := sFilePath;
NewTemplate := True;
ItemIndex := 1; try
WordApp.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end; WordApp.Visible := False;
WordApp.Documents.Add(Template, NewTemplate);
WordDoc.ConnectTo(WordApp.Documents.Item(ItemIndex));
WordApp.ActiveWindow.View.Type_ := wdPrintPreview;
WordDoc.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageFooter;
WordDoc.ActiveWindow.ActivePane.Selection.InsertAfter('地瑅北ゅン ');
j:= StrToInt(Edt_PrintNumber.Text); i:= 1;
try
for i:=1 to j do
begin
WordDoc.PrintOut;
end
finally
Sleep(5000); //
SaveChanges := WdDoNotSaveChanges;
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned; WordDoc.Close(SaveChanges, OriginalFormat, RouteDocument);
WordDoc.Disconnect;
if wordApp.Documents.Count >0 then
begin
WordApp.Visible := True;
wordApp.Disconnect;
end
else
begin
WordApp.Visible := False;
wordApp.Disconnect;
WordApp.Quit;
end; InserPrintInfo(i);
Application.MessageBox('ゴΘ','',MB_OK);
end;以下是EXCEL:
function TBPR_RmlPrint00_Option_Frm.PrintExcel: integer;
VAR
LCID : Integer;
wkBook : _WorkBook;
i,j:integer;
begin
LCID := GetUserDefaultLCID();
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(sFilePath, LCID);
ExcelApplication1.Visible[LCID] := False;
ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveWorkbook);
ExcelWorksheet1.ConnectTo(ExcelApplication1.ActiveSheet as _Worksheet); j:= StrToInt(Edt_PrintNumber.Text);
i:= 1;
try
for i:=1 to j do
begin
ExcelWorksheet1.PageSetup.LeftFooter:='地瑅北ゅン '{+'材'+IntToStr(i)+'/羆'+Trim(Edt_PrintNumber.Text)+''};
ExcelWorksheet1.PrintOut;
end;
finally
InserPrintInfo(i);
ExcelWorkbook1.Close(WdDoNotSaveChanges);
ExcelApplication1.Disconnect;
end;
end;
有以下些问题存在 客户环境中开启了很多个Excel和Word后 在运行我的程序经常报Ole Error 800..
Normal.dot是否替换。TWordApplication,TExcelApplication 可不可以单独开启个独立的进程?
原来使用:
WordApp.Connection;
以下Word程序:
function TBPR_RmlPrint00_Option_Frm.PrintDoc: integer;
var
Template,NewTemplate,DocType,Visiable,ItemIndex:OleVariant;
SaveChanges,OriginalFormat,RouteDocument: OleVariant;
i,j:integer;
sOldFooterText :String;
begin
Template := sFilePath;
NewTemplate := True;
ItemIndex := 1; try
WordApp.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end; WordApp.Visible := False;
WordApp.Documents.Add(Template, NewTemplate);
WordDoc.ConnectTo(WordApp.Documents.Item(ItemIndex));
WordApp.ActiveWindow.View.Type_ := wdPrintPreview;
WordDoc.ActiveWindow.ActivePane.View.SeekView := wdSeekCurrentPageFooter;
WordDoc.ActiveWindow.ActivePane.Selection.InsertAfter('地瑅北ゅン ');
j:= StrToInt(Edt_PrintNumber.Text); i:= 1;
try
for i:=1 to j do
begin
WordDoc.PrintOut;
end
finally
Sleep(5000); //
SaveChanges := WdDoNotSaveChanges;
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned; WordDoc.Close(SaveChanges, OriginalFormat, RouteDocument);
WordDoc.Disconnect;
if wordApp.Documents.Count >0 then
begin
WordApp.Visible := True;
wordApp.Disconnect;
end
else
begin
WordApp.Visible := False;
wordApp.Disconnect;
WordApp.Quit;
end; InserPrintInfo(i);
Application.MessageBox('ゴΘ','',MB_OK);
end;以下是EXCEL:
function TBPR_RmlPrint00_Option_Frm.PrintExcel: integer;
VAR
LCID : Integer;
wkBook : _WorkBook;
i,j:integer;
begin
LCID := GetUserDefaultLCID();
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(sFilePath, LCID);
ExcelApplication1.Visible[LCID] := False;
ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveWorkbook);
ExcelWorksheet1.ConnectTo(ExcelApplication1.ActiveSheet as _Worksheet); j:= StrToInt(Edt_PrintNumber.Text);
i:= 1;
try
for i:=1 to j do
begin
ExcelWorksheet1.PageSetup.LeftFooter:='地瑅北ゅン '{+'材'+IntToStr(i)+'/羆'+Trim(Edt_PrintNumber.Text)+''};
ExcelWorksheet1.PrintOut;
end;
finally
InserPrintInfo(i);
ExcelWorkbook1.Close(WdDoNotSaveChanges);
ExcelApplication1.Disconnect;
end;
end;
ExcelApp := CreateOleObject( 'Excel.Application' );
a.頁眉:
ExcelApp.ActiveSheet.PageSetup.CenterHeader := '報表演示';
b.頁腳:
ExcelApp.ActiveSheet.PageSetup.CenterFooter := '第&P頁';