sql匯入匯出 excel檔案

2021-07-10 03:10:13 字數 1343 閱讀 8180

在企業管理器的匯入一步步操作或用

語句如下

--從excel檔案中,匯入資料到sql資料庫中,很簡單,直接用下面的語句:

在開始前需要啟用ad hoc distributed queries

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'ad hoc distributed queries',1

reconfigure

使用完成後,關閉ad hoc distributed queries:

exec sp_configure 'ad hoc distributed queries',0

reconfigure

exec sp_configure 'show advanced options',0

reconfigure

--如果接受資料匯入的表已經存在

insert into 表 select * from

openrowset('microsoft.jet.oledb.4.0'

,'excel 5.0;hdr=yes;database=c:\test.xls',sheet1$)

--如果匯入資料並生成表

select * into 表 from

openrowset('microsoft.jet.oledb.4.0'

,'excel 5.0;hdr=yes;database=c:\test.xls',sheet1$)

--如果從sql資料庫中,匯出資料到excel,如果excel檔案已經存在,而且已經按照要接收的資料建立好表頭,就可以簡單的用:

insert into openrowset('microsoft.jet.oledb.4.0'

,'excel 5.0;hdr=yes;database=c:\test.xls',sheet1$)

select * from 表

--如果excel檔案不存在,也可以用bcp來導成類excel的檔案,注意大小寫:

--匯出表的情況

exec master..xp_cmdshell 'bcp 資料庫名.dbo.表名 out "c:\test.xls" /c -/s"伺服器名" /u"使用者名稱" -p"密碼"'

--匯出查詢的情況

exec master..xp_cmdshell 'bcp "select au_fname, au_lname from pubs..authors order by au_lname" queryout "c:\test.xls" /c -/s"伺服器名" /u"使用者名稱" -p"密碼"'

SQL語句匯入匯出Excel

匯出到excel exec master.xp cmdshell bcp settledb.dbo.shanghu out c temp1.xls c q s gnetdata gnetdata u sa p 匯入excel select from opendatasource microsoft....

關於匯入 匯出Excel檔案

因為excel的易用,使得使用者能夠自己做表,幾乎所有使用者的報表都有excel檔案。使用者希望能將excel的檔案讀入報表工具,這樣就可以省去畫表的工作了 同時,生成的報表,要能匯出成excel檔案,這樣使用者就可以在其上再加工處理。因而對於乙個報表工具來說,有沒有完善的匯入 匯出excel檔案的...

php匯出匯入excel 檔案

php 匯入匯出excel 需要載入excel 類庫 ps 如果匯出檔案打不開時,要檢查一下php.ini 中 在php.ini檔案中,將extension php zip.dll前面的分號 去除,然後同樣在php.ini檔案中,將 zlib.output compression off 改為 zl...