title: Create an XLSX file using POI
body: <p>I have two programs in Java: one to create and write data to an XLSX file and the other to read data from the same file.</p>
  
  <p>In my first program, I used the statements below to write data to the XLSX file.</p>
  
  <pre><code>FileOutputStream prelimOut = new FileOutputStream(new File("D:\\News\\Prelim.xlsx"));
  XSSFWorkbook out = new XSSFWorkbook();
  XSSFSheet spreadSheet = out.createSheet("ResultSheet");
  </code></pre>
  
  <p>and on my drive, I've the file created as expected.</p>
  
  <p>When I'm trying to read the same file from a different program with this code</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.Iterator;
  
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class GetCellCount {
      public static void main(String[] args) throws IOException {
          FileInputStream input_document = new FileInputStream(new File("D:\\News\\Prelim.xlsx"));
          XSSFWorkbook my_xlsx_workbook = new XSSFWorkbook(input_document);
          XSSFSheet my_worksheet = my_xlsx_workbook.getSheetAt(0);
          Iterator&lt;Row&gt; rowIterator = my_worksheet.iterator();
          while (rowIterator.hasNext()) {
              Row row = rowIterator.next();
              Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
              while (cellIterator.hasNext()) {
                  Cell cell = cellIterator.next();
                  switch (cell.getCellType()) {
                  case Cell.CELL_TYPE_NUMERIC:
                      System.out.print(cell.getNumericCellValue() + "\t\t");
                      break;
                  case Cell.CELL_TYPE_STRING:
                      System.out.print(cell.getStringCellValue() + "\t\t");
                      break;
                  }
              }
              System.out.println("");
          }
          my_xlsx_workbook.close();
          input_document.close();
      }
  }
  </code></pre>
  
  <p>it throws the below error</p>
  
  <pre><code>Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
      at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
      at org.apache.poi.xssf.usermodel.XSSFWorkbook.&lt;init&gt;(XSSFWorkbook.java:258)
      at GetCellCount.main(GetCellCount.java:14)
  Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
      at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:203)
      at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:673)
      at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:274)
      at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
      ... 2 more
  </code></pre>
  
  <p>When changing the path and accessing another XLSX file (created directly in Excel), the data appears correctly.</p>
  
  <p>Also, when I checked the properties of both these Excel files by right-clicking on them, I see the "Type of File" as <code>MS Office Excel OpenXML (.xlsx)</code>, which is the same for both files.</p>