Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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

Hello I think this article can help you much, it uses a free data export component, see details:
Exporting Data to Excel[^]
 
Share this answer
 
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 ;)
5) Save and close the workbook. Use Close[^] method with parameter SaveChanges:=True

That's all! Good luck ;)

Examples:
Opening and Navigating Excel with C#[^]
http://csharp.net-informations.com/excel/csharp-open-excel.htm[^]

If you would like to add some data in to existing collection, please let me know.
 
Share this answer
 
v2
EPPlus[^] is a nice library, and the accompanying examples shows you how to do this.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-Sep-12 18:35pm    
My 5.
--SA
Espen Harlinn 21-Sep-12 3:31am    
Thank you, Sergey :-D
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:
http://support.microsoft.com/kb/302084[^]

Good luck
 
Share this answer
 
v2
Comments
IamBlessed 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 20-Sep-12 15:31pm    
You should take a look here then: http://support.microsoft.com/kb/302084
Maciej Los 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 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900