复制代码
//List数据验证
// Specify the validation area.
CellArea area;
area.StartRow = 3;
area.EndRow = 100;
area.StartColumn = 6;
area.EndColumn = 6;
// Get the validations collection.
ValidationCollection validations = sheet.Validations;
// Create a new validation to the validations list.
Validation validation = validations[validations.Add(area)];
// Set the validation type.
validation.Type = Aspose.Cells.ValidationType.List;
// Set the operator.
validation.Operator = OperatorType.None;
// Set the in cell drop down.
validation.InCellDropDown = true;
// Set the formula1.
validation.Formula1 = "呵呵,搜索,水水时,我的,你啊";
// Enable it to show error.
validation.ShowError = true;
// Set the alert type severity level.
validation.AlertStyle = ValidationAlertType.Stop;
// Set the error title.
validation.ErrorTitle = "错误";
// Set the error message.
validation.ErrorMessage = "请选取下拉列表的值";
这段代码只能给指定的3-100行添加下拉列表,但是我想给3-excel最大限制行数添加下拉列表,怎么让area.EndRow 的值为excel最大限制行数(整列设置)?
cells.MaxRow和cells.MaxDataRow 都只能获取已有数据行数或者已设置样式的行数。不能获取excel最大限制行数。
我在exel当中操作是先选中整列,再单独去除选择列的0,1,2行。再进行数据验证序列设置。这样就把第7列的3-excel最大行数的所有单元格设置成了下拉列表。
va1.png (36.0 KB)