ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Workbooks.Add(ExtractFilePath(ParamStr(0))+'1.xls',0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
ExcelWorkSheet1.Activate;
ADOQuery1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(ParamStr(0))+'cardb.mdb;Persist Security Info=False';
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * From 销售库 Where 购车日期 Between #'+FormatDateTime('yyyy-mm',DateTime)+'-01# and #'+FormatDateTime('yyyy-mm-dd',EndofTheMonth(DateTime))+'#');
ADOQuery1.Active:=True;
Row:=3;
while Not ADOQuery1.Eof do
begin
ExcelWorksheet1.Cells.Item[Row,1]:=ADOQuery1.Fields[16].AsString;
ExcelWorksheet1.Cells.Item[Row,2]:=ADOQuery1.Fields[17].AsString;
ExcelWorksheet1.Cells.Item[Row,3]:=ADOQuery1.Fields[12].AsString;
ExcelWorksheet1.Cells.Item[Row,4]:=ADOQuery1.Fields[13].AsString;
ExcelWorksheet1.Cells.Item[Row,6]:=ADOQuery1.Fields[8].AsString;
if Length(ADOQuery1.Fields[1].AsString)<8 then
begin
ExcelWorksheet1.Cells.Item[Row,7]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,10]:=ADOQuery1.Fields[5].AsString;
ExcelWorksheet1.Cells.Item[Row,14]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,23]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,24]:=ADOQuery1.Fields[3].AsString;
ExcelWorksheet1.Cells.Item[Row,31]:=ADOQuery1.Fields[6].AsString;
end
else
begin
ExcelWorksheet1.Cells.Item[Row,12]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,13]:=ADOQuery1.Fields[5].AsString;
end;
ExcelWorksheet1.Cells.Item[Row,9]:=ADOQuery1.Fields[2].AsString;
ExcelWorksheet1.Cells.Item[Row,11]:=ADOQuery1.Fields[3].AsString;
ExcelWorksheet1.Cells.Item[Row,15]:=ADOQuery1.Fields[4].AsString;
ExcelWorksheet1.Cells.Item[Row,16]:=ADOQuery1.Fields[3].AsString;
ExcelWorksheet1.Cells.Item[Row,20]:=ADOQuery1.Fields[7].AsString;
ExcelWorksheet1.Cells.Item[Row,21]:=ADOQuery1.Fields[14].AsString;
ExcelWorksheet1.Cells.Item[Row,22]:=ADOQuery1.Fields[18].AsString;
ExcelWorksheet1.Cells.Item[Row,26]:=ADOQuery1.Fields[19].AsString; ADOQuery1.Next;
Inc(Row);
end;
ExcelWorkSheet1.SaveAs(ExtractFilePath(ParamStr(0))+FormatDateTime('yyyy-mm',DateTime)+'.xls');
end;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Workbooks.Add(ExtractFilePath(ParamStr(0))+'1.xls',0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
ExcelWorkSheet1.Activate;
ADOQuery1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(ParamStr(0))+'cardb.mdb;Persist Security Info=False';
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * From 销售库 Where 购车日期 Between #'+FormatDateTime('yyyy-mm',DateTime)+'-01# and #'+FormatDateTime('yyyy-mm-dd',EndofTheMonth(DateTime))+'#');
ADOQuery1.Active:=True;
Row:=3;
while Not ADOQuery1.Eof do
begin
ExcelWorksheet1.Cells.Item[Row,1]:=ADOQuery1.Fields[16].AsString;
ExcelWorksheet1.Cells.Item[Row,2]:=ADOQuery1.Fields[17].AsString;
ExcelWorksheet1.Cells.Item[Row,3]:=ADOQuery1.Fields[12].AsString;
ExcelWorksheet1.Cells.Item[Row,4]:=ADOQuery1.Fields[13].AsString;
ExcelWorksheet1.Cells.Item[Row,6]:=ADOQuery1.Fields[8].AsString;
if Length(ADOQuery1.Fields[1].AsString)<8 then
begin
ExcelWorksheet1.Cells.Item[Row,7]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,10]:=ADOQuery1.Fields[5].AsString;
ExcelWorksheet1.Cells.Item[Row,14]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,23]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,24]:=ADOQuery1.Fields[3].AsString;
ExcelWorksheet1.Cells.Item[Row,31]:=ADOQuery1.Fields[6].AsString;
end
else
begin
ExcelWorksheet1.Cells.Item[Row,12]:=ADOQuery1.Fields[1].AsString;
ExcelWorksheet1.Cells.Item[Row,13]:=ADOQuery1.Fields[5].AsString;
end;
ExcelWorksheet1.Cells.Item[Row,9]:=ADOQuery1.Fields[2].AsString;
ExcelWorksheet1.Cells.Item[Row,11]:=ADOQuery1.Fields[3].AsString;
ExcelWorksheet1.Cells.Item[Row,15]:=ADOQuery1.Fields[4].AsString;
ExcelWorksheet1.Cells.Item[Row,16]:=ADOQuery1.Fields[3].AsString;
ExcelWorksheet1.Cells.Item[Row,20]:=ADOQuery1.Fields[7].AsString;
ExcelWorksheet1.Cells.Item[Row,21]:=ADOQuery1.Fields[14].AsString;
ExcelWorksheet1.Cells.Item[Row,22]:=ADOQuery1.Fields[18].AsString;
ExcelWorksheet1.Cells.Item[Row,26]:=ADOQuery1.Fields[19].AsString; ADOQuery1.Next;
Inc(Row);
end;
ExcelWorkSheet1.SaveAs(ExtractFilePath(ParamStr(0))+FormatDateTime('yyyy-mm',DateTime)+'.xls');
end;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
转换这样速度会比用ole快一些