简体   繁体   中英

Import Multiple Excel files to SQL Server

I have about 40+ excel files that I would like to import to SQL Server 2012. The import wizard is a great tool but it only allows me to import one file at a time.

I want to avoid using SSIS because the import should be relatively easy - basically it is just a direct copy-paste with the first row in the Excel files being the column names, and the Excel Files name = Table Name.

Is there any easy way to achieve this?

Edited: Since the columns will change quite frequently, I would like to avoid creating the tables manually. The wizard is great because it will create the table for me automatically.

A solution I used is to combine multiple Excel files into one with multiple sheets. This can be done by running a VBA script (for example How to merge Excel files with VBA - thanks to Svetlana Cheusheva ) then use the SSMS import wizard to load multiple sheets into multiple tables. In my case, I have 160 files, but they are not very big — 100 to 10000 rows — and it worked perfectly for me.

You can do it using OpenRowSet. The OPENROWSET function can be referenced in the FROM clause of a query as though it is a table name.

Read excel using the following SELECT statement together with the OPENROWSET function

SELECT * 
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
                'SELECT * FROM [Sheet1$]')

To import this to a SQL Server table without using DTS, since you are able to read the data using the SELECT statement, you can simply add the INTO clause to insert the records into a new SQL Server table.

SELECT * 
INTO [dbo].[Addresses_NewTable]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
                'SELECT * FROM [Sheet1$]')

Reference article:- http://www.sql-server-helper.com/tips/read-import-excel-file-p03.aspx

It may be more research than you want to put into your problem, but you might also look into using BIML to script out the tedious and numerous similar packages.

http://www.sqlservercentral.com/stairway/100550/ http://www.mssqltips.com/sqlservertip/3094/introduction-to-business-intelligence-markup-language-biml-for-ssis/

Use Kutools for Excel to merge the worksheets across workbooks into one worksheet in a new workbook and then load that.

https://www.extendoffice.com/product/kutools-for-excel/merge-excel-wordbooks.html#a4

That's what I'm doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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