Excel & EPPlus .NET library: Advanced DropDown list validation

后端 未结 1 1733
刺人心
刺人心 2021-01-12 05:01

In Epplus, when we create a DropDown list for some cells in excel file, then user put a value which is not part of the list, the cell show a message says: value must match o

1条回答
  •  深忆病人
    2021-01-12 05:08

    I did it with the following code:

    //ExcelWorksheet ws
    var validation = ws.DataValidations.AddListValidation(cell.Address);
    //Error handling
    validation.ShowErrorMessage = true;
    validation.ErrorStyle = ExcelDataValidationWarningStyle.stop;
    validation.ErrorTitle = "Error";
    validation.Error = "Error Text";
    // sheet with a name : DropDownLists 
    // from DropDownLists sheet, get values from cells: !$A$1:$A$10
    var formula = "=DropDownLists!$A$1:$A$10";
    //Applying Formula to the range
    validation.Formula.ExcelFormula = formula;
    

    0 讨论(0)
提交回复
热议问题