tags:

views:

104

answers:

5
+1  Q: 

C# export to excel

Hello, Which is the best way to export data to an existing xls sheet. I needs to support many versions of excel. If i was using Visual basic. I would use the CreateObject("Excel.application") code which will do what i need. What is the equivalent in c#? I would love for it to work on any version, and if possible then also computers without ms office at all. Please no 3rd party components that cost money. we are poor :).

TY

A: 

There are built in functions for exporting an ASP.Net grid to excel. It gives a little warning message to the end user but it works.

It is described here: C Sharp Corner

antonlavey
Hi. I use winforms. Thanks for your help anyways.
+1  A: 

I would use ado.net to read/write to excel. This will work if excel is not installed on the machine. I found this link for you that may be helpful.

http://www.davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx

buckbova
Very nice code. TY.
A: 

If you are wanting to Open an excel doc and then add content, one of the easiest way (w/o requiring excel to be installed) is to get a 3rd party lib ( there are probably some open source solutions) that can read and save excel files.

Muad'Dib
A: 

I know you said no third-party but the reason seems to be cost.

The library I use is GemBox. It is free as long as the spreadsheets are not too large (150 rows and 5 worksheets max). For my use this is no problem and it works very well.

http://www.gemboxsoftware.com/GBSpreadsheet.htm

There are also some open source options.

If you are writing to the XML format then ExcelPackage is free (GPL) and may work for you:

http://excelpackage.codeplex.com/

If you want no XML but the other formats, I hear good things about ExcelLibrary (LGPL):

http://code.google.com/p/excellibrary/

There is also a port of the JExcel library (LGPL) to C#:

http://www.chrislaforetsoftware.com/products.html

Justin
FlexCel should also be included.
siride
Thanks siride. I had not heard of FlexCel. Do they have an free version of some kind (OP said he was poor)?
Justin
SpreadsheetGear is also excellent, but not free.
Ben M
Guys I appreciate your help! TY.
+1  A: 

Writing to Excel using C# can be accomplished using the Interop.Excel Here is a nice tutorial with screen shots to help make this happen.

http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm

Edward Leno
That site looks to be packed with great information. It is too bad it is damn ugly.
buckbova