当前位置:首页 > 芯闻号 > 充电吧
[导读] 一、如我在D盘下有D:/物件编码.xls文件,有工作表名Sheet是中文命名为‘办公用品编码’,‘零件编码’。        select * into #temp  from opendataso

 一、如我在D盘下有D:/物件编码.xls文件,有工作表名Sheet是中文命名为‘办公用品编码’,‘零件编码’。

       select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:/物件编码.xls')...[办公用品编码$]

       select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:/物件编码.xls')...[零件编码$]

二、如你的Excel文件是工作表是默认的Sheet命名为Sheet1,Sheet2等。

      select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:/物件编码.xls')...[Sheet1$]

      select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:/物件编码.xls')...[Sheet2$]

三、引用 Limpire (昨夜小楼)以下方法,也行

      OpenRowSet和OpenDataSource都能用读取用数字命名的Sheet,只不过要加单引号界定,其它不规则命名的Sheet也一样。

假设C:/Text.xls有个Sheet名字是“3”: 
       select * from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:/Test.xls')...['3$']
--OR
select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:/Test.xls',['3$'])
--OR
select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:/Test.xls','select * from [''3$'']')
--OpenRowSet(,,'query')可以不加单引号界定:
select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:/Test.xls','select * from [3$]')

四、本人的方法:

导出EXCEL时,对应字段数类型都要相同,EXCEL字段的名称stano,sname 和数据库的要一样,才能导出成功。

insert into openrowset('MICROSOFT.JET.OLEDB.4.0','excel 8.0;
HDR=YES;database=D:/FName.xls',sheet1$)
 select stano,sname from stainfo

以上在SQL SERVER2000上测试均可以运行,是在本地查询分析器中调试。

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭