Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want the code that will extract the cell values of an excel file???
Plz help!!!
Posted

Herez sample code to extract excel cell value:

C#
Microsoft.Office.Interop.Excel.Worksheet sheet = newWorkbook.ActiveSheet;
  if ( sheet != null ) {
     Microsoft.Office.Interop.Excel.Range range = sheet.UsedRange;
     if ( range != null )
     {
         int nRows = usedRange.Rows.Count;
         int nCols = usedRange.Columns.Count;
         foreach ( Microsoft.Office.Interop.Excel.Range row in usedRange.Rows )
         {
           string value = row.Cells[0].FormattedValue as string;
         }
     }
  } 
 
Share this answer
 
Comments
Dagma D 19-Jan-12 23:18pm    
hi...
thank you for your reply..
can u tell me which DLL should be linked??
Hi
C#
using Excel = Microsoft.Office.Interop.Excel;

string FilePath="..\MyFile\Demo.xlsx";  \\ path of your file
         ap = new Excel.Application();  \\ creating instance of excel file
        private Excel.Application ap;
        private Excel.Workbook wb;
        private Excel.Worksheet ws1;

rg1 = ws1.get_Range(ws1.Cells[3, 1],ws1.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,Type.Missing));  \\getting values in range object


On google you may find more effective and simple samples.
 
Share this answer
 
Comments
Dagma D 20-Jan-12 0:28am    
Thank you 4 ur reply
comred 20-Jan-12 0:34am    
u r welcome...
if you want to do it in C#/.net the code above is enough.. but I suggest you can improve the performance of the application by reading the complete range of values... another way is to use Open XML skd 2.0 which will be highly efficient and support the standards..
 
Share this answer
 
Comments
Dagma D 20-Jan-12 0:53am    
Thank you...& I'll check Open XML skd 2.0

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