2using System.Text.RegularExpressions;
24 string argbMessage = ValidateColorInternal(hexCode,
true, allowEmpty);
25 string rgbMessage =
null;
26 if (argbMessage !=
null)
28 rgbMessage = ValidateColorInternal(hexCode,
false, allowEmpty);
29 if (rgbMessage !=
null)
43 public static void ValidateColor(
string hexCode,
bool useAlpha,
bool allowEmpty =
false)
45 string message = ValidateColorInternal(hexCode, useAlpha, allowEmpty);
61 bool isCellAddress =
false;
63 Exception lastException =
null;
92 System.FormatException innerException =
new System.FormatException(
"The expression (" + expression +
") is a single cell address, but a cell range was expected");
101 throw new FormatException(
"The passed expression is valid cell address or range, but the validation was explicitly inverted");
112 if (
string.IsNullOrEmpty(name))
120 Regex regex =
new Regex(
@"[\[\]\*\?/\\]");
121 Match match = regex.Match(name);
122 if (match.Captures.Count > 0)
124 throw new FormatException(
@"the worksheet name must not contain the characters [ ] * ? / \ ");
135 private static string ValidateColorInternal(
string hexCode,
bool useAlpha,
bool allowEmpty)
137 if (
string.IsNullOrEmpty(hexCode))
143 return "The color expression cannot be null or empty";
146 int length = useAlpha ? 8 : 6;
147 if (hexCode.Length != length)
149 return "The value '" + hexCode +
"' is invalid. A valid value must contain " + length +
" hex characters";
151 if (!Regex.IsMatch(hexCode,
"[a-fA-F0-9]{6,8}"))
153 return "The expression '" + hexCode +
"' is not a valid hex value";
Class representing a cell of a worksheet.
static Address ResolveCellCoordinate(string address)
Gets the column and row number (zero based) of a cell by the address.
static Range ResolveCellRange(string range)
Resolves a cell range from the format like A1:B3 or AAD556:AAD1000.
AddressScope
Enum to define the scope of a passed address string (used in static context).
Class for exceptions regarding Style incidents.
Class providing general validator methods.
static void ValidateWorksheetName(string name)
Validates the passed string, whether it is an expression that can be used as worksheet name.
static void ValidateCellAddressExpression(string expression, Cell.AddressScope scope=Cell.AddressScope.Any)
Validates the passed string, whether it is a valid single cell address or cell range....
static void ValidateGenericColor(string hexCode, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills,...
static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills,...
Class representing a worksheet of a workbook.
static readonly int MaxWorksheetNameLength
Maximum number of characters a worksheet name can have.