This project has moved and is read-only. For the latest updates, please go here.

Cell date validation and format

Mar 5, 2015 at 6:08 PM
Hi, can someone help me? I want to make certain cells to take only date, and in this format dd/MM/yyyy this is my code now

int columnNumber = worksheet.Cells[nroPreguntas, i].Start.Column;

string cell = getColumnLetter(columnNumber ) +Convert.ToString(nQuestions);

var validation = worksheet.Cells[cell].DataValidation.AddDateTimeDataValidation();
validation.ShowErrorMessage = true;
validation.ErrorStyle = ExcelDataValidationWarningStyle.stop;
validation.Error = "invalid date";
validation.ShowInputMessage = true;
validation.Prompt = "insert date here";
validation.Operator = ExcelDataValidationOperator.greaterThan;
worksheet.Cells[celda].Style.Numberformat.Format = "dd/MM/yyyy";
validation.Formula.Value = DateTime.Now.Date;

for now, it only takes dates, but in MM/dd/yyyy format,