weiphp 2.0:Your requested sheet index: 1 is out of bounds. The actual number of sheets is 0

我在做读取服务器的excel上的文件的时候,意外的发现了这样一个奇怪的错误
Your requested sheet index: 1 is out of bounds. The actual number of sheets is 0


产生错误的原因是你可能打开了错误的文件,需要查一下你打开的文件是不是excel格式,还是哪里写错了。

我这里就是把file_id弄错了,导致它找不到我打开的文件,所以报了错误。

Vendor('PHPExcel/IOFactory');
		Vendor('PHPExcel/Cell');
		//判断excel版本,导入不同文件
		$file_id=$message['filename'];  //当时file_id没有用这条语句获取,所以下面getSheet的时候,就找不到我对应的文件,而打开了错误的文件
		$file= M('file')->where('id='.$file_id)->find();
		if ($file['ext'] == 'xls') {
			//如果excel文件后缀名为.xls,导入这个类
			$objReader=\PHPExcel_IOFactory::createReader('Excel5');  
		} else {
			//如果excel文件后缀名为.xlsx,导入这个类
			 $objReader=\PHPExcel_IOFactory::createReader('Excel2007');  
		}
		
		$fileURL='./Uploads/Download/'.$file['savepath'].$file['savename'];
		//$this->success ($fileURL); 
		 // 判断使用哪种格式
		//$objReader = PHPExcel_IOFactory::createReader("Excel2007");
		$PHPExcel = $objReader ->load($fileURL);
		//$this->success ($PHPExcel); 
		//获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
		$currentSheet = $PHPExcel->getSheet(0);
	    $allColumn = $currentSheet->getHighestColumn();  //获取总列数
		//$this->success ($allColumn); 
		$allRow = $currentSheet->getHighestRow();  //获取总行数

参考文献

[1].PHPExcel_Exception' with message 'Your requested sheet index: 0 is out of bounds. The actual number of sheets is 0. https://github.com/Maatwebsite/Laravel-Excel/issues/678

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值