简体   繁体   English

使用SQL Server 2005导入Excel 2007文件

[英]Importing Excel 2007 File Using SQL Server 2005

I have an excel 2007 file with about 301808 rows and 2 columns. 我有一个具有301808行和2列的Excel 2007文件。 I was trying to use SSIS to import but cant use 2007 excel. 我试图使用SSIS导入,但是不能使用2007 excel。 I then decided to try and make a linked server in SQL Server, Following the instructions here: 然后,我决定按照此处的说明尝试在SQL Server中制作链接服务器:

  • In SQL Server Management Studio, expand Server Objects in Object Explorer. 在SQL Server Management Studio中,在“对象资源管理器”中展开“服务器对象”。
  • Right-click Linked Servers, and then click New linked server. 用鼠标右键单击链接服务器,然后单击新建链接服务器。
  • In the left pane, select the General page, and then follow these steps: 在左窗格中,选择“常规”页面,然后执行以下步骤:
  • In the first text box, type any name for the linked server. 在第一个文本框中,键入链接服务器的任何名称。
  • Select the Other data source option. 选择其他数据源选项。
  • In the Provider list, click Microsoft Jet 4.0 OLE DB Provider. 在提供程序列表中,单击“ Microsoft Jet 4.0 OLE DB提供程序”。
  • In the Product name box, type Excel for the name of the OLE DB data source. 在“产品名称”框中,键入Excel作为OLE DB数据源的名称。
  • In the Data source box, type the full path and file name of the Excel file. 在“数据源”框中,键入Excel文件的完整路径和文件名。
  • In the Provider string box, type Excel 8.0 for an Excel 2002, Excel 2000, or Excel 97 - workbook. 在提供程序字符串框中,为Excel 2002,Excel 2000或Excel 97-工作簿键入Excel 8.0。
  • Click OK to create the new linked server. 单击“确定”创建新的链接服务器。

From Here: http://support.microsoft.com/kb/306397/EN-US 从这里: http : //support.microsoft.com/kb/306397/EN-US

However the instructions only covers previous excel files not 2007 so I looked up connection strings for 2007 and used Excel 12.0 instead of Excel 8.0 in settings of linked server: 但是,这些说明仅涵盖了以前的excel文件,而没有涵盖2007年,因此我查找了2007年的连接字符串,并在链接服务器的设置中使用了Excel 12.0而不是Excel 8.0:

  • Provider: Microsoft Office 12.0 Access Database Engine OLE DB 提供者:Microsoft Office 12.0 Access数据库引擎OLE DB
  • Provider Product Name: Excel Data source: C:\\Documents and 提供程序产品名称:Excel数据源:C:\\ Documents和
  • Settings\\UserName\\Desktop\\Main\\FilesIns\\MyExcelFile.xlsx Provider 设置\\用户名\\桌面\\主\\ FilesIns \\ MyExcelFile.xlsx提供程序
  • String: Excel 12.0 字串:Excel 12.0
  • Location: 位置:
  • Catalog: 目录:

I then got this error: 然后我得到了这个错误:

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "EXCEL_MY_FILE" does not contain the table "Report 1$". 链接服务器“ EXCEL_MY_FILE”的OLE DB提供程序“ Microsoft.ACE.OLEDB.12.0”不包含表“ Report 1 $”。 The table either does not exist or the current user does not have permissions on that table. 该表不存在,或者当前用户对该表没有权限。

I went into security and added nt authority\\system just in case it was permissions problem and it still gave me the error above. 我进入安全性并添加了nt权限\\系统,以防万一这是权限问题,但仍然给我上面的错误。

The excel table is called 'Report 1'. excel表称为“报表1”。

I also tried using openrowset in sql to see what happened and I got this: 我也尝试在sql中使用openrowset看看发生了什么,我得到了:

SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. SQL Server阻止访问组件“ Ad Hoc Distributed Queries”的状态“ OpenRowset / OpenDatasource”,因为此组件的安全配置已关闭此组件。

I then tried the code in link below to see if it helped me use openrowset: 然后,我尝试了下面链接中的代码,以查看它是否有助于我使用openrowset:

How to enable Ad Hoc Distributed Queries 如何启用即席分布式查询

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

And got: 并得到:

OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Syntax error in FROM clause.". 链接服务器“(null)”的OLE DB提供程序“ Microsoft.ACE.OLEDB.12.0”返回了消息“ FROM子句中的语法错误”。 Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing the query "Select * from C:\\Documents and Settings\\UserName\\Desktop\\Main\\FilesIns\\MyExcelFile.xlsx" for execution against OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". 消息7321,级别16,状态2,行1为针对OLE DB提供程序“ Microsoft”执行的查询“从C:\\ Documents and Settings \\ UserName \\ Desktop \\ Main \\ FilesIns \\ MyExcelFile.xlsx中选择*”而准备查询时发生错误。链接服务器“(null)”的“ ACE.OLEDB.12.0”。

So I am not sure if the values in my openrowset statement are correct. 因此,我不确定openrowset语句中的值是否正确。

Really just looking for a way to import this file into an sql table without using SSIS - I cant use it anyway. 真的只是在寻找一种无需使用SSIS即可将此文件导入sql表的方法-无论如何我都无法使用它。

Thanks 谢谢

Andrew 安德鲁

Under your sp_Reconfigure, see that you reference an article here.. However, I think you may need to go to Microsoft instead.. 在您的sp_Reconfigure下,请参见此处引用的文章。但是,我认为您可能需要去Microsoft。

http://technet.microsoft.com/en-us/library/ms187569%28v=sql.90%29.aspx http://technet.microsoft.com/zh-cn/library/ms187569%28v=sql.90%29.aspx

And there are quite a few examples of how to use OPENROWSET here - 这里有很多有关如何使用OPENROWSET的示例-

http://technet.microsoft.com/en-us/library/ms190312%28v=sql.90%29.aspx http://technet.microsoft.com/zh-cn/library/ms190312%28v=sql.90%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM