我實現,增加了數據驗證在細胞從指定範圍內的代碼,但包含,
值被分塊成片......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