Unable to use XSSF with Excel 2007

2019-07-27 15:42发布

问题:

I am having tough time getting to read data from excel 2007. I am using XSSF to read data from a specific cell of excel but keep getting error -

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setSaveAggressiveNamespaces()Lorg/apache/xmlbeans/XmlOptions; at org.apache.poi.POIXMLDocumentPart.(POIXMLDocumentPart.java:46)

This is my piece of code:

public static void main(String [] args) throws IOException {
    InputStream ins = new FileInputStream("C:\\Users\\Tarun3Kumar\\Desktop\\test.xlsx"); 
    XSSFWorkbook xwb = new XSSFWorkbook(ins);
    XSSFSheet sheet = xwb.getSheetAt(0);
    Row row = sheet.getRow(1);
    Cell cell = row.getCell(0);
    System.out.println(cell.getStringCellValue());
    System.out.println("a");
}

I have following jars added to build path -

poi-3.6 poi-ooxml-3.6 poi-ooxml-schemas-3.6 x-bean.jar

I could only figure out that setSaveAggressiveNamespaces has replaced setSaveAggresiveNamespaces....

回答1:

there is other issue happen to be: xbean.jar and xmlbeans.jar both have XmlOptions, but only xmlbeans.jar have method you want. I changed path order for xmlbeans.jar first and worked.