views:

451

answers:

6

Hi anybody working on data exporting? I've 4 tables in my sql server database. I want to export these 4 tables data into one excel file in different sheets with column names.

Is it possible?

Thanks in advance

+1  A: 

You can to create an OpenXML Excel document (XSLX) through Open XML Format SDK 1.0. Example: Creating spreadsheets from a server application

If you can to drop that multiple worksheets requirement, that would be a lot easier.

Rubens Farias
+1  A: 

yes. You're best off sucking the data in from excel using the copyfromrecordset method

dim conn as new adodb.connection
conn.connectionString = "..."
conn.open

dim sql as string
sql = "..."

sheet1.cells(1,1).copyFromRecordset conn.execute(sql)
Nick
You should to explain OP will need to open a Excel workbook through Interop, just as a template, and to place that database values inside it. It's a nice suggestion too.
Rubens Farias
+1  A: 

There have been lots of previous questions about this. Look here: http://stackoverflow.com/questions/tagged/excel

One component that does what you want is the open-source myXls.

Rune Grimstad
A: 

Try this link

Import / export data in MS Excel using C#

Anuraj
A: 

You can use SpreadsheetML, which is just a schema that will let you define a workbook with multiple sheets in xml that Excel will open natively. I have an example here:

http://stackoverflow.com/questions/150339/generating-an-excel-file-in-asp-net/150368#150368

Joel Coehoorn
A: 

You can export data set to multi sheet excel file in just one line of code. For Details see this link:-

Export To Excel in .Net

Zeeshan Umar