/// <summary> /// Gets the name of the safe sheet. /// </summary> /// <param name="sheets">The sheets.</param> /// <param name="proposedName">Name of the proposed.</param> /// <returns></returns> public static string GetSafeSheetName(this Sheets sheets, string proposedName) { if (sheets.HasSheetWithName(proposedName)) { int number = 0; string stem = GetNameStemAndNumericTrailer(proposedName, out number); number++; string trailer = string.Concat("~", number.ToString()); // Work out max permitted stem length if ((stem.Length + trailer.Length) > Constants.SheetNameMaxLength) { stem = stem.Substring(0, Constants.SheetNameMaxLength - trailer.Length); } string proposedNewName = string.Concat(stem, trailer); if (sheets.HasSheetWithName(proposedNewName)) { // Recurse until we get a safe name return(GetSafeSheetName(sheets, proposedNewName)); } return(proposedNewName); } else { return(proposedName); } }