未将正确的数组格式XLS文件放入PHPEXCEL

未将正确的数组格式XLS文件放入PHPEXCEL,php,arrays,phpexcel,Php,Arrays,Phpexcel,我正在使用PHPExcel读取Excel文件并将其放入数组。我正在读取.xlsx和.xls文件。我编写了xlsExtract和xlxsExtract函数 功能包括: function xlsxExtract() { $inputFileType = PHPExcel_IOFactory::identify($this->filepath); /*file path */ $objReader = PHPExcel_IOFactory::createReader($i

我正在使用PHPExcel读取Excel文件并将其放入数组。我正在读取
.xlsx
.xls
文件。我编写了
xlsExtract
xlxsExtract
函数

功能包括:

function xlsxExtract() 
{  

    $inputFileType = PHPExcel_IOFactory::identify($this->filepath); /*file path */
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);  
    $objReader->setReadDataOnly(true);

    /**  Load $inputFileName to a PHPExcel Object  **/  
    $objPHPExcel = $objReader->load($this->filepath);  
    $total_sheets=$objPHPExcel->getSheetCount(); // here 4  
    $allSheetName=$objPHPExcel->getSheetNames(); // array ([0]=>'student',[1]=>'teacher',[2]=>'school',[3]=>'college')  
    $objWorksheet = $objPHPExcel->setActiveSheetIndex(0); // first sheet  
    $highestRow = $objWorksheet->getHighestRow(); 
    $highestColumn = $objWorksheet->getHighestColumn();  
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);  
    for ($row = 1; $row <= $highestRow; ++$row) 
    {  
        for ($col = 0; $col <$highestColumnIndex; ++$col)
        {  
            $value=$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();  
            if(is_array($this->arraydata) ) 
            { 
                $this->arraydata[$row-1][$col]=$value; 
            }  
        }  
    }
    print_r($this->arraydata); /*array display*/ 

}   



function xlsExtract() 
{
$inputFileType = PHPExcel_IOFactory::identify($this->filepath);  
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);  
    $objReader->setReadDataOnly(true);

    /**  Load $inputFileName to a PHPExcel Object  **/  
    $objPHPExcel = $objReader->load($this->filepath);  
    $total_sheets=$objPHPExcel->getSheetCount(); // here 4  
    $allSheetName=$objPHPExcel->getSheetNames(); // array ([0]=>'student',[1]=>'teacher',[2]=>'school',[3]=>'college')  
    $objWorksheet = $objPHPExcel->setActiveSheetIndex(0); // first sheet  
    $highestRow = $objWorksheet->getHighestRow(); 
    $highestColumn = $objWorksheet->getHighestColumn();  
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);  
    for ($row = 1; $row <= $highestRow; ++$row) 
    {  
        for ($col = 0; $col <$highestColumnIndex; ++$col)
        {  
            $value=$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();  
            if(is_array($this->arraydata) ) 
            { 
                $this->arraydata[$row-1][$col]=$value; 
            }  
        }  
    }
    print_r($this->arraydata);

}
我的xlsxExtract给了我这样的输出:

Array ( [0] => Array ( [0] =>Name city Address  ) [1] => Array ( [0] => abc X wxy ) [2] => Array ( [0] => bb Y mno ) 
Array ( [0] => Array ( [0] => Name [1] => City [2] => Addres ) [1] => Array ( [0] => AA [1] => XYZ [2] => xxx) 
我希望我的数组输出像第二个一样。即
xlsxExtract

有人能帮我吗。我错在哪里


谢谢。

我怀疑xlsExtract实际上不是针对真正的BIFF格式xls文件运行的,而是针对具有xls扩展名的csv文件运行的。。。并且分隔符不是默认的逗号分隔符。查看实际使用的阅读器;在文本编辑器中查看xls文件,看看它到底是什么。嗨,马克·贝克。我从网站下载的xls文件。它的未来xls格式只。当我在文本编辑器中打开该文件时,它是制表符分隔符文件。那么如何解决这个问题。你能帮我吗。谢谢。您需要确定它是一个分隔值文件而不是BIFF文件,并实例化编写器;但在加载之前,请手动设置分隔符和任何其他详细信息(如存储模块和转义存储模块)。。。我希望能在明天晚上的PHPNW13 hackathon上得到一个csv文件的自动检测,它将在下一个版本中发布。。。但在此之前,我担心带有非默认deparator的csv文件是一个手动操作。测试调用返回的$inputFileType以确定是否需要额外设置。