GetRangeByName doesn't retrieve cell format

When I use GetRangeByName to retrieve a cell’s value by it’s name it doesn’t keep the format the cell is using in the Excel file. For example, I have a cell whose value is 1,000,000 using the Number format in Excel. When I retrieve this cell’s value using GetRangeByName it turns it to a Double date type that looks like 1000000 (without the commas). Is this a bug or is there a way I can keep the Number format (or any other format) while using GetRangeByName?

I am using Aspose.Cell version 4.8.2.0 for .NET (Windows forms).

Thanks,

Hi,

If you want to get formatted data (e.g numbers formatted with commas for your case here) from a cell, you should use Cell.StringValue attribute.

See the following example below with comments:

Workbook workbook = new Workbook();
//Open the template excel file.
//This file has a named range i.e. “MyRange1” created on A1 cell
//in the first sheet.
workbook.Open(“e:\test\GetRangeBook1.xls”);
Worksheet worksheet= workbook.Worksheets[0];
Range myRange = workbook.Worksheets.GetRangeByName(“MyRange1”);
//Get the first cell of the range.
Aspose.Cells.Cell cell0 = myRange[0, 0];
MessageBox.Show(cell0.StringValue); //1,000,000 - You should use this to get formatted data of the cell.
MessageBox.Show(cell0.DoubleValue.ToString());//1000000
MessageBox.Show(cell0.Value.ToString());//1000000
MessageBox.Show(cell0.Type.ToString()); //IsNumeric


Thank you.