userimage

Exception (org.apache.poi.openxml4j.exception - no content type [M1.13]) reading xlsx files using Apache POI

i"m using Apache POI(XSSF API) for reading xlsx file.when i tried to read file.i got the following error:

org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

userimage

Pretty sure that this exception is thrown when the Excel file is either password protected or the file itself is corrupted.

Also you can refer to the below code to read the Excel files in case you wrote some thing wrong.


import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;

static final String excelLoc = "C:/Documents and Settings/Users/Desktop/testing.xlsx";

public static void ReadExcel() {
InputStream inputStream = null;
   try {
        inputStream = new FileInputStream(new File(excelLoc));
        Workbook wb = WorkbookFactory.create(inputStream);
        int numberOfSheet = wb.getNumberOfSheets();

        for (int i = 0; i < numberOfSheet; i++) {
             Sheet sheet = wb.getSheetAt(i);
             //.... Customize your code here
             // To get sheet name, try -> sheet.getSheetName()
        }
   } catch {}
}


Note : Import the required classes if required.

Answer is