title: Unable to delete row using Apache POI because the cell contains email address
body: <p>I am using Apache POI 3.17 to open xlsx spreadsheet , read the <code>row =1</code> (row = 0 is the header that should stay there), store the values in my object, and then remove the <code>row =1</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/Dn5nU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dn5nU.jpg" alt="enter image description here"></a></p>
  
  <p>I expect after removal , <code>row = 2</code> will become <code>row = 1</code> and <code>last row</code> will become <code>last row -1</code>.   This is my codes: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    private static void removeRow (String pathToExcel ) throws InvalidFormatException {
  
          try {
  
              FileInputStream file = new FileInputStream(pathToExcel);
  
              Workbook workbook = WorkbookFactory.create(file);
              Sheet sheet = workbook.getSheetAt(0);
              int lastRowNum = sheet.getLastRowNum();
              sheet.shiftRows( 2, lastRowNum, -1);
  
              file.close();
  
              FileOutputStream outFile =new FileOutputStream(new File(pathToExcel));
              workbook.write(outFile);
              outFile.close();
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    public static void main(String[] args) throws InvalidFormatException {
          removeRow(PATH_TO_EXCEL);
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>When removing the row = 1  , I get </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Invalid CellReference: D3:D21
  at org.apache.poi.ss.util.CellReference.separateRefParts(CellReference.java:395)
  at org.apache.poi.ss.util.CellReference.&lt;init&gt;(CellReference.java:113)
  at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:3024)
  at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2966)
  at Sandbox.ExcelReader.removeRow(ExcelReader.java:177)
  </code></pre>
  
  <p>I am not sure why it complains about Invalid CellReference ?</p>
  
  <p>Thanks. </p>
  
  <p><strong>Updated:</strong>  I find the issue, apparently POI doesn't like the entire column D which contains email address format <code>testing@testing.com</code> , once I remove the entire column D , POI doesn't throw exception anymore. I am wondering why it doesn't like email address format.  The spreadsheet must contain email address. </p>
  
  <p><strong>Updated 2 (After Axel's Suggestion)</strong> :</p>
  
  <p>This will not throw any exception, but also doesn't remove the row. After running this method, my spreadsheet stays as it was before running this method.  </p>
  
  <pre class="lang-java prettyprint-override"><code>    private static void removeRow(String pathToExcel) throws IOException, InvalidFormatException {
  
          try {
              FileInputStream file = new FileInputStream(pathToExcel);
              Workbook workbook = WorkbookFactory.create(file);
              Sheet sheet = workbook.getSheetAt(0);
  
              int rowIndex = 1;
              int lastRowNum = sheet.getLastRowNum();
                  Row row = sheet.getRow(rowIndex);
              if (row != null) {
                  System.out.println(row.getCell(3).getRichStringCellValue()); //For Testing
                  System.out.println(row.getCell(4).getRichStringCellValue()); //For Testing
                  sheet.removeRow(row);
                  sheet.shiftRows(rowIndex + 1, lastRowNum, -1);
              }
  
              if (rowIndex == lastRowNum) {
                  System.out.println("Last Row");
                  Row removingRow = sheet.getRow(rowIndex);
                  if (removingRow != null) {
                      sheet.removeRow(removingRow);
                  }
              }
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>