Click here to Skip to main content
12,951,971 members (64,345 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
 
good
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
  Permalink  
Comments
Sergey Alexandrovich Kryukov 20-Sep-12 18:35pm
   
My 5.
--SA
Espen Harlinn 21-Sep-12 3:31am
   
Thank you, Sergey :-D
Rate this: bad
 
good
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:
http://support.microsoft.com/kb/302084[^]

Good luck
  Permalink  
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.
Rate this: bad
 
good
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 ;)
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.
  Permalink  
v2
Rate this: bad
 
good
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[^]
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2017
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