Updating value of cells in Excel with Java Apache POI
<p>I am trying to update an existing Excel with Apache POI. </p>

<p>The thing is, I have an excel having in its 3rd column telephone numbers, and I want to correct them to the specific format using if-statements. </p>

<p>But I cannot write to the file. </p>

<p>Here is the code I am using:</p>

<pre><code> public void readingExcel(String fileName) throws Exception {
    try (FileInputStream file = new FileInputStream(new File(fileName))) {
        HSSFWorkbook workbook = new HSSFWorkbook(file);
        HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator&lt;Row&gt; rowIterator = sheet.iterator();
            int counter = 0;
        for (Row row : sheet) {
            int columnIndex = 2;
            row = CellUtil.getRow(counter, sheet);
            Cell cell = CellUtil.getCell(row, columnIndex);
            if (formatter.formatCellValue(cell).length() == 8)
                cell.setCellValue("+216" + formatter.formatCellValue(cell));
            if (formatter.formatCellValue(cell).length() == 11 &amp;&amp; formatter.formatCellValue(cell).startsWith("216"))
                cell.setCellValue("+" + formatter.formatCellValue(cell));
            counter++;
        }

        FileOutputStream outFile =new FileOutputStream(new File(fileName));
        workbook.write(outFile);
        outFile.close();
    }  
}
</code></pre>

<p>And I am getting this error</p>

<pre><code>org.apache.poi.poifs.filesystem.NotOLE2FileException: Invalid header signature; read 0x0000000000000000, expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document
at org.apache.poi.poifs.storage.HeaderBlock.&lt;init&gt;(HeaderBlock.java:181)
at org.apache.poi.poifs.storage.HeaderBlock.&lt;init&gt;(HeaderBlock.java:140)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.&lt;init&gt;(NPOIFSFileSystem.java:302)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.&lt;init&gt;(HSSFWorkbook.java:398)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.&lt;init&gt;(HSSFWorkbook.java:379)
at excelapp.myClass.readingExcel(myClass.java:50)
at excelapp.myClass.&lt;init&gt;(myClass.java:41)
at excelapp.ExcelApp.main(ExcelApp.java:26)
</code></pre>

<p>The thing is that it is really important for today, and I am getting really stuck on updating the values of that column :-/ anyone has an idea? I think I'm writing the wrong way.. </p>