easyexcel填坑(easyexcel教程)

  本篇文章为你整理了easyexcel填坑(easyexcel教程)的详细内容,包含有easyx填充 easyexcel教程 easyexcel模板填充图片 easyexcel pom easyexcel填坑,希望能帮助你了解 easyexcel填坑。

  3.0版本以前listener中抛出的所有异常都会被easyexcel捕获,并且包装成ExcelAnalysisException,写法如下:

  

private void parseXmlSource(InputStream inputStream, ContentHandler handler) {

 

   InputSource inputSource = new InputSource(inputStream);

   try {

   SAXParserFactory saxFactory;

   String xlsxSAXParserFactoryName = xlsxReadContext.xlsxReadWorkbookHolder().getSaxParserFactoryName();

   if (StringUtils.isEmpty(xlsxSAXParserFactoryName)) {

   saxFactory = SAXParserFactory.newInstance();

   } else {

   saxFactory = SAXParserFactory.newInstance(xlsxSAXParserFactoryName, null);

   saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

   saxFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);

   saxFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

   SAXParser saxParser = saxFactory.newSAXParser();

   XMLReader xmlReader = saxParser.getXMLReader();

   xmlReader.setContentHandler(handler);

   xmlReader.parse(inputSource);

   inputStream.close();

   } catch (ExcelAnalysisException e) {

   throw e;

   } catch (Exception e) {

   throw new ExcelAnalysisException(e);

   } finally {

   if (inputStream != null) {

   try {

   inputStream.close();

   } catch (IOException e) {

   throw new ExcelAnalysisException("Can not close inputStream!");

   }

 

  3.1.5版本对此做了优化,只会包装指定的异常,代码如下:

  

 private void parseXmlSource(InputStream inputStream, ContentHandler handler) {

 

   InputSource inputSource = new InputSource(inputStream);

   try {

   SAXParserFactory saxFactory;

   String xlsxSAXParserFactoryName = xlsxReadContext.xlsxReadWorkbookHolder().getSaxParserFactoryName();

   if (StringUtils.isEmpty(xlsxSAXParserFactoryName)) {

   saxFactory = SAXParserFactory.newInstance();

   } else {

   saxFactory = SAXParserFactory.newInstance(xlsxSAXParserFactoryName, null);

   try {

   saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

   } catch (Throwable ignore) {}

   try {

   saxFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);

   } catch (Throwable ignore) {}

   try {

   saxFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

   } catch (Throwable ignore) {}

   SAXParser saxParser = saxFactory.newSAXParser();

   XMLReader xmlReader = saxParser.getXMLReader();

   xmlReader.setContentHandler(handler);

   xmlReader.parse(inputSource);

   inputStream.close();

   } catch (IOException ParserConfigurationException SAXException e) {

   throw new ExcelAnalysisException(e);

   } finally {

   if (inputStream != null) {

   try {

   inputStream.close();

   } catch (IOException e) {

   throw new ExcelAnalysisException("Can not close inputStream!");

   }

 

  

  以上就是easyexcel填坑(easyexcel教程)的详细内容,想要了解更多 easyexcel填坑的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: