title: Get excel sheet names for large excel files using Apache POI
body: <p>I have the following code that I use to get the sheet names of an excel file(.xlsx)</p>
  
  <pre><code>    XSSFWorkbook workBookXlsx = new XSSFWorkbook(new FileInputStream(pathToFile));
      ArrayList&lt;String&gt; sheetNames = new ArrayList&lt;&gt;();
  
      int numberOfSheets = workBookXlsx.getNumberOfSheets();
      for (int i = 0; i &lt; numberOfSheets; i++) {
          sheetNames.add(workBookXlsx.getSheetAt(i).getSheetName());
      }
  
      workBookXlsx = null;
  </code></pre>
  
  <p>The issue I have with the above code is that it takes a lot of memory(~700MB) &amp; a long time(5-6s) to create the <code>XSSFWorkbook</code> for a file of size 9MB. Even setting the <code>workBookXlsx</code> to <code>null</code> doesn't release the memory taken by the <code>javaw</code>(I know <code>gc</code> may or maynot be called &amp; JVM wont release memory just because I have set a variable to null)</p>
  
  <p>I did go through the documentation of <a href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Workbook.html" rel="nofollow noreferrer">Workbook</a>, <a href="https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html" rel="nofollow noreferrer">XSSFWorkbook</a> &amp; from what I understood, there is no method that will help me get the sheet names with low memory imprint.</p>
  
  <p>The one solution I have found is to manually unzip the <code>.xlsx</code> file and read the contents of the <code>.\xl\woorkbook.xml</code> to get the sheet names and the <code>r:id</code></p>
  
  <p>Is there an API for getting the sheet names in an <code>.xlsx</code> file without large memory imprint?</p>