Free Support Forum - aspose.com

Aspose.Cells .net Named Ranges not Adjacent cells

Dear,

I'm have a named ranged in excel 2007 of not adjecent spaces. I would like to replace all the values of these cells with the samen value. It's like aspose cells doesn't recognize the named range.

Is this possible with aspose cells ?

Kind regards


This message was posted using Page2Forum from Frequently Asked Questions - Aspose.Cells for .NET

Hi,

When you want to work with non sequenced ranges in the template file, please use Name object rather using Range object. For your scenario, you can first get the Name and then get the ranges from it to fill the Range array. In this way you may get the area of each range included in it and may fill your desired data into different cells of it.

See the sample code below:

Sample code:

Workbook workbook = new Workbook();
workbook.Open(@“e:\test\nonseq\Book1.xls”);
Name name = workbook.Worksheets.Names[“MyRange”];
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);

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.