我收到此错误:

org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (e.g. XSSF instead of HSSF)

我读了扔谷歌,我发现我需要使用XSSF而不是HSSF,因为我的Excel文件是xlsx,但正如你在我的maven中看到的,我已经在使用xlsx了.我哪里出错了?

org.apache.poi

poi-ooxml

3.13-beta1

产生异常的代码是:

POIFSFileSystem fs;

fs = new POIFSFileSystem(new FileInputStream(getFilePath()));

我的新代码

public void getBColum() {

try {

OPCPackage fs;

fs = new OPCPackage.open(new File(getFilePath()));

XSSFWorkbook wb = new XSSFWorkbook(fs);

XSSFSheet sheet = wb.getSheet("Master column name - Used Car");

XSSFRow row;

CellReference cr = new CellReference("A1");

row = sheet.getRow(cr.getCol());

System.out.println(row.getCell(3));

} catch (FileNotFoundException e) {

if (logger.isDebugEnabled()) {

logger.debug("How can this error be possible? we should have already thrown an exception in the construction");

}

} catch (IOException e) {

logger.error(String.format("Exception in reading the file: %s",

e.getMessage()));

}

}

我在新的oPCPackage.open中有一个编译错误,它是:

OPCPackage.open cannot be resolved to a type

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐