【发布时间】:2021-01-15 18:03:58
【问题描述】:
我正在尝试将 Excel(xlsx) 文件解析为 SQL Server。一张表中有很多表,我不确定如何处理。
我知道我可以用这个拉整个工作表:
SELECT *
FROM OPENROWSET
(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0; Database=\\afcn2011\root\DATA\VisualCron\SharePoint\Templates\Kitchen+Bar Inventory.xlsx; HDR=NO; IMEX=1',
'SELECT * FROM [Inventory$]'
)
但我希望有一种方法可以从工作表中的特定表格中进行选择?
例如,我为每种酒都有一张桌子;伏特加、杜松子酒、波旁酒等,它们都被命名为“VodkaTable”、“GinTable”、“BourbonTable”等。
有没有办法只从该特定表中进行选择?请记住,范围会随着时间而改变,所以我不能只说 $A10:$B20 或类似的东西。 但是像这样:
SELECT *
FROM OPENROWSET
(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0; Database=\\afcn2011\root\DATA\VisualCron\SharePoint\Templates\Kitchen+Bar Inventory.xlsx; HDR=NO; IMEX=1',
'SELECT * FROM [Inventory$VodkaTable]'
)
我现在也试过了: 我定义了一个引用 Vodka 表的名称,称为“VodkaData”:
然后我使用了这个查询:
SELECT *
FROM OPENROWSET
(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0; Database=\\afcn2011\root\DATA\VisualCron\SharePoint\Templates\Kitchen+Bar Inventory.xlsx; HDR=NO; IMEX=1',
'SELECT * FROM [VodkaData]'
)
但我收到此错误:
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine could not find the object 'VodkaData'. Make sure the object exists and that you spell its name and the path name correctly. If 'VodkaData' is not a local object, check your network connection or contact the server administrator.".
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-server excel