簡體   English   中英

如何將SQL表數據導出到Excel工作表中?

[英]how to export sql table data into excel worksheet?

我有想要將其數據導出到我的excel文件中的表。 到目前為止,我已經在這里嘗試了所有主題,但沒有任何效果。 我已經嘗試過這些2:

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
    'Excel 8.0;Database=D:\excel\testing.xls;', 
    'SELECT * FROM [newStart$]') select * from OutputResult


insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0',
    'Excel 8.0;Database=D:\excel\testing.xls;', 
    'SELECT * FROM [newStart$]') select * from OutputResult

當我用jet運行它時,我會得到這個錯誤:

OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "The Microsoft Jet database engine could not find the object 'newStart$'.  Make sure the object exists and that you spell its name and the path name correctly.".
 Msg 7350, Level 16, State 2, Line 1 Cannot get the column information from OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

當我運行ACE.OLEDB時,我得到了這個:

OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Office Access database engine could not find the object 'newStart$'.  Make sure the object exists and that you spell its name and the path name correctly.".
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

我也給我的sql帳戶完全控制權限。 再加上我也運行這兩個:

USE [master]
GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1
GO

EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1
GO

2:

sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE

如果有人能指出我正確的方向,我將不勝感激。

strSqlQry = "Place SQL Qry Here"
vFilePath = "Database Path"

'Create Objects
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

'Open Connection
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & vFilePath & ";" & _
 "Extended Properties=""Excel 8.0;HDR=Yes;"";"

'Execute Qry
rs.Open strSqlQry, conn, adOpenStatic, adLockOptimistic

'Place recorset into excel worksheet
ActiveSheet.Range("A1").CopyFromRecordset (NewRS)

rs.Close

Set rs = Nothing
Set conn = Nothing

您可以使用本主題中編寫的方式如何將SQL Server 2005數據傳輸或導出到Excel

在Excel中使用外部數據菜單連接到數據庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM