Recently I downloaded a generated Excel file (xlsx) from the internet, and saved it to my pc. To edit this file in Excel, I first have to click on 'Protected view - Enable editing' to edit the document.
When I upload the file to the server without opening this file in Excel first, PHPExcel isn't able to recognize the data in the Excel file. After opening the file in Excel and clicking on 'Enable editing' and re-saving the file, PHPExcel imports the file correctly.
I checked the mimetype of the file (directly after downloading it). The mimetype is 'application/zip' (instead of 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'). After resave the document in Excel the mimetype is 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
The code I use to import files using PHPExcel:
<?php
$file_name = 'Excelfile.xlsx';
$objReader = PHPExcel_IOFactory::createReaderForFile($file_name);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file_name);
$worksheet = $objPHPExcel->getSheet(0);
?>
Do anyone know how you could read Excel files with PHPExcel, without the need of resaving the file in Excel?