Reading Excel Cell Value as string

Hi All,

I am trying to read in an Excel worksheet. In a column, the value can be integer or string, for instance ‘50’ or ‘50-60’. I would like to store them as string.

StrValue = excel.Range(“B” + str(ExcelCounter)).value

If the value is ‘50-60’, it behaves normally. However when the value is pure integer like ‘55’ it reads as 5.5e+1. How can I cater them?

You could try the text property instead of the value.

Hi Tony,

Excel defaults the number 55 in Scientific Notation. The way to convert from a number to a string (text) is to use the Format command. Below is an example where cell A1 loads text and reads text, and cell A2 loads an integer and converts the integer to a string.

[code]Dim Excel as New ExcelApplication

excel.Visible = True

excel.Range(“A1”).Value = “50-60” //text
excel.Range(“A2”).Value = “50” //number

TextArea1.Text = excel.Range(“A1”).Value //show text
//convert number to text
TextArea1.Text = TextArea1.Text + Format(excel.Range(“A2”).Value, “#”) [/code]