public class fileReader { public static void main (String[] args) throws IOException { String excelFilePath = "sample.xlsx"; InputStream inputStream = new FileInputStream(new File(excelFilePath)); XSSFWorkbook workbook = new XSSFWorkbook(); Sheet firstSheet = workbook.getSheetAt(0); Iterator<Row> iterator = firstSheet.iterator(); while (iterator.hasNext()) { Row nextRow = iterator.next(); Iterator<Cell> cellIterator = nextRow.cellIterator(); ...在 XSSFWorkbook 行中显示了错误Exception in thread "main" org.apache.poi.ooxml.POIXMLException: org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions; at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:66) at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:657) at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:282) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:303) at fileReader.main(fileReader.java:20)
1 回答
墨色风雨
TA贡献1853条经验 获得超6个赞
你没有阅读你的文件。您正在创建一个新工作簿。所以我怀疑你有一个例外,因为你要求一个Sheet没有的地方。
将您的文件提供给实例使用XSSFWorkbook(File)
String excelFilePath = "sample.xlsx";
File f = new File(excelFilePath);
XSSFWorkbook workbook = new XSSFWorkbook(f);
或者XSSFWorkbook(InputStream)
String excelFilePath = "sample.xlsx";
File f = new File(excelFilePath);
InputStream inputStream = new FileInputStream(f);
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
如果将 File 提供给工作簿实例,则会出现错误,显示 File cannot be resolved to a type
只需要导入java.io.File
添加回答
举报
0/150
提交
取消