步驟如下:
--1.開啟遠端查詢支援
exec sp_configure '
show advanced options
' ,1
reconfigure
exec sp_configure '
ad hoc distributed queries
',1reconfigure
--2.鏈結excel microsoft ace 12.0 ole db provider 讀excel資料(注意excel必須事先關閉)
select
*from
openrowset('
microsoft.ace.oledb.12.0
','excel 12.0;hdr=yes;database=c:/users/nichk/desktop/data.xls
', sheet1$);
--3.記得用完選項後,關閉這些選項
exec sp_configure '
ad hoc distributed queries
',0reconfigure
exec sp_configure '
show advanced options
',0reconfigure
--4.檢視是不是關閉
exec sp_configure
--> jet 引擎訪問 excel 97-2003
select
*from
openrowset('
microsoft.jet.oledb.4.0
', '
excel 8.0;hdr=yes;imex=1;database=d:/97-2003.xls
', '
select * from [sheet1$]
')
select
*from
openrowset('
microsoft.jet.oledb.4.0
', '
excel 8.0;hdr=yes;imex=1;database=d:/97-2003.xls
', [
sheet1$
])
select
*from
opendatasource('
microsoft.jet.oledb.4.0
', '
excel 8.0;hdr=yes;imex=1;database=d:/97-2003.xls
')...[
sheet1$
]select
*from
opendatasource('
microsoft.jet.oledb.4.0
', '
data source=d:/97-2003.xls;extended properties="excel 8.0;hdr=yes;imex=1"
')...[
sheet1$]--
> ace 引擎訪問 excel 97-2003
select
*from
openrowset('
microsoft.ace.oledb.12.0
', '
excel 12.0;hdr=yes;imex=1;database=d:/97-2003.xls
', '
select * from [sheet1$]
')
select
*from
openrowset('
microsoft.ace.oledb.12.0
', '
excel 12.0;hdr=yes;imex=1;database=d:/97-2003.xls
', [
sheet1$
])
select
*from
opendatasource('
microsoft.ace.oledb.12.0
', '
excel 12.0;hdr=yes;imex=1;database=d:/97-2003.xls
')...[
sheet1$
]select
*from
opendatasource('
microsoft.ace.oledb.12.0
', '
data source=d:/97-2003.xls;extended properties="excel 12.0;hdr=yes;imex=1"
')...[
sheet1$]--
> ace 引擎訪問 excel 2007
select
*from
openrowset('
microsoft.ace.oledb.12.0
', '
excel 12.0;hdr=yes;imex=1;database=d:/2007.xlsx
', '
select * from [sheet1$]
')
select
*from
openrowset('
microsoft.ace.oledb.12.0
', '
excel 12.0;hdr=yes;imex=1;database=d:/2007.xlsx
', [
sheet1$
])
select
*from
opendatasource('
microsoft.ace.oledb.12.0
', '
excel 12.0;hdr=yes;imex=1;database=d:/2007.xlsx
')...[
sheet1$
]select
*from
opendatasource('
microsoft.ace.oledb.12.0
', '
data source=d:/2007.xlsx;extended properties="excel 12.0;hdr=yes;imex=1"
')...[
sheet1$
]
shell將sql查詢結果存放到excel中
bin sh cd d compare mysql mysql h uroot p default character set utf8 a sql select from contrast.dx record limit 0,10 mysql e sql dx.xls echo end 轉換編碼的...
exce 操作總結
data excel type ole2 object,excel object macro type ole2 object,macro object w book type ole2 object,list of workbooks book type ole2 object,workbook ...
python openpyxl設定excel格式
from openpyxl import workbook 新建時匯入這個 from openpyxl import load workbook 讀取時匯入這個 from openpyxl.styles import font,alignment 設定單元格格式 from openpyxl.util...