簡體   English   中英

我們可以使用單元格范圍驗證從 EPPLUS 的另一張表中填充 excel 中的下拉列表嗎

[英]Can we use Cell Range Validation to populate a dropdown list in excel from another sheet in EPPLUS

我是使用 EPplus 的新手。 我實際上想從Sheet2中的值列表填充Sheet1 中的下拉列表。 這可以通過 Excel 中的單元格范圍驗證來實現。但我不確定 EPPlus 是否以編程方式支持這一點。 如果有人可以幫助我,那將非常有幫助。 從表 2中的名稱列填充此名稱列中的下拉列表。表 2

這是如何做到的:

var departmentSheet = excel.Workbook.Worksheets.Add("department");
departmentSheet.Cells["A1"].Value = "Management";
departmentSheet.Cells["A2"].Value = "Administrator";
departmentSheet.Cells["A3"].Value = "Quality Engineering";
departmentSheet.Cells["A4"].Value = "Enablers";

var designationSheet = excel.Workbook.Worksheets.Add("designations");
designationSheet.Cells["A1"].Value = "Developer 1";
designationSheet.Cells["A2"].Value = "Developer 2";
designationSheet.Cells["A3"].Value = "Developer 3";
designationSheet.Cells["A4"].Value = "Developer 4";

// add a validation and set values
// the range of cells that will contain the validation
var validation = departmentSheet.DataValidations.AddListValidation("B1:B4");

// set validation rules as required
validation.ShowErrorMessage = true;
validation.ErrorStyle = ExcelDataValidationWarningStyle.warning;
validation.ErrorTitle = "An invalid value was entered";
validation.Error = "Select a value from the list";

// set the range that contains the validation list
validation.Formula.ExcelFormula = $"={ designationSheet.Name }!$A$1:$A$4";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM