问题
I implemented a code that adds Data Validation on cells from a specified range, but the values that contain ,
are chunked into pieces...
This is my code
var listFormats = new List<string>();
listFormats.Add("US punctuation + alphanumeric lowercase:[a-z0-9,.?;:!&()_'" + '"' + "]+");
listFormats.Add("US punctuation + alphanumeric uppercase:[A-Z0-9,.?;:!&()_'" + '"' + "]+");
listFormats.Add("US punctuation + alphanumeric mixedcase:[A-Za-z0-9,.?;:!&()_'" + '"' + "]+");
var flatListFormats = string.Join(",", listFormats.ToArray());
rng.Validation.Add(XlDVType.xlValidateList, XlDVAlertStyle.xlValidAlertInformation, XlFormatConditionOperator.xlBetween, flatListDelimiters, Type.Missing);
And this is what I get in the Validation List:
Instead of
US punctuation + alphanumeric lowercase:[a-z0-9,.?;:!&()_'"]+
US punctuation + alphanumeric uppercase:[A-Z0-9,.?;:!&()_'"
US punctuation + alphanumeric mixedcase:[A-Za-z0-9,.?;:!&()_'"
回答1:
Get the list into a range and reference the range for the data validation. Here's some pseudo code to get you started:
// Get the list you want into a cell range
worksheet.Range("A1:A3").Value = listFormats;
// Reference the range when applying the validation
rng.Validation.Delete();
rng.Validation.Add(... xlBetween, "='" + worksheet.Name + "'!" + worksheet.Range("A1:A3").Address);
来源:https://stackoverflow.com/questions/42703424/c-sharp-interop-format-validation-list