C#Interop格式验证列表 [英] C# Interop format Validation List

查看:308
本文介绍了C#Interop格式验证列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I implemented a code that adds Data Validation on cells from a specified range, but the values that contain , are chunked into pieces...

这是我的代码

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

这是我在验证列表中获得的:

< a href =https://i.stack.imgur.com/hAsgD.jpg =nofollow noreferrer>

And this is what I get in the Validation List:

而不是

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

这篇关于C#Interop格式验证列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆