简体   繁体   English

PHPExcel-读取下载的xlsx文件

[英]PHPExcel - Read downloaded xlsx file

Recently I downloaded a generated Excel file (xlsx) from the internet, and saved it to my pc. 最近,我从互联网上下载了生成的Excel文件(xlsx),并将其保存到我的PC中。 To edit this file in Excel, I first have to click on 'Protected view - Enable editing' to edit the document. 要在Excel中编辑此文件,我首先必须单击“保护视图-启用编辑”来编辑文档。

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. 当我不首先在Excel中打开文件而将文件上传到服务器时,PHPExcel无法识别Excel文件中的数据。 After opening the file in Excel and clicking on 'Enable editing' and re-saving the file, PHPExcel imports the file correctly. 在Excel中打开文件并单击“启用编辑”并重新保存文件后,PHPExcel会正确导入文件。

I checked the mimetype of the file (directly after downloading it). 我检查了文件的模仿类型(下载后直接)。 The mimetype is 'application/zip' (instead of 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'). 模仿类型为“ application / zip”(而不是“ application / vnd.openxmlformats-officedocument.spreadsheetml.sheet”)。 After resave the document in Excel the mimetype is 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'. 在Excel中重新保存文档后,模仿类型为“ application / vnd.openxmlformats-officedocument.spreadsheetml.sheet”。

The code I use to import files using PHPExcel: 我使用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? 有谁知道您可以用PHPExcel读取Excel文件,而无需在Excel中重新保存文件?

"Protected view" is a security feature built into the more recent versions of MS Excel/Office itself. “受保护的视图”是MS Excel / Office本身最新版本中内置的安全功能。 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. 据我所知,这并没有以任何方式影响PHPExcel加载文件的能力,但是我将看一下是否可以确定其原因。 Can you please raise it as an issue on github 你能把它作为一个问题在github上提出吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM