1
votes

I found many threads related to Date formatting in POI, but could not find exact solution for my problem (have found some workarounds though).

I am creating an empty excel sheet with some headers, some columns are dates, for example start date and end date. I want to force user to provide dates in format - MM/dd/yyyy only. I tried with dataValidationHelper.createDateConstraint(BETWEEN, excelDate1, excelDate2)

Is there any way in which I am not required to provide range for date but just the format.

Also, I need to add validation in poi which will restrict user to provide end date greater than start date. Please help !

1

1 Answers

0
votes

Try this

DataValidationHelper dvHelper = sheet.getDataValidationHelper();
DataValidationConstraint dvConstraint = dvHelper.createDateConstraint(
    OperatorType.BETWEEN,
    ""+DateUtil.getExcelDate(sdf.parse("25/10/2014")),
    ""+DateUtil.getExcelDate(sdf.parse("30/10/2015")), "");