title: Importing data from .xls and .xlsx (Struts and Spring)
body: <p>I am doing a excel data import and reading through the file. The file format can be <code>.xls</code> or <code>.xlsx</code>. 
  I have seen the different methods for doing so with both files.</p>
  
  <p>For <code>.xls</code>,</p>
  
  <p><code>HSSFWorkbook workbook = new HSSFWorkbook(file);</code></p>
  
  <p><code>........;</code></p>
  
  <p>and for <code>.xlsx</code></p>
  
  <p><code>XSSFWorkbook workbook = new XSSFWorkbook (file);</code></p>
  
  <p><code>......;</code></p>
  
  <p>But this looks like an extra work, writing different methods for different file formats.
  If we write in different methods, almost all the code will be same, except the file format checking at the beginning.
  I'm doing the excel importing using Apache POI.</p>
  
  <p>Is there a way for doing both file formats in a single method? Such as in a single method do the same for both <code>.xls</code> and <code>.xlsx</code> file data importing and validation.</p>
  
  <p>I am not expecting the whole code or something(which I wont get), but the idea to get it done in a single method.</p>