Free Support Forum - aspose.com

Range is Nothing

Hello,

i try to get named ranges from attached Excel-file.

First range is called ‘BIP_range_simple’.
The area includes B1 to C4.
When i use 'GetRangeByName(“BIP_range_simple”) i get a proper range.

Second is called ‘BIP_range_komplex’.
the area includes A1 to A11 plus C1 to C11.
When i use 'GetRangeByName(“BIP_range_komplex”) the range is nothing.

I use Aspose.Cells Version 4.8.1.3

Hi,

Thanks for providing us the template file.

Since “BIP_range_komplex” is defined Name having non sequenced ranges in it, so, you will not use Range object directly. Please use Name API to get the defined Name first. If you want to get the ranges for “BIP_range_komplex”, you can use Name.GetRanges() to obtain an array of ranges ([]Range) in the defined Name. I have created a sample code for your reference, kindly refer to it, it works fine as I tested.

Sample code:

Workbook wb = new Workbook();
wb.Open(“e:\test\range_test.xls”);

Name name = wb.Worksheets.Names[“BIP_range_komplex”];
MessageBox.Show(name.RefersTo); //fine

Range[] ranges = name.GetRanges();

int frow, fcol;
int rowcount, colcount;

if (ranges != null)
{
for (int i = 0; i < ranges.Length; i++)
{
frow = ranges[i].FirstRow;
fcol = ranges[i].FirstColumn;
string f1 = CellsHelper.CellIndexToName(frow, fcol);
MessageBox.Show(ranges[i].FirstRow + “:” + ranges[i].FirstColumn);

rowcount = ranges[i].RowCount - 1 + ranges[i].FirstRow;
colcount = ranges[i].ColumnCount - 1 + ranges[i].FirstColumn;
string f2 = CellsHelper.CellIndexToName(rowcount, colcount);

MessageBox.Show(f1 + “:” + f2);

}
}


Thank you.