Mary
Mary

Reputation: 37

PHPExcel dont read my xls file

When I load any file xls, but always gives the text. I do all this: DOM ELEMENT: HTML DOM ELEMENT: BODY DOM ELEMENT: P START OF PARAGRAPH: END OF PARAGRAPH: FLUSH CELL: A1 => ÐÏ

$ aSheet = $ objPHPExcel-> getActiveSheet ();

There is no data from external files what to do?

My code:

function getXLS($xls) {
    include_once '/server_name/public_html/PHPExcel/Classes/PHPExcel/IOFactory.php';
    $objPHPExcel = PHPExcel_IOFactory::load($xls);
    $objPHPExcel->setActiveSheetIndex(0);
    $aSheet = $objPHPExcel->getActiveSheet();
    $array = array();
    foreach($aSheet->getRowIterator() as $row) {
        $cellIterator = $row->getCellIterator();
        $item = array();
        foreach($cellIterator as $cell) {
            array_push($item, $cell->getCalculatedValue());
        }
        return $array;
    }

    $excel_file = $_FILES['excel_file'];
    if( $excel_file )
        $excel_file = $_FILES['excel_file']['tmp_name'];
    if($_FILES['excel_file']['tmp_name']) {
        $xlsData = getXLS($excel_file); 
    }
}

Upvotes: 0

Views: 1126

Answers (1)

Mark Baker
Mark Baker

Reputation: 212402

Those error messages are old debug code for reading an HTML file. PHPExcel has identified the file you're loading as HTML rather than a real .xls file, and is using the HTML Reader. Unfortunately, I left some diagnostics in the code that should have been removed before release.

To resolve, edit the HTML Reader file, and comment out any line that echoes anything

However, on closer inspection it actually looks like as though there is HTML markup wrapped around the bytestream data for a genuine Excel file (open the file in a text editor to see what I mean). However this file is being generated, it's being corrupted by this, making it unreadable. You need to fix the code that is creating this file.

Upvotes: 1

Related Questions