“包应包含内容类型部分 [M1.13]" [英] "Package should contain a content type part [M1.13]"

查看:54
本文介绍了“包应包含内容类型部分 [M1.13]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试写入 Excel 文件,但是我不断收到错误消息:

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

线程main"中的异常 org.apache.poi.POIXMLException:org.apache.poi.openxml4j.exceptions.InvalidFormatException:包应包含内容类型部分 [M1.13]

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

据我所知,我缺少一个 jar 文件.

From what I understand I am missing a jar file.

谁能帮我确定它是哪个文件?

Can anyone help me identify which file it is?

附言我正在使用 Netbeans.

P.S. I am using Netbeans.

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 *
 * @author nicholaskissaun
 */

public class Tester {

    public static void main (String args \[\])throws FileNotFoundException, IOException, InvalidFormatException{     
        int RowCount = 7, iChoice;
        String sChoice;
        XSSFSheet s;
        XSSFRow row1;
        XSSFWorkbook wb;
        XSSFCell r1c1, r1c2, r1c8, r1Episodes;

        FileInputStream fis = new FileInputStream("/Users/nicholaskissaun/Google Drive/Grade 11_12/Computer Science/Java/Term1/src/IA/Profiles/Becky/ShowDetails.xlsx");           
        wb = new XSSFWorkbook(fis);  
        s = wb.getSheetAt(0);

    }      

}

推荐答案

使用文件扩展名处理WorkSheet类型

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\"";
                    }

对于 XLSX 文件:使用 XSSFWorkbook &XSSFSheet

For XLSX file: use XSSFWorkbook & XSSFSheet

    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File(path)));

    XSSFSheet sheet = workbook.getSheetAt(0);

对于 XLS 文件:使用 HSSFWorkbook &HSSFSheet

For XLS file: use HSSFWorkbook & HSSFSheet

    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(path)));

    HSSFSheet sheet = workbook.getSheetAt(0);

这篇关于“包应包含内容类型部分 [M1.13]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆