導出數據庫查詢內容為Excel時,同樣的查詢結果,為什麼有的電腦有數據,有的沒數據只是空的(只有表頭)?
系統有win2000,win98,Excel為Excel 2000以下是代碼:procedure TForm1.Button2Click(Sender: TObject);
var
xlApp,xlBook,xlSheet,xlQuery: Variant;
adoConnection,adoRecordset: Variant;
begin
adoConnection := CreateOleObject('ADODB.Connection');
adoRecordset := CreateOleObject('ADODB.Recordset');
adoConnection.Open(ADOConnection1.ConnectionString);
adoRecordset.CursorLocation := 3;//adUseClient;
adoRecordset.Open('select * from complainnote',adoConnection,1,3);
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := True; xlQuery := xlSheet.QueryTables.Add(adoRecordset,xlSheet.Range['A1']); xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.SavePassword := True;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.FieldNames := True;
xlQuery.Refresh; xlApp := Unassigned;
xlBook := Unassigned;
xlSheet := Unassigned;
xlQuery := Unassigned;
end;
系統有win2000,win98,Excel為Excel 2000以下是代碼:procedure TForm1.Button2Click(Sender: TObject);
var
xlApp,xlBook,xlSheet,xlQuery: Variant;
adoConnection,adoRecordset: Variant;
begin
adoConnection := CreateOleObject('ADODB.Connection');
adoRecordset := CreateOleObject('ADODB.Recordset');
adoConnection.Open(ADOConnection1.ConnectionString);
adoRecordset.CursorLocation := 3;//adUseClient;
adoRecordset.Open('select * from complainnote',adoConnection,1,3);
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := True; xlQuery := xlSheet.QueryTables.Add(adoRecordset,xlSheet.Range['A1']); xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.SavePassword := True;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.FieldNames := True;
xlQuery.Refresh; xlApp := Unassigned;
xlBook := Unassigned;
xlSheet := Unassigned;
xlQuery := Unassigned;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货