/// <summary> /// Creates a new named range with a name in the format [SHEET_NAME]_[NAME]. /// Any non-alphanumeric characters are replaced with an underscore. /// If an existing named range exists with the same name then an underscore /// followed by a number is added. /// </summary> /// <param name="workbook">The workbook.</param> /// <param name="sheetName">Name of the sheet.</param> /// <param name="name">The name of the named range.</param> /// <param name="columnIndex">Index of the column.</param> /// <param name="rowIndex">Index of the row.</param> /// <param name="columnCount">The number of columns in the named range.</param> /// <param name="rowCount">The number of rows in the named range.</param> public static void AddDefinedName( this Workbook workbook, string sheetName, string name, uint columnIndex, uint rowIndex, int columnCount, int rowCount) { if (workbook.DefinedNames == null) { workbook.DefinedNames = new DefinedNames(); } string formattedName = FormatName(workbook.DefinedNames, name); string start = CellExtensions.GetCellFormula(columnIndex, rowIndex); string finish = CellExtensions.GetCellFormula( (uint)(columnIndex + columnCount - 1), (uint)(rowIndex + rowCount - 1)); workbook.DefinedNames.Append( new DefinedName() { Name = formattedName, Text = string.Format("\'{0}\'!{1}:{2}", sheetName, start, finish) }); }