L
lijun175165721
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br>var<br> xlApp,xlBook,xlSheet,xlQuery: Variant;<br> adoConnection,adoRecordset: Variant;<br>begin<br> adoConnection :=CreateOleObject('ADODB.Connection');<br> adoRecordset :=CreateOleObject('ADODB.Recordset');<br> adoConnection.Open(self.ADOConnection1.ConnectionString);<br> adoRecordset.CursorLocation :=self.ADOQuery1.CursorLocation;<br> adoRecordset.Open('SELECT * FROM table1',adoConnection,1,3);<br> xlApp := CreateOleObject('Excel.Application');<br> xlBook := xlApp.Workbooks.Add;<br> xlSheet := xlBook.Worksheets['sheet1'];<br> xlApp.Visible := True;<br><br> //把查询结果导入EXCEL数据<br><br> xlQuery := xlSheet.QueryTables.Add(adoRecordset,xlSheet.Range[ '"A1:E2"' ]); //出问题老是这一句<br><br> xlQuery.FieldNames := True;<br> xlQuery.RowNumbers := False;<br> xlQuery.FillAdjacentFormulas := False;<br> xlQuery.PreserveFormatting := True;<br> xlQuery.RefreshOnFileOpen := False;<br> xlQuery.BackgroundQuery := True;<br> //xlQuery.RefreshStyle := xlInsertDeleteCells;<br> xlQuery.SavePassword := True;<br> xlQuery.SaveData := True;<br> xlQuery.AdjustColumnWidth := True;<br> xlQuery.RefreshPeriod := 0;<br> xlQuery.PreserveColumnInfo := True;<br> xlQuery.FieldNames := True;<br> xlQuery.Refresh;<br>end;<br>运行后产生了OLE error 800A03EC!的错误!请大家指点!