[SQL server]将Excel数据导入Sql server
执行以下语句可以查询Excel内容:
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source=C:\Book1.xls;Extended Properties=Excel 8.0')...[T_TABLE$]
其中:C:\Book1.xls为所需导入的Excel文件路径,T_TABLE$为Excel的表格名称。(勿漏了$这个符号),Excel 8.0这个为Excel的版本号,Office97-2000的版本号为8.0
如,导入数据可以这样写:在Sql server的查询分析器里键入
insert into [t_table]( [u_name] )
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source=C:\Book1.xls;Extended Properties=Excel 8.0')...[T_TABLE$]
MS提供的方法有:
SELECT * INTO XLImport3 FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\test\xltest.xls;Extended Properties=Excel 8.0')...[Customers$]
SELECT * INTO XLImport4 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', [Customers$])
SELECT * INTO XLImport5 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', 'SELECT * FROM [Customers$]')
具体可参见:
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;321686
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source=C:\Book1.xls;Extended Properties=Excel 8.0')...[T_TABLE$]
其中:C:\Book1.xls为所需导入的Excel文件路径,T_TABLE$为Excel的表格名称。(勿漏了$这个符号),Excel 8.0这个为Excel的版本号,Office97-2000的版本号为8.0
如,导入数据可以这样写:在Sql server的查询分析器里键入
insert into [t_table]( [u_name] )
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source=C:\Book1.xls;Extended Properties=Excel 8.0')...[T_TABLE$]
MS提供的方法有:
SELECT * INTO XLImport3 FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\test\xltest.xls;Extended Properties=Excel 8.0')...[Customers$]
SELECT * INTO XLImport4 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', [Customers$])
SELECT * INTO XLImport5 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', 'SELECT * FROM [Customers$]')
具体可参见:
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;321686