title: Apache POI Excel Sheet Protection and Data Validation
body: <p>I am using Apache POI to generate Excel File (.xlsx format)</p>
  
  <p>I got stuck with two things.</p>
  
  <p>First,
  I want to disable few features like format cells in the generated excel file.<br><br>
  I have used to following code to achieve it (got it from <a href="https://stackoverflow.com/questions/14701322/apache-poi-how-to-protect-sheet-with-options">Apache POI - How to protect sheet with options?</a>.</p>
  
  <pre><code>sheet.lockDeleteColumns();
  sheet.lockDeleteRows();
  sheet.lockFormatCells();
  sheet.lockFormatColumns();
  sheet.lockFormatRows();
  sheet.lockInsertColumns();
  sheet.lockInsertRows();
  sheet.getCTWorksheet().getSheetProtection().setPassword(pwdBytes);
  sheet.enableLocking();
  workbook.lockStructure();
  </code></pre>
  
  <p>But this code making the generated sheet as read only. I am not able to enter any data in the generated excel sheet.</p>
  
  <p>Please tell me how to disable only few features and enable the read and write at the same time.</p>
  
  <p>Second, there is a date column in Excel file. i want to apply some date validation (something like isValidDate) at column level.</p>
  
  <p>I have tried <em>XSSFDataValidationHelper createCustomConstraint</em>, but no success, validation is not working for date column. when i open the generated excel file i am getting below error </p>
  
  <p><em>Excel found unreadable content in file.</em> </p>
  
  <p>I guess something is wrong in the function(createCustomConstraint("ISNUMBER()");.</p>
  
  <p>Below is code snippet i have used.</p>
  
  <pre><code>XSSFDataValidationConstraint dateConstraint = (XSSFDataValidationConstraint) dvHelper
                  .createCustomConstraint("ISNUMBER()");
          CellRangeAddressList dateAddressList = new CellRangeAddressList(0,
                  10000, 2, 3);//1000rows and 3rd &amp; 4th column
          DataValidation dateValidation = dvHelper.createValidation(
                  dateConstraint, dateAddressList);
          dateValidation.setEmptyCellAllowed(true);
          dateValidation.setErrorStyle(DataValidation.ErrorStyle.STOP);
          dateValidation.createErrorBox("Error", "InValid Date.");
          dateValidation.setShowErrorBox(true);
          sheet.addValidationData(dateValidation);
  </code></pre>
  
  <p>Please help me to solve these two issues.</p>
  
  <p>Thanks in Advance.</p>