poi解析excel时问题_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > poi解析excel时问题

poi解析excel时问题

 2014/10/15 18:46:18  liu578182160  程序员俱乐部  我要评论(0)
  • 摘要:try{//2007+workbook=newXSSFWorkbook(path+"\\"+fileName);}catch(IOExceptione1){//2003workbook=newHSSFWorkbook(newFileInputStream(path+"\\"+fileName));}代码先贴出来运行报错Exceptioninthread"main"org.apache.poi.openxml4j.exceptions.InvalidOperationException
  • 标签:excel 问题 解析
class="java" name="code">try {
				//2007+
				workbook = new XSSFWorkbook(path + "\\" + fileName);
			} catch (IOException e1) {
				//2003
				workbook = new HSSFWorkbook(new FileInputStream(path + "\\" + fileName));
			}

?代码先贴出来

运行报错

Exception in thread "main" org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: 'D:\demo.xls'
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
	at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:62)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:167)
	at com.beyondsoft.local.LocalString.readExcel(LocalString.java:26)
	at com.beyondsoft.local.LocalString.main(LocalString.java:98)

?使用HSSF处理2003,XSSF处理2007,怎么检查都感觉没有问题啊

仔细读每一行的代码才发现catch语句中顺手写了monospace; font-size: 1em; line-height: 1.5;">IOException,太粗心了,果断改成Exception,问题解决

发表评论
用户名: 匿名