title: Updating existing excel document with Apache POI via Groovy
body: <p>I am trying to update an existing excel document with via Groovy Script. I have tried with jxl, but the file was always corrupted so as I was suggested I have tried with Apache POI. I have found the code that I have managed to configure that looks like so:</p>
  
  <pre><code>FileOutputStream fileOut = new FileOutputStream("Path.xls");
              HSSFWorkbook workbook = new HSSFWorkbook();
              HSSFSheet worksheet = workbook.createSheet("POI Worksheet");
  
              // index from 0,0... cell A1 is cell(0,0)
              HSSFRow row1 = worksheet.createRow((short) 0);
  
              HSSFCell cellA1 = row1.createCell((short) 0);
              cellA1.setCellValue("Hello");
              HSSFCellStyle cellStyle = workbook.createCellStyle();
              cellStyle.setFillForegroundColor(HSSFColor.GOLD.index);
              cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
              cellA1.setCellStyle(cellStyle);
  
              HSSFCell cellB1 = row1.createCell((short) 1);
              cellB1.setCellValue("Goodbye");
              cellStyle = workbook.createCellStyle();
              cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
              cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
              cellB1.setCellStyle(cellStyle);
  
              HSSFCell cellC1 = row1.createCell((short) 2);
              cellC1.setCellValue(true);
  
              HSSFCell cellD1 = row1.createCell((short) 3);
              cellD1.setCellValue(new Date());
              cellStyle = workbook.createCellStyle();
              cellStyle.setDataFormat(HSSFDataFormat
                      .getBuiltinFormat("m/d/yy h:mm"));
              cellD1.setCellStyle(cellStyle);
  
                fileOut.close();
  
              FileOutputStream outFile =new FileOutputStream(new File("Path.xls"));
              workbook.write(outFile);
              outFile.close();
  </code></pre>
  
  <p>The code works perfectly and I am having the fields defined written in the file, but the problem is that with the current code all previous data is deleted ... I have tried to preserve the data but without any success. </p>
  
  <p>Can you tell me how I can make the update of the document without deleting the previous data?</p>