问题描述
我有一个PHP程序,它读取XLS文件的工作表并将每个工作表转换为CSV文件。
我得到的错误:
致命错误:未捕获PHPExcel_Exception:您试图通过越界设置活动表index:3。实际页数为3.在C中:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ htdocs\Technocripa-php\convertCSV.php(34):PHPExcel-> setActiveSheetIndex(3)#1 C:\ xampp \\\\\\\\\\\\\\\\\\\ 'uploads / Central ...','Centralizator_f ...')#6 {main}抛出C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
代码:
I have a PHP program that reads an XLS file's worksheets and converts every worksheet to a CSV file.
The error i get:
Fatal error: Uncaught PHPExcel_Exception: You tried to set a sheet active by the out of bounds index: 3. The actual number of sheets is 3. in C:\xampp\htdocs\Technocripa-php\PHPExcel\Classes\PHPExcel.php:695 Stack trace: #0 C:\xampp\htdocs\Technocripa-php\convertCSV.php(34): PHPExcel->setActiveSheetIndex(3) #1 C:\xampp\htdocs\Technocripa-php\convertCSV.php(19): convertXLStoCSV('uploads/Central...', 'Centralizator_f...') #2 {main} thrown in C:\xampp\htdocs\Technocripa-php\PHPExcel\Classes\PHPExcel.php on line 695
Code:
function convertXLStoCSV($infile, $outfile) // the function that converts the file
{
$fileType = PHPExcel_IOFactory::identify($infile);
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($infile);
//$objPHPExcel->createSheet();
$i = 0;
while ($objPHPExcel->setActiveSheetIndex($i)){
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->save($outfile);
$i++;
//$sheetNames = $infile->getSheetNames();
}
}
?>
我尝试了什么:
我试过放置
What I have tried:
I have tried placing
$objPHPExcel->createSheet();
循环外,但错误仍然存在,但只是修改了它的数据:
致命错误:未捕获PHPExcel_Exception:您试图通过越界索引设置活动工作表:4。实际工作表数为4.
推荐答案
这篇关于Phpexcel无法修复错误:您尝试通过越界索引设置活动表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!