我实现,增加了数据验证在细胞从指定范围内的代码,但包含,
值被分块成片......C#互操作的格式确认列表
这是我的代码
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,.?;:!&()_'"
'XlDVType.xlValidateList'基本上使单元格下拉框。你可以做的最好的办法是使用'xlValidateCustom'和一个狡猾的公式,因为excel不支持公式中的正则表达式,但是vba会。 – Xiaoy312
这里有两个不错的答案:http://stackoverflow.com/questions/30724178/create-data-validation-list-when-some-of-the-values-have-commas – reasra
我不知道如何转换vba代码从那个答案到c#... – Valip