read number and string cell format in c#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • molaeiiut
    New Member
    • Mar 2008
    • 2

    read number and string cell format in c#?

    I want read an exel sheet from my program,i have problem with one column :(
    in this column the value of some cell is just number like 1234667 and some of them is number and text together like 123ADGJ76,for this column i chose text format in exel.
    when i want read this cells in my c# program ,read null for cells that are combined text and number for example if the value of cell =12JGFD76 it read null
    what can i do?!!!!
    plz help me
  • guimel
    New Member
    • Oct 2009
    • 7

    #2
    1. How are you reading your excel sheet ?
    2. You can't put null into a value type (int, double, etc.)
    3. To check if you can convert text into an int:
    Code:
    try{
      int value = int.Parse(text);
    }catch(FormatException){
      //handle failure to convert
    }catch(OverflowException){
     //handle failure to convert
    }
    or
    Code:
      int value;
      bool success = int.TryParse(text, out value);

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      when i want read this cells in my c# program ,read null for cells that are combined text and number for example if the value of cell =12JGFD76 it read null
      what can i do?!!!!
      There is nothing wrong with getting a null returned so long as you check for it.

      Code:
      if (mycell != null)
      {
         // Do something with it
      }
      else
      {
         // Don't try, its null
      }

      Comment

      Working...