我想使用 EPPlus 验证 Excel 中的列,时间范围为下午 1:00 到上午 11:00。
时间必须是“hh:mm AM/PM”格式。
我解决了这个问题。这是代码:
var validationEndTime = workSheet.DataValidations.AddTimeValidation("H:H");
validationEndTime.ShowInputMessage = true;
validationEndTime.Prompt = "Add end time in hh:mm AM/PM format as example 9:00 AM or 12:30 PM";
validationEndTime.ErrorStyle = ExcelDataValidationWarningStyle.stop;
validationEndTime.ShowErrorMessage = true;
validationEndTime.Error = "Insert valid time";
validationStartDate.Operator = ExcelDataValidationOperator.between;
var timeEnd = validationStartDate.Formula.Value;
timeEnd.Hour = 00;
timeEnd.Minute = 00;
var timeEnd2 = validationStartDate.Formula2.Value;
timeEnd2.Hour = 23;
timeEnd2.Minute = 59;
validationEndTime.Formula.Value = timeEnd;
validationEndTime.Formula2.Value = timeEnd2;
这将像这样在 excel 中进行验证: