C# 互操作格式验证列表

C# Interop format Validation List

我实现了一个代码,在指定范围内的单元格上添加数据验证,但包含 , 的值被分成几块...

这是我的代码

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,.?;:!&()_'"  

将列表放入一个范围内并引用该范围进行数据验证。这里有一些伪代码可以帮助您入门:

// 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);