从SQL Server表将数据导出到现有的EXCEL文件

时间:2011-08-02 11:21:00

标签: sql sql-server-2008

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

此代码无法正常工作..它正在提供错误

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

请帮忙

2 个答案:

答案 0 :(得分:3)

结果是The Microsoft Jet database engine could not find the object '$Sheet1',所以你应该Make sure the object exists and that you spell its name and the path name correctly

答案 1 :(得分:0)

Excel sheet names

确定您尝试“连接”的工作表的名称。看看上面的图片。标准纸张称为“Sheet1”至“Sheet3”。 D:\contact.xls下的工作簿可能包含自定义名称。使用您在那里找到的名称,并在其末尾添加$

'SELECT * FROM [Sheet1$]'