title: Apache POI to read excel file with many worksheets and write single sheet to new file
body: <p>I am using Apache POI to read an xlsx file that has many worksheets in it.
  I want to write out the contents to a new xlsx file, but I only want one selected worksheet from the original input.</p>
  
  <p>The example I have (code below) reads the file fine, but it writes out all worksheets to the file. I need to know what to do to write only one of the sheets. 
  Can I do that?</p>
  
  <pre><code>import java.io.*;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class ExcelTest {
  
      public static void main(String[] args)
      {  
  
      try
      {
          FileInputStream file = new FileInputStream(new File("FileLotOfSheets.xlsx"));
          //Create Workbook instance holding reference to .xlsx file
          XSSFWorkbook workbook = new XSSFWorkbook(file);
  
          //Get first/desired sheet from the workbook
         // XSSFSheet sheet = workbook.getSheetAt(0);
  
          file.close();
  
          FileOutputStream out = new FileOutputStream("FileOnlyOneSheetFromLots.xlsx");
          workbook.write(out);
          out.close();
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  
      }
  }
  </code></pre>