Free Support Forum - aspose.com

Cells.Characters with Integers

Howdy,

I wanted to confirm a note that I read on your website regarding Cells.Characters. According to your remark, the code only works with string values, does this mean if the data within an Excel cell was a number (E.G 12.34), it wouldn't work?

If it doesn't work, is there a way of being able to specify a range of characters in a number?

Cheers,

James

Hi,

Yes, Cell.Characters method only works for string values, so, you cannot format (apply font attributes etc.) selected characters in a numeric value. The behavior is same as MS Excel, you may confirm.

But if you want to just extract some numeric characters from a number, you may simply use String.Substring() method to extract your desired range of characters.

e.g

Worksheet worksheet = excel.Worksheets[0];
Cells cells = worksheet.Cells;
//Get the numeric cell.
Aspose.Cells.Cell cell = cells[0, 0];

//Extract the first three chars in the number.
string myval = cell.StringValue.Substring(0, 3);
MessageBox.Show(val);


Thank you.

Thank you for the response, exactly what I needed.