C# Interop format Validation List

妖精的绣舞 提交于 2019-12-24 09:17:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!