2
votes

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?

1

1 Answers

0
votes

"Protected view" is a security feature built into the more recent versions of MS Excel/Office itself. Any file downloaded from the internet is treated as suspicious, and requires a user to explicitly confirm that they want to enable it in edit mode before they can edit it.

As far as I was aware, this didn't affect PHPExcel's ability to load a file in any way, but I'll take a look and see if I can identify the cause of this. Can you please raise it as an issue on github