title: Writing to a existing xls file using POI
body: <p>The scenario is roughly this:</p>
  
  <p>I have a java program with several methods getting called randomly.</p>
  
  <p>The first method will create an xls file using apache POI and will put the headers for the columns. </p>
  
  <p>All the other methods has to write a record into this file.</p>
  
  <p>The final method will first mail the created xls and then delete the xls.</p>
  
  <p>For above scenario is the below approach correct:</p>
  
  <p>1) Create the file and put the header names in the first method:</p>
  
  <pre><code>Workbook wb = new HSSFWorkbook();
  CreationHelper createHelper = wb.getCreationHelper();
  Sheet sheet = wb.createSheet("First Sheet");
  Row row = sheet.createRow((short)0);
  row.createCell(1).setCellValue(createHelper.createRichTextString("First Column"));
  row.createCell(2).setCellValue(createHelper.createRichTextString("Second Column"));
  row.createCell(3).setCellValue(createHelper.createRichTextString("Third Column"));
  
  // Write the output to a file
  FileOutputStream fileOut = new FileOutputStream("workbook.xls");
  wb.write(fileOut);
  fileOut.close();
  </code></pre>
  
  <p>2) In the remaining methods put the records:</p>
  
  <p>I am not sure of the code here. I know that I can reach the end of the sheet using getRowCount method and then add the new row. But I could not find any example code.</p>
  
  <p>Also, how to access the existing xls file ?</p>
  
  <p>3) In the last method, the file will be mailed and then deleted. </p>
  
  <p>Do I need to perform any other steps before deleting the file ?</p>