V1.1.2-beta5
// 解析每行结果在listener中处理
ExcelListener listener = new ExcelListener();
ExcelReader excelReader = new ExcelReader(inputStream,null, listener,true);
excelReader.read(new Sheet(2, 1, CategoryModel.class));
public class ExcelListener extends AnalysisEventListener
@Override
public void invoke(CategoryModel object, AnalysisContext context) {
System.out.println("当前行: " + context.getCurrentRowNum());
System.out.println(object);
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
// TODO Auto-generated method stub
}
}
public class CategoryModel extends BaseRowModel { @ExcelProperty(index=2) private String catagory_v1; @ExcelProperty(index=3) private String catagory_v2; @ExcelProperty(index=4) private String catagory_v3; }
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.CategoryModel at com.enation.app.shop.excel.ExcelListener.invoke(ExcelListener.java:1) at com.alibaba.excel.analysis.BaseSaxAnalyser.notifyListeners(BaseSaxAnalyser.java:72) at com.alibaba.excel.analysis.v07.XlsxRowHandler.endRow(XlsxRowHandler.java:132) at com.alibaba.excel.analysis.v07.XlsxRowHandler.endElement(XlsxRowHandler.java:110) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643) at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.parseXmlSource(XlsxSaxAnalyser.java:97) at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.execute(XlsxSaxAnalyser.java:81) at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:74) at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:67) at com.alibaba.excel.ExcelReader.read(ExcelReader.java:112) at com.enation.app.shop.excel.TestImport.main(TestImport.java:23)