How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility

To read an Excel 2007 or Excel 2010 file using OPENROWSET, run the following query:

SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\YourFile.xlsx;',
'SELECT * FROM [Sheet1$]')

If the Excel 2007 or Excel 2010 file does not contain any headers, simply add the “HDR=No” to the OPENROWSET command as follows:

SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\YourFile.xlsx;HDR=No',
'SELECT * FROM [Sheet1$]')

If one of the columns in the Excel 2007 or Excel 2010 file contains a mixed type of data, where some rows may contain just numbers while others may contain alphanumeric values, add the “IMEX=1” to the second parameter of the OPENROWSET command, as follows:

SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\YourFile.xlsx;IMEX=1',
'SELECT * FROM [Sheet1$]')

To load the Excel 2007 or Excel 2010 data to a new SQL Server table, simply add the INTO clause of the SELECT statement as follows:

SELECT *
INTO [dbo].[MyExcelData]
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\YourFile.xlsx;',
'SELECT * FROM [Sheet1$]') we must set adhocremotequeriesenabled = true :
right click the database and choose facets the link is :
http://www.mssqltips.com/sqlservertip/1673/where-is-the-surface-area-configuration-tool-in-sql-server-2008/

t-sql read xlsx的更多相关文章

  1. 一、SQL系列之~使用SQL语言导出数据及实现定时导出数据任务

    一般情况下,SQL数据库中带有导入与导出数据的直接按键操作,点击数据表所在的数据库--任务--导出/导入数据,根据导入/导出向导直接将数据导出即可. 但导出的数据格式多为Excel格式,如果需要导出的 ...

  2. Oracle导出excel

    oracle导出excel(非csv)的方法有两种,1.使用sqlplus  spool,2.使用包体 现将网上相关代码整理后贴出以备不时之需: 使用sqlplus: 使用sqlplus需要两个文件: ...

  3. 64位的Sql Server使用OPENROWSET导入xlsx格式的excel数据的时候报错(转载)

    In the old times while all the CPUs were 32bit, we were happily using JET OLEDB Provider reaching Ex ...

  4. Microsoft SQL Server 17导出xlsx文件时报错:The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. (System.Data)

    导出数据时报错: 如果你是导出office 2007格式 TITLE: SQL Server Import and Export Wizard ---------------------------- ...

  5. SQL Server Reporting Services (SSRS): Reporting Services in SQL Server 2012 (codename "Denali") will support XLSX, DOCX formats. Bye bye 65536 rows limit in XLS files ;)

    当SSRS报表的时候,若相应EXCEL是2003以下,在行数超过65536的时候报表会报错 "Microsoft.ReportingServices.ReportProcessing.Han ...

  6. C#创建Excel(.xls和.xlsx)文件的三种方法

    生成EXCEL文件是经常需要用到的功能,我们利用一些开源库可以很容易实现这个功能. 方法一:利用excellibrary,http://code.google.com/p/excellibrary/ ...

  7. sql server 读取excel里的数据

    以下是执行的sql代码,只拿简单读取数据举例,其他详细的,请自行查看 reconfigure RECONFIGURE GO GO SELECT * FROM OPENROWSET('Microsoft ...

  8. Asp.Net中使用OpenRowSet操作Excel表,导入Sql Server(实例)

    有两种接口可供选择:Microsoft.Jet.OLEDB.4.0(以下简称 Jet 引擎)和Microsoft.ACE.OLEDB.12.0(以下简称 ACE 引擎). Jet 引擎大家都很熟悉,可 ...

  9. 在Excel中使用SQL语句查询和筛选

    本文转自:http://blog.sina.com.cn/s/blog_5fc375650102e1g5.html 今天在微博上看到@数据分析精选 分享的一篇文章,是关于<在Excel中使用SQ ...

  10. sql server sql语句导入数据到execl2007中

    insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\c.xlsx','select 字段1,字段2 FR ...

随机推荐

  1. mycat 实践扩容

    实践扩容, travelrecord表定义为10个分片,尝试将10个分片中的2个分片转移到第二台MySQL上 1--定义10个分片<table name="travelrecord_t ...

  2. 2016.7.27 VS搜索正则表达式,在UltraEdit中可选用Perl正则引擎,按C#语法搜索

    表达式 语法 说明 任一字符 . 匹配除换行符外的任何一个字符. 最多 0 项或更多 * 匹配前面表达式的 0 个或更多搜索项. 最多一项或更多 + 匹配前面表达式的至少一个搜索项. 最少 0 项或更 ...

  3. Canopy聚类算法(经典,看图就明白)

    只有这个算法思想比较对,其他 的都没有一开始的remove: 原网址:http://www.shahuwang.com/?p=1021 Canopy Clustering 这个算法是2000年提出来的 ...

  4. ffmpeg一揽子

    avformat_alloc_output_context2().在基于FFmpeg的视音频编码器程序中,该函数通常是第一个调用的函数(除了组件注册函数av_register_all()).avfor ...

  5. eclipse中maven的配置与使用

    以eclipse Juno版本为例 1.插件安装 eclipse==>help====>install new software===>add name :m2e location: ...

  6. Android ListView 设置

    android:minHeight="80dip"//设置每一条的高度 android:divider="@null" //设置默认的分割线不显示 androi ...

  7. JavaScript的运算符

    一.什么是表达式??? 是ECMScript中的一个短语,解释器可以通过计算把它转成一个值,最简单的表达式是字面量或者变量名,单一字面量和组合字面量统称为表达式. 二.一元运算符 1.delete 运 ...

  8. JAVA input/output 流层次关系图

    在java中,input和output流种类繁多,那么它们之间是否有关系呢?答案是肯定的,其中使用到了设计模式,装饰模式 下图来自于HEAD FIRST 设计模式 装饰模式一章 下图来自网络博客:ht ...

  9. HDU 5242 树链剖分思想的贪心

    题意及博客 树链剖分分为2步,第一次求出深度,重儿子,第二次求出重链,用到了启发式的思想,即对于比较重的儿子,尽量去完整的维护它.类似于我们去合并两个堆,明显把小的堆逐个插入大的堆中会比大的往小的插更 ...

  10. Codeforces 1097F Alex and a TV Show (莫比乌斯反演)

    题意:有n个可重集合,有四种操作: 1:把一个集合设置为单个元素v. 2:两个集合求并集. 3:两个集合中的元素两两求gcd,然后这些gcd形成一个集合. 4:问某个可重复集合的元素v的个数取模2之后 ...