Excel操作

来源:互联网 发布:淘宝上比较好的饰品店 编辑:程序博客网 时间:2024/06/05 17:26
 

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

--03版本导入Excel
insert  into tbGuestBook select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0',
'Excel 8.0;HDR=No;DATABASE=E:1.xls',Sheet1$)

--07以上版本导入Excel
insert into tbGuestBook select * from
OPENROWSET('Microsoft.Ace.OleDb.12.0'
,'Excel 12.0;HDR=No;DATABASE=E:1.xlsx',sheet1$)

--03版本导入Excel
insert into tbGuestBook select * from
OPENROWSET('Microsoft.Ace.OleDb.12.0'
,'Excel 12.0;HDR=No;DATABASE=E:1.xls',sheet1$)

--表不存在时建立表
select * into TestTable
from OPENROWSET('Microsoft.Ace.OleDb.12.0'
,'Excel 12.0;HDR=No;DATABASE=E:1.xls',sheet1$)
--查询Excel
select *  from OPENROWSET('Microsoft.Ace.OleDb.12.0'
,'Excel 12.0;HDR=Yes;DATABASE=E:mmm.xlsx',sheet1$)


--适用03版本 07版本有误

EXEC sp_configure N'xp_cmdshell', N'0'
RECONFIGURE WITH OVERRIDE

EXEC master..xp_cmdshell 'bcp Example.dbo.Test1 out E:\ww.xls -c -q -S"." -U"sa" -P"8959288"'

 


--使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure "Ad Hoc Distributed Queries",0
reconfigure

exec sp_configure "show advanced options",0
reconfigure

原创粉丝点击