cb1295
cb1295

Reputation: 753

Get Data Into Excel from WinForm

Ok, So I have a form, that is filled in with a customers address, purchase info etc. Now, I want to get that data into Excel, having a column for the quantities of each product purchased, the name of the person, their email, etc. Each customer would have their own row. My program is coded in C#, it is a winform. Now, I am a bit of a beginner and I have only put data into a ListBox before. Would it be easy to do ListBox to Excel or is there a better way to go about this?

Upvotes: 0

Views: 2559

Answers (5)

user680607
user680607

Reputation: 13

You can also do this through ADO using Excel as a database. This is an older article and deals with Visual Basic or VBA, but you should be able to convert the concept to C# easily enough. It doesn't require Excel to be on your machine.

http://support.microsoft.com/kb/257819

If you haven't inserted data using ADO, this should point you in the right direction, though it is dealing with Access here, so you want to use the connection string from the article above:

http://www.java2s.com/Code/ASP/ADO.net-Database/InsertdatatodatabaseusingSQLC.htm

Upvotes: 1

Yahia
Yahia

Reputation: 70369

For creating/modiyfing/reading/writing Office files (including Excel, Word etc.) there is a free SDK from MS you can use called OpenXML SDK 2.0 - you can download it here.

IF the features are not enough there are other free and commercial SDKs out there - to recommend something it would help to know more about your requirements.

Upvotes: 0

TheBlastOne
TheBlastOne

Reputation: 4320

Possible the easiest solution: You could create a comma-separated (csv) file with column headers, and give them the extension .xls. Excel will open them and at least understand the column structure.

The "xls" file will be a csv file, but for readonly results, it is totally sufficient in astoundingly many cases.

Using Interop is a bigger task, for example just getting rid of the Excel instance you created is a piece of high arts (or dark magic).

Upvotes: 0

BizApps
BizApps

Reputation: 6130

I am using this on my Apps from Codeplex.

Excel Data Reader - Read Excel files in .NET

Regards

Upvotes: 1

Josh O'Bryan
Josh O'Bryan

Reputation: 327

I'd recommend referencing Microsoft.Office.Interop.Excel . For more information on how to do this follow this guide.

http://msdn.microsoft.com/en-us/library/dd264733.aspx

Upvotes: 4

Related Questions