Hello,
Is there a way to retrieve a named range if it has multiple Ranges? Excel supports this kind of Named Ranges, but when I try to read them with GetRangeByName(rangeName) I get a null - so this method works only for single-range Named Ranges. I guess this makes sense since the return type is Range, not a collection of ranges, but I would like to be able to retrieve the content from all the ranges that make up a named range.
We need this feature especially for Print Areas, so if there is a way to retrieve those it would be very appreciated .
Thanks,
Ruxandra
Hi Ruxandra,
Thank you for contacting Aspose support.
Please be kind enough to share a sample spreadsheet containing the mentioned Named Range. Please also state the name of the range if there are multiple ranges in the spreadsheet. We will test the scenario on our side, and log an enhancement (if required) by forwarding the sample to product team.
Hi,
I’m attaching the file that contains a print area range with multiple cells / ranges. The range is created using the standard Set Print Area feature in Excel.
Have a nice weekend!
Hi,
Thanks for the template file.
Well, you may try to use Name collection and Name object(s) to retrieve the multiple range(s). See the following sample code that may help you to accomplish the task a bit:
e.g
Sample code:
Workbook workbook = new Workbook(“e:\test2\PrintArea.xlsx”);
//Get the worksheet scoped named range
Name name = workbook.Worksheets.Names[“Sheet1!Print_Area”];
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);
}
}
Hope, this helps a bit.
Thank you.