Creating XLS Files in C#

If you need to create XLS files in .NET, I suggest you to use the following open-source libraries:

Import Data from Excel with T-SQL

Here are the two examples of importing data from Excel into SQL Server using T-SQL: both tecniques use the OPENROWSET function:

--Excel 97-2003
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;HDR=YES;IMEX=1;Database=C:\MyExcel.xls', 'SELECT * FROM [Sheet1$]')

--Excel 2007-2010
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;IMEX=1;Database=C:\MyExcel.xlsx', 'SELECT * FROM [Sheet1$]')

If you are unable to use the OPENROWSET function, you need to do the following:

sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO

sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO