473,498 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read number and string cell format in c#?

2 New Member
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
Oct 22 '09 #1
2 3438
guimel
7 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. try{
  2.   int value = int.Parse(text);
  3. }catch(FormatException){
  4.   //handle failure to convert
  5. }catch(OverflowException){
  6.  //handle failure to convert
  7. }
  8.  
or
Expand|Select|Wrap|Line Numbers
  1.   int value;
  2.   bool success = int.TryParse(text, out value);
  3.  
Oct 22 '09 #2
tlhintoq
3,525 Recognized Expert Specialist
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.

Expand|Select|Wrap|Line Numbers
  1. if (mycell != null)
  2. {
  3.    // Do something with it
  4. }
  5. else
  6. {
  7.    // Don't try, its null
  8. }
Oct 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2681
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
1
2963
by: Michel | last post by:
Hi all, This is my first post, so I am very new at this. I am trying to use page-number-citation twice in my code, but the second time it just shows '0'. The output is in pdf format and I am...
0
4674
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
0
6252
by: rascal_mon | last post by:
I'm new with XML. Please give me some advice. I wonder there are any difference between XML that is automatically generated from ADO and XML file that shows in many textbooks. I found that the...
12
5989
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
6
8133
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
3
6221
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
5362
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
1
15263
by: Magnus.Moraberg | last post by:
Hi, I have the following event which checks if a cell in a dgv contains a date and if so, checks if it is formatted correctly. I don't think its good practice for be to try this by catching an...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.