procedure TForm1.Button2Click(Sender: TObject);
Var i, j, IntChar,count: integer;
ExcelApp: Variant;
begin
try
ExcelApp:=CreateOleObject('excel.application');
ExcelApp.WorkBooks.open('d:programtest\excelmodal\xlBZDGD.xls');
ExcelApp.Caption:='測試';
ExcelApp.Activesheet.Cells(7,4):=1;
if not ExcelApp.ActiveWorkBook.saved then
ExcelApp.ActiveSheet.PrintPreview;
except
ExcelApp.Workbooks.close;
ExcelApp.quit;
exit;
end;
Var i, j, IntChar,count: integer;
ExcelApp: Variant;
begin
try
ExcelApp:=CreateOleObject('excel.application');
ExcelApp.WorkBooks.open('d:programtest\excelmodal\xlBZDGD.xls');
ExcelApp.Caption:='測試';
ExcelApp.Activesheet.Cells(7,4):=1;
if not ExcelApp.ActiveWorkBook.saved then
ExcelApp.ActiveSheet.PrintPreview;
except
ExcelApp.Workbooks.close;
ExcelApp.quit;
exit;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var i, j, IntChar,count: integer;
ExcelApp: Variant;
begin
try
ExcelApp:=CreateOleObject('excel.application');
ExcelApp.WorkBooks.open('d:programtest\excelmodal\xlBZDGD.xls');
ExcelApp.Caption:='測試';
ExcelApp.Activesheet.Cells(7,4):=1;
ExcelApp.visable:=true;//這句掉了,關鍵
if not ExcelApp.ActiveWorkBook.saved then
ExcelApp.ActiveSheet.PrintPreview;
except
ExcelApp.Workbooks.close;
ExcelApp.quit;
exit;
end;
*********If you want preview it you must set the visable is true;**********
procedure GetExcelData(FileName:string;getdbconnection:tadoconnection;pagecount,starnum,endnum:integer);
var
c,jindu, pagenum,rr,j,ll_row,ll_col,bom_comn:integer;
compname,star_port,aid_port,controy:integer;
lcl,ship_date,ship_comp,ok_date,traslate:integer;
myworksheet1,MyExcel,MyWorkbook:Variant;
TmpQry:TADOQuery;
zuhe,xiao,zhong,da:boolean;
begin
if filename='' then
begin
showmessage('请选择Excel文件!');
exit;
end;
try
begin
Flh_FFrm:=TFlh_FFrm.Create(application);
flh_ffrm.Show ;
flh_ffrm.Caption :='正在打开: '+filename+', 请稍等...';
screen.Cursor :=crHourGlass;
jindu:=(endnum-starnum)*4+3;
Flh_FFrm.InitProgress(jindu,Flh_FFrm.ProgressBar2);
Flh_FFrm.InitProgress(5,Flh_FFrm.ProgressBar1);
Flh_FFrm.SetProgress(Flh_FFrm.ProgressBar2);
Flh_FFrm.SetProgress(Flh_FFrm.ProgressBar1);
MyExcel:=createoleobject('Excel.Application');
Flh_FFrm.SetProgress(Flh_FFrm.ProgressBar1);
MyExcel.Workbooks.Open(FileName);
Flh_FFrm.SetProgress(Flh_FFrm.ProgressBar1);
MyExcel.Visible:=false;
Flh_FFrm.SetProgress(Flh_FFrm.ProgressBar1);
Flh_FFrm.SetProgress(Flh_FFrm.ProgressBar2);
end;
except
Application.Messagebox('Excel 没有安装!','ERROR!', MB_ICONERROR + mb_Ok);
Abort;
end;
try
try
if endnum>MyExcel.Worksheets.Count then
begin
showmessage('最大页设置错误,当前Excel只有'+inttostr(MyExcel.Worksheets.Count)+'页,请重新设置');
exit;
end;