C#Interop格式validation列表

我实现了一个代码,将数据validation添加到指定范围的单元格中,但是包含的值被分块化。

这是我的代码

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

这是我在validation列表中得到的:
在这里输入图像说明

代替

 US punctuation + alphanumeric lowercase:[a-z0-9,.?;:!&()_'"]+ US punctuation + alphanumeric uppercase:[A-Z0-9,.?;:!&()_'" US punctuation + alphanumeric mixedcase:[A-Za-z0-9,.?;:!&()_'" 

将列表获取到一个范围内并引用数据validation的范围。 这里有一些伪代码来帮助你开始:

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