Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# C#4.0 .NET4 WinForm
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 4

Hello I think this article can help you much, it uses a free data export component, see details:
Exporting Data to Excel[^]
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.

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

  Print Answers RSS
0 Maciej Los 645
1 OriginalGriff 453
2 CPallini 239
3 CHill60 180
4 Peter Leow 175
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,898
2 Maciej Los 3,159
3 Peter Leow 3,129
4 DamithSL 2,490

Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2014
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