Click here to Skip to main content
11,805,604 members (54,539 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET C#4.0 .NET4
Hi guys i have a collection list that contains data, i want to export the data in the collection list to a sheet in an already existing excel file. How do i do that?
Posted 20-Sep-12 9:17am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

EPPlus[^] is a nice library, and the accompanying examples shows you how to do this.

Best regards
Espen Harlinn
Sergey Alexandrovich Kryukov at 20-Sep-12 18:35pm
My 5.
Espen Harlinn at 21-Sep-12 3:31am
Thank you, Sergey :-D
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I would use Sheet.UsedRange and then hard code to find out were you want to add the cells. You dont give us much code to go on so,:

See sample here:[^]

Good luck
IamBlessed at 20-Sep-12 15:28pm
Have not writing any single code on exporting to excel, and the excel sheet is empty. I hav virtually no clue on what to do
Kenneth Haugland at 20-Sep-12 15:31pm
You should take a look here then:
Maciej Los at 20-Sep-12 17:01pm
UsedRange (object type of Range) is the collection of used cells in a worksheet. It can be one or more ranges (collections of data), for example: A1:C300 and E1:AH5000. In this case UsedRange object will contains cells: A1:AH5000.
Do you know what i mean?
Kenneth Haugland at 20-Sep-12 17:07pm
I guess so, If cell(1,1) is in use, and cell(69000,69000) is in use the UsedRange will returne a 69000 * 69000 values.

But as he was going to make and rewrite the excel sheet from application, i dont think thats a problem.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If you would like to replace existing data, you need to go through these steps:
1) Create the instance of MS Excel application. How? You can use Interop[^] or OLE Automation[^].
2) Open existing workbook,
3) Clear existing data,
4) Export data from your application, using for .. next loop or CopyFromRecordset[^] method for Range object. Personally, i prefer CopyFromRecordset because it's quick Wink | ;)
5) Save and close the workbook. Use Close[^] method with parameter SaveChanges:=True

That's all! Good luck Wink | ;)

Opening and Navigating Excel with C#[^][^]

If you would like to add some data in to existing collection, please let me know.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Hello I think this article can help you much, it uses a free data export component, see details:
Exporting Data to Excel[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 310
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 128
4 ppolymorphe 125
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100