title: Writing Excel file from Java with apache poi
body: <p>I'm writing an application which reads data from a Microsoft Access database  and writes this data into an Excel Sheet. Everything works fine but not the writing of the new data to the file. Here is the code:</p>
  
  <pre><code>private static XSSFWorkbook readFile(String filename) throws IOException {
      // return new XSSFWorkbook(new FileInputStream(filename));
      InputStream inp = new FileInputStream(filename);
      XSSFWorkbook wb = null;
      try {
          wb = (XSSFWorkbook) WorkbookFactory.create(inp);
      } catch (InvalidFormatException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return wb;
  }
  
  public void writeToFile(LinkedList&lt;TimeRowWrapper&gt; list) {
  
      try {
          // read file
          XSSFWorkbook workbook = readFile(fileName);
  
          // choose table from index
          XSSFSheet sheet = workbook.getSheetAt(kapaSheetIndex);
  
          for (Row row : sheet) {
              int rowNum = row.getRowNum();
  
              // iterate over list for row id
              for (TimeRowWrapper trw : list) {
                  if (rowNum == trw.getRowNumber()) {
  
                      double hour = Math
                              .round(trw.getTotalTime() / 60.0 * 100.) / 100.;
                      Cell cell = row.getCell(timeCol);
                      cell.setCellValue(hour);
                  }
              }
          }
  
          XSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);
  
          FileOutputStream out = new FileOutputStream(fileName);
          workbook.write(out);
          out.close();
  
      } catch (IOException e) {
          e.printStackTrace();
      } catch (NullPointerException e) {
          e.printStackTrace();
      } catch (NumberFormatException e) {
          e.printStackTrace();
      }
  }
  </code></pre>