procedure Texportexcel.BitBtn1Click(Sender: TObject);
var
row,column,Tempcolumn:integer;
i,j:integer;
begin
inherited;
ExcelWorksheet1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelApplication1.Disconnect;
Try
{ Excelapplication1.Connect;
ExcelWorkbook1.Connect;
ExcelWorksheet1.Connect;}
Except
Messagedlg('沒有安裝Excel!'+char(13)+
'請重新安裝!',mtinformation,[mbok],0);
Abort;
end;
Excelapplication1.Visible[0]:=true;
Excelapplication1.Caption:= '數據導出窗口程序';
Excelapplication1.Workbooks.Add(varNull,0);
Excelworkbook1.ConnectTo(excelapplication1.workbooks[excelapplication1.workbooks.count]);
Excelworksheet1.ConnectTo(excelworkbook1.worksheets[1] as _worksheet);
Excelworksheet1.Cells.Item[1,3]:='TOOLING PROGRESS REPORT';
Excelworksheet1.Cells.Item[2,1]:='Customer:';
Excelworksheet1.Cells.Item[2,3]:=dm.xvalue.fieldbyname('customer').value;
Excelworksheet1.Cells.Item[3,1]:='Cust.No:';
Excelworksheet1.Cells.item[3,3]:=dm.xvalue.fieldbyname('custph').value;
Excelworksheet1.Cells.Item[4,1]:='Description';
Excelworksheet1.Cells.Item[4,3]:=dm.xvalue.fieldbyname('custcpname').value;
Excelworksheet1.Cells.item[5,1]:='RSC No.:';
Excelworksheet1.Cells.Item[5,3]:=dm.xvalue.fieldbyname('rscno').value;
Excelworksheet1.Cells.item[6,1]:='Chinese Description:';
Excelworksheet1.Cells.Item[6,3]:=dm.xvalue.fieldbyname('rsccpname').value;
Excelworksheet1.Cells.Item[7,1]:='Start date:';
Excelworksheet1.Cells.Item[7,3]:=dm.xvalue.fieldbyname('rjdate').value;
Excelworksheet1.Cells.item[8,1]:='Estimate Finish Date:';
Excelworksheet1.Cells.Item[8,3]:=dm.xvalue.fieldbyname('rjoverdate').value;
Excelworksheet1.Cells.item[9,1]:='Actual Finish Date';
Excelworksheet1.cells.Item[10,1]:='total days:';
Excelworksheet1.Cells.Item[10,3]:=dm.xvalue.fieldbyname('totaldays').value;
Excelworksheet1.cells.item[11,1]:='Progress Per Day:';
Excelworksheet1.Cells.Item[11,3]:=dm.xvalue.fieldbyname('perday').value+'%';
Excelworksheet1.Cells.Item[12,1]:='Date/Time';
EXCELWORKSHEET1.Cells.Item[12,2]:='PLAN(%)';
Excelworksheet1.Cells.Item[12,3]:='ACTUAL(%)';
Excelworksheet1.Cells.Item[12,4]:='GAP';
Excelworksheet1.Cells.Item[12,5]:='WORKING DAYS';
row:=13;
dm.evalue.First ;
While Not(dm.evalue.Eof) do
begin
TempColumn := 0 ;
for Column:=1 to DbGrid1.FieldCount do
begin
if DbGrid1.Columns.Items[Column-1].Visible = True Then
begin
TempColumn := TempColumn + 1 ;
ExcelWorksheet1.Cells.Item[row,TempColumn] := DbGrid1.Fields[Column-1].AsString;
end;
end;
dm.evalue.Next;
row:=row + 1;
end;
end;