We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

GetRangeByName() returning null all the time

Hello all. I recently ugraded to the latest version 5.x dll and i am experiencing issues. I exported an excel file using aspose and then try to upload it into our system as i need only a range of data I use the aspose Range class but i always get back a null value altho by zooming out i clearly see the range name. And the exact thing was working before I upgraded my dll.

The following is the piece of code i use to read from the excel work bok:

Workbook workbook = new Workbook();

LoadOptions lo;

MemoryStream ms = null;

string excelformaterror = String.Empty;

try

{

ms = new MemoryStream(excelFile);

try

{

lo = new LoadOptions(LoadFormat.Excel97To2003);

workbook = new Workbook(ms, lo);

}

catch

{

lo = new LoadOptions(LoadFormat.Xlsx);

workbook = new Workbook(ms, lo);

}

}

catch (Exception ex)

{

excelformaterror = ex.Message;

}

finally

{

if (ms != null)

ms.Close();

}

Range forecastDataRange = workbook.Worksheets.GetRangeByName("Current Forecast");

and the forecastDataRange always returns a null value. I am also attaching the excel file that I am trying to upload. Again by reducing the zoom factor to 25% you can see the range name. Thany in advance for any help.

Hi,

Please change your codes as:
Range range = workbook.Worksheets.GetRangeByName("CurrentForecast");

This will resolve the issue. If the issue persist, please feel free to reach us.

Thanks,

Hey thank you guys that solved the issue, it was a bit starnge though as in the prev versions it worked with the space. I have another issue After upgrading to the latest aspose dll I get Excel 2007 support. So if I save the previously attached file as an xlsx file i see the range name changed from “Current Forecats” to “_1Current_Forecast” when I zoom out is this normal. Also how do i get the range names in a workbook. I tried workbook.worksheet.Names[0] but dint work for me. Thansk in advance.