Subscribe:

Pages

Thursday, September 15, 2011

Retrive data from excel file in code behind

There are two ways to implement this scenario.
          i. create a OleDbConnection and work with like a Database
          ii. using excel data library and get its functionality
                                    I think second one is the better solution to doing this.

1. Import excel library into the class
   
          I assign a library  to simple word(Excel) for working easily

2. Create objects
 

3. Assign values
   

 4. Assign values to object

                 In this case you can open all sheets in workbook, only doing is parsing a specific sheet number which you need to open. Further details you can access the Workbooks.Open Method

5. Get the data range in excel file and fill it to the ArrayList
   

6. Save your data in excel sheet
   
            You can change rowNo & columnNo. This is the cell position which you want to save your data.

7. Close the application
   

8. Finlay you must release all the excel objects.
   
                                   In this application I also release the xlWorkBook object and xlWorkSheet object.

No comments:

Post a Comment