problem with excel

0

I'm trying to read an excel in php and this is my code:

require_once 'Excel/Classes/PHPExcel/IOFactory.php';

$file = "currier.xls";

$objPHPExcel = PHPExcel_IOFactory::load($file, 'Excel2007');

$objPHPExcel->getSecurity()->setLockWindows(true);

$objPHPExcel->getSecurity()->setLockStructure(true);

$objPHPExcel->getSecurity()->setWorkbookPassword('123456');

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
    $worksheetTitle     = $worksheet->getTitle();
    $highestRow         = $worksheet->getHighestRow(); // e.g. 10
    $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $nrColumns = ord($highestColumn) - 64;
    echo "<br>The worksheet ".$worksheetTitle." has ";
    echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
    echo ' and ' . $highestRow . ' row.';
    echo '<br>Data: <table border="1"><tr>';
    for ($row = 1; $row <= $highestRow; ++ $row) {
        echo '<tr>';
        for ($col = 0; $col < $highestColumnIndex; ++ $col) {
            $cell = $worksheet->getCellByColumnAndRow($col, $row);
            $val = $cell->getValue();
            $dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
            echo '<td>' . $val . '<br>(Typ ' . $dataType . ')</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
}

Read very well but the problem is that I have an xls or xlsx that comes with a password and I can not read the excel with a password. How can I read a password or protected file?

    
asked by Felipe 06.11.2018 в 16:01
source

1 answer

0

If you are going to work with excel files, the first thing is that you use PhpSpreadsheet , because it is the new version of PHPExcel that is currently deprecated.

I leave the link to your documentation:

EJ:

    $file = "currier.xls";
    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
    $reader->setWorkbookPassword('secreto');  
    $sheet = $reader->load($file);
    
answered by 06.11.2018 в 16:28