B
beyzhzj
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm2.sbtnSaveClick(Sender: TObject);var
sFileName,My_FileName,sPallet : String;
MsExcel, MsExcelWorkBook : Variant;
i,iIndex,iTest : Integer;
begin
if (not DutyTemp.Active) OR (DutyTemp.recordCount=0) Then Exit;
if not FileExists(ExtractFilePath(Application.EXEName)+'DailyRepairReport.xlt') then
begin
MessageDlg('YieldRate.xlt Not Exist!',mtWarning,[mbOK],0);
exit;
end;
sFileName := ExtractFilePath(Application.EXEName)+'DailyRepairReport.xlt';
try
//try
iTest :=1;
MsExcel := CreateOleObject('Excel.Application');
iTest := 2;
MsExcelWorkBook := MsExcel.WorkBooks.Open(sFileName);
iTest:=3;
MsExcel.Worksheets['Input'].select;
SaveDialog1.InitialDir := ExtractFilePath('C:/');
SaveDialog1.DefaultExt := 'xls';
SaveDialog1.Filter := 'All Files(*.xls)|*.xls|All Files(*.xlt)|*.xlt';
if Sender = sbtnSave then
if not (SaveDialog1.Execute) then exit;
iTest:=4;
SaveExcel(MsExcel,MsExcelWorkBook); //*****出錯的地方,SaveExcel函數見下面*********
iTest:=5;
if Sender = sbtnSave then
begin
iTest:=6;
sFileName := SaveDialog1.FileName;
iTest:=8;
MsExcelWorkBook.SaveAs(sFileName);
showmessage('Save Excel OK!!');
end else
begin
MsExcel.WorkSheets['sheet1'].PrintOut;
showmessage('Print Excel OK!!');
end;
{iTest:=9;
iTest :=10;
with QryTemp do
begin
Close;
Params.Clear;
CommandText := 'Update SAJET.G_PACK_PALLET '
+ ' Set Print_Flag = ''Y'' '
+ ' Where Pallet_No in (' + sPallet + ')';
Execute;
end; }
//Except
ShowMessage('Could not start Microsoft Excel.('+IntToStr(iTest)+')');
//end;
finally
MsExcelWorkBook.close(False);
MsExcel.Application.Quit;
MsExcel:=Null;
end;
procedure TForm2.SaveExcel(MsExcel,MsExcelWorkBook:Variant);
var i, j,k, iCount, iRow,iIndex,iTrow,iTotal:integer;
vRange1: variant;
sSQL, sPallet, sSN,sWO,sTpallet,sTemp: String;
begin
DutyTemp.First;
for i:=1 to DutyTemp.RecordCount-1 do
begin
MsExcel.WorkSheets['Input'].Range['A'+inttostr(21+i)].Value :=DutyTemp.Fields[0].AsString;
MsExcel.WorkSheets['Input'].Range['B'+inttostr(21+i)].Value :=DutyTemp.Fields[1].AsString;
MsExcel.WorkSheets['Input'].Range['C'+inttostr(21+i)].Value :=DutyTemp.Fields[2].AsString;
MsExcel.WorkSheets['Input'].Range['D'+inttostr(21+i)].Value :=DutyTemp.Fields[3].AsString;
MsExcel.WorkSheets['Input'].Range['E'+inttostr(21+i)].Value :=DutyTemp.Fields[4].AsString;
MsExcel.WorkSheets['Input'].Range['F'+inttostr(21+i)].Value :=DutyTemp.Fields[5].AsString;
MsExcel.WorkSheets['Input'].Range['G'+inttostr(21+i)].Value :=DutyTemp.Fields[6].AsString;
MsExcel.WorkSheets['Input'].Range['I'+inttostr(21+i)].Value :=DutyTemp.Fields[7].AsString;
DutyTemp.Next;
end;
end;
sFileName,My_FileName,sPallet : String;
MsExcel, MsExcelWorkBook : Variant;
i,iIndex,iTest : Integer;
begin
if (not DutyTemp.Active) OR (DutyTemp.recordCount=0) Then Exit;
if not FileExists(ExtractFilePath(Application.EXEName)+'DailyRepairReport.xlt') then
begin
MessageDlg('YieldRate.xlt Not Exist!',mtWarning,[mbOK],0);
exit;
end;
sFileName := ExtractFilePath(Application.EXEName)+'DailyRepairReport.xlt';
try
//try
iTest :=1;
MsExcel := CreateOleObject('Excel.Application');
iTest := 2;
MsExcelWorkBook := MsExcel.WorkBooks.Open(sFileName);
iTest:=3;
MsExcel.Worksheets['Input'].select;
SaveDialog1.InitialDir := ExtractFilePath('C:/');
SaveDialog1.DefaultExt := 'xls';
SaveDialog1.Filter := 'All Files(*.xls)|*.xls|All Files(*.xlt)|*.xlt';
if Sender = sbtnSave then
if not (SaveDialog1.Execute) then exit;
iTest:=4;
SaveExcel(MsExcel,MsExcelWorkBook); //*****出錯的地方,SaveExcel函數見下面*********
iTest:=5;
if Sender = sbtnSave then
begin
iTest:=6;
sFileName := SaveDialog1.FileName;
iTest:=8;
MsExcelWorkBook.SaveAs(sFileName);
showmessage('Save Excel OK!!');
end else
begin
MsExcel.WorkSheets['sheet1'].PrintOut;
showmessage('Print Excel OK!!');
end;
{iTest:=9;
iTest :=10;
with QryTemp do
begin
Close;
Params.Clear;
CommandText := 'Update SAJET.G_PACK_PALLET '
+ ' Set Print_Flag = ''Y'' '
+ ' Where Pallet_No in (' + sPallet + ')';
Execute;
end; }
//Except
ShowMessage('Could not start Microsoft Excel.('+IntToStr(iTest)+')');
//end;
finally
MsExcelWorkBook.close(False);
MsExcel.Application.Quit;
MsExcel:=Null;
end;
procedure TForm2.SaveExcel(MsExcel,MsExcelWorkBook:Variant);
var i, j,k, iCount, iRow,iIndex,iTrow,iTotal:integer;
vRange1: variant;
sSQL, sPallet, sSN,sWO,sTpallet,sTemp: String;
begin
DutyTemp.First;
for i:=1 to DutyTemp.RecordCount-1 do
begin
MsExcel.WorkSheets['Input'].Range['A'+inttostr(21+i)].Value :=DutyTemp.Fields[0].AsString;
MsExcel.WorkSheets['Input'].Range['B'+inttostr(21+i)].Value :=DutyTemp.Fields[1].AsString;
MsExcel.WorkSheets['Input'].Range['C'+inttostr(21+i)].Value :=DutyTemp.Fields[2].AsString;
MsExcel.WorkSheets['Input'].Range['D'+inttostr(21+i)].Value :=DutyTemp.Fields[3].AsString;
MsExcel.WorkSheets['Input'].Range['E'+inttostr(21+i)].Value :=DutyTemp.Fields[4].AsString;
MsExcel.WorkSheets['Input'].Range['F'+inttostr(21+i)].Value :=DutyTemp.Fields[5].AsString;
MsExcel.WorkSheets['Input'].Range['G'+inttostr(21+i)].Value :=DutyTemp.Fields[6].AsString;
MsExcel.WorkSheets['Input'].Range['I'+inttostr(21+i)].Value :=DutyTemp.Fields[7].AsString;
DutyTemp.Next;
end;
end;