Unplanned
Last Updated: 21 Sep 2017 08:33 by ADMIN
ADMIN
Deyan
Created on: 25 Apr 2016 17:20
Category: SpreadProcessing
Type: Feature Request
14
SpreadProcessing: Add API to get the list of ranges to which a defined name refers
Add API to get the list of ranges to which a defined name refers.

Example:
List<CellRange> ranges = workbook.Names["definedName"].Ranges;
CellSelection selection = worksheet.Cells[ranges];

The cell range referred by the defined name could be accessed using code similar to the following one:
foreach (var name in workbook.Names)
{
    if (name.Name == givenName)
    {
        string[] v = name.RefersTo.Split("!".ToCharArray());

        foreach (Worksheet sheet in workbook.Sheets)
        {
            if (sheet.Name.ToUpper() == v[0].Replace("=", String.Empty).ToUpper())
            {
                string rangeName = v[1];
                string firstIndexName = rangeName.Split(":".ToCharArray())[0];

                int rowIndex;
                int columnIndex;
                bool isRowAbsolute;
                bool isColumnAbsolute;
                bool nameRefersToIndex = NameConverter.TryConvertCellNameToIndex(firstIndexName, out isRowAbsolute, out rowIndex, out isColumnAbsolute, out columnIndex);

                if (nameRefersToIndex)
                {
                    sheet.Cells[rowIndex, columnIndex].SetValue(givenValue);
                }
            }
        }
    }
}

0 comments