“Package should contain a content type part [M1.13]”

前端 未结 11 1226
野趣味
野趣味 2020-12-19 02:36

I am attempting to write to an Excel file however I keep getting the error:

Exception in thread \"main\" org.apache.poi.POIXMLException: org.apache.po

相关标签:
11条回答
  • 2020-12-19 03:06

    The excel file which your application trying to access is not responding due to network issues or corrupted format causes this error. If it is due to network issue try to run application later (or) If file is corrupted, try to put new file and test your application. Good Luck.

    0 讨论(0)
  • 2020-12-19 03:07

    I have the same problem. When you open excel file it will generate some file like ~$______.xlsx Just find and delete all of them worked for me.

    0 讨论(0)
  • 2020-12-19 03:13

    I got the same problem. Your excel isn't in right format. You can copy all work to new sheet or do Clear Format. Good luck.

    0 讨论(0)
  • 2020-12-19 03:15

    Use file extension to handle WorkSheet Type

      String inputFilename = new File(path).getName();
    
                        switch (inputFilename.substring(inputFilename.lastIndexOf(".") + 1,
                                inputFilename.length())) {
                            case "xls":
                                return readXLS(path);
    
                            case "xlsx":
                                return readXLSX(path);
                            default:
                                Log.e(TAG, "No XLS file chosen");
                                return "Please select valid \"Excel\" File\"";
                        }
    

    For XLSX file: use XSSFWorkbook & XSSFSheet

        XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File(path)));
    
        XSSFSheet sheet = workbook.getSheetAt(0);
    

    For XLS file: use HSSFWorkbook & HSSFSheet

        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(path)));
    
        HSSFSheet sheet = workbook.getSheetAt(0);
    
    0 讨论(0)
  • 2020-12-19 03:17

    Another possible solution is

    Workbook workbook = WorkbookFactory.create(source)
    

    WorkbookFactory should be provided by Apache POI you are using (if not upgrade to newer version). It recognize file format and creates concrete implementation of Workbook interface (XSSFWorkbook or HSSFWorkbook). The source parameter can be java.io.InputStream or java.io.File.

    0 讨论(0)
提交回复
热议问题