使用脚本将Excel表格转换为临时表 [英] Get Excel sheet into temp table using a script

查看:127
本文介绍了使用脚本将Excel表格转换为临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将这个excel表放入表中,所以我可以应用select语句等来更新表的信息。

Im trying to get this excel sheet into a table, so I can apply select statements to it etc, to update tables with its info.

SELECT * 
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
          'Excel 8.0;Database=C:\PB.xlsx',
          'SELECT * FROM [Sheet1$]')

我运行64位机器。
不知道是什么excel版本。

Im running 64 bit machine. No idea what excel version it is.

错误:


消息7399,级别16,状态1,行1
链接服务器(null)的OLE DB提供程序Microsoft.Jet.OLEDB.4.0报告错误。提供者没有提供有关该错误的任何信息。
消息7303,级别16,状态1,行1
无法初始化链接服务器(null)的OLE DB提供程序Microsoft.Jet.OLEDB.4.0的数据源对象。

Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider did not give any information about the error. Msg 7303, Level 16, State 1, Line 1 Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

当我更改为Excel 12.0;

When I change to Excel 12.0;


OLE链接服务器(null)的DB提供程序Microsoft.Jet.OLEDB.4.0返回消息找不到可安装的ISAM。
消息7303,级别16,状态1,行1
无法初始化链接服务器(null)的OLE DB提供程序Microsoft.Jet.OLEDB.4.0的数据源对象。

OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Could not find installable ISAM.". Msg 7303, Level 16, State 1, Line 1 Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".


推荐答案

这个错误有5个可能的原因。

There are 5 possible causes for this error.


  1. 喷气发动机必须安装在服务器上。

  2. xls的路径相对于服务器,而不是从

  3. 运行命令的工作站
  4. 运行SQL Server服务的帐户必须具有xls所在文件夹的写入权限。一个可能的解决方案是将服务启动帐户(例如管理员)的temp =和tmp =环境变量更改为(例如)c:\temp,然后将c:\temp上的完全控制更改为Everyone

4 ...

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

5 ....

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'AllowInProcess', 0 
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'DynamicParameters', 0
GO 

现在我不知道为什么这样工作,特别是考虑到所有人都说他们应该设置为1.对我而言,将它们设置为零,在SQL Server 2008R2 32位和M $上执行以下SQL语句的技巧Office 2007

Now I don't know why this works, especially considering that everyone else says they should be set to 1. For me however, setting them to zero, did the trick for the following SQL statement on SQL Server 2008R2 32bit and M$ Office 2007

Select * 
into [temp_table$]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\temp\EXPENDITURE REPORT.xls;HDR=YES;IMEX=1',
'SELECT * FROM [EXPENDITURE SHEET$]')

注意:我有意使用一个示例,其中文件名和工作表名称都有空格显示这可以做到。

Note: I purposely have used an example in which both the filename and the worksheet name have spaces to show that this can be done.

这篇关于使用脚本将Excel表格转换为临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆