title: How to lock data in excel sheet using POI, leaving cells without any data / the rest of the sheet unlocked
body: <p>I am trying to lock the data within an Excel Worksheet so that it is not possible to edit the data already written to the Worksheet, but leaving the rest of the empty spaces free for editing/ adding more data. </p>
  
  <p>I have tried going through the whole sheet trying to set the cell style, using the code provided below but it is only the relevant code, but it doesn't work, which agrees to this question already asked</p>
  
  <p><a href="https://stackoverflow.com/questions/8397169/lock-single-column-in-excel-using-apache-poi">Lock single column in Excel using Apache POI</a></p>
  
  <pre><code>XSSFCellStyle lockCell = getFileWriter().getWorkbook().createCellStyle();
  lockCell.setLocked(true);
  for(Row row : sheet){
      for(Cell mycell : row){
          mycell.setCellStyle(lockCell);
      }
  }
  </code></pre>
  
  <p>the opposite: by locking the whole sheet and setting the relevant rows' cell style to unlock, I have tried that but the cells without any data don't unlock and so it hasn't worked for me. In any case how far and wide should one unlock the cells as it is not known how much space is needed for the unknown amount of data to be added.  </p>
  
  <p>Any help or suggestions would be greatly appreciated.</p>