我实现了一个代码,该代码在指定范围内的单元格上添加了数据验证,但包含,
的值被分块...
这是我的代码
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);
而不是
US punctuation + alphanumeric lowercase:[a-z0-9,.?;:!&()_'"]+
US punctuation + alphanumeric uppercase:[A-Z0-9,.?;:!&()_'"
US punctuation + alphanumeric mixedcase:[A-Za-z0-9,.?;:!&()_'"
答案 0 :(得分:1)
将列表放入范围并引用数据验证的范围。这里有一些伪代码可以帮助您入门:
// 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);