Java – “package should contain content type part [m1.13]”

I tried to write to an excel file, but I kept getting an error:

According to my understanding, I missed a jar file

Anyone can help me identify which file it is?

Attachment: I'm 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);

    }      

}

Solution

Use file extensions to handle worksheet types

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 files: use xssfworkbook & xssfsheet

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

    XSSFSheet sheet = workbook.getSheetAt(0);

For XLS files: use hssfworkbook & hssfsheet

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

    HSSFSheet sheet = workbook.getSheetAt(0);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>