Click here to Skip to main content
14,331,823 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,
I need to read excel cell value in C#.net. like value of cell A1 or M33 etc.
Thanks in advance.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 3

Try This Out ,May be would help to you...


if (!Page.IsPostBack)
            {
                Excel.Application appExl;
                Excel.Workbook workbook;
                Excel.Worksheet NwSheet;
                Excel.Range ShtRange;
                appExl = new Excel.ApplicationClass();
 

                  //Opening Excel file(myData.xlsx)
                workbook = appExl.Workbooks.Open(Server.MapPath("myData.xlsx"), Missing.Value, Missing.Value,Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value);

                NwSheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
                int Cnum = 0;
                int Rnum = 0;
     
                ShtRange = NwSheet.UsedRange; //gives the used cells in sheet
               
                  //Reading Excel file.
               //Creating datatable to read the containt of the Sheet in File.
                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Name");
                dt.Columns.Add("Status");
                dt.Columns.Add("Contact");

                for (Rnum = 2; Rnum <= ShtRange.Rows.Count; Rnum++)
                {
                    DataRow dr = dt.NewRow();
//Reading Each Column value From sheet to datatable Colunms                  
                    for (Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
                 {
                       dr[Cnum - 1] = (ShtRange.Cells[Rnum, Cnum] as Excel.Range).Value2.ToString();
                    }
                    dt.Rows.Add(dr); // adding Row into DataTable
                    dt.AcceptChanges();
                }

                workbook.Close(true, Missing.Value, Missing.Value);
                appExl.Quit();

                 gvOne.DataSource = dt;//DataSource to GrigView(Id:gvOne)
                gvOne.DataBind();
      }
   
v2
Comments
Badrinath_subudhi 1-Jun-14 0:46am
   
I have a value "91223456789033" in excel sheet, But when i open excel sheet it is showing as
9.12235E+13. and when i upload this value , it is storing as "9.12235E+13". How to solve this issue?
Rate this:
Please Sign up or sign in to vote.

Solution 2

The power of Google: About 5,850,000 results (0.42 seconds)[^].
   
Comments
Ambesha 23-Oct-12 5:55am
   
:)
PRASHANT KUMAR LAL 23-Oct-12 5:56am
   
I browse but not getting appropriate solution.
CPallini 23-Oct-12 6:04am
   
You should browse better (downvoting won't help you).
Nelek 23-Oct-12 6:21am
   
Countered
BlackMilan 23-Oct-12 6:33am
   
Looks like strike dead from too much results ;-)
Member 7873103 22-Sep-16 1:08am
   
i have 15 digit double in my one cell/column but C# code reading only 7 digit.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100