private static bool TryParseInteger(string text, out int value) { value = 0; if (!text.StartsWith("#")) { return(false); } text = text.Substring(1).Trim(); if (int.TryParse(text, out value)) { return(true); } var match = ExcelColumnShorthandRegex.Match(text); if (!match.Success) { return(false); } value = ConvertExcelColumnToIndex(match.Groups["columnName"].Value.Trim()); return(true); }
private static bool TryParseInteger(string text, out int value) { value = default; if (!text.StartsWith("#")) { return(false); } text = text.Substring(1).Trim(); if (int.TryParse(text, out value)) { return(true); } var match = ExcelColumnShorthandRegex.Match(text); if (!match.Success) { return(false); } value = ConvertExcelColumnToIndex(match.Groups["columnName"].Value.Trim()); const int minExcelColumnIndex = 1; const int maxExcelColumnIndex = 16384; if (value < minExcelColumnIndex || value > maxExcelColumnIndex) { // This ducks around weird edge cases like when a column named "# Sections" converts the "Sections" text to a weird -424898077 value. value = default; return(false); } return(true); }