我正在使用Apache POI(XSSF API)来读取xlsx文件.当我试图读取file.i时出现以下错误:
org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
Run Code Online (Sandbox Code Playgroud)
码:
public class ReadXLSX
{
private String filepath;
private XSSFWorkbook workbook;
private static Logger logger=null;
private InputStream resourceAsStream;
public ReadXLSX(String FilePath)
{
logger=LoggerFactory.getLogger("ReadXLSX");
this.filepath=FilePath;
resourceAsStream = ClassLoader.getSystemResourceAsStream(filepath);
}
public ReadXLSX(InputStream fileStream)
{
logger=LoggerFactory.getLogger("ReadXLSX");
this.resourceAsStream=fileStream;
}
private void loadFile() throws FileNotFoundException, NullObjectFoundException
{
if(resourceAsStream==null)
throw new FileNotFoundException("Unable to locate give file..");
else
{
try
{
workbook = new XSSFWorkbook(resourceAsStream);
}
catch(IOException ex)
{
}
}
}// end loadxlsFile …Run Code Online (Sandbox Code Playgroud)