文件格式和扩展名不匹配 [英] File format and extension do not match

查看:281
本文介绍了文件格式和扩展名不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 php-export-data 库将一些数据导出到一个excel文件。

I'm using the php-export-data library to export some data to an excel document.

我已初始化,添加行并根据示例确定文档,并生成可用的 .xls 文件按预期方式,但是当我打开它时Excel 2010会抛出一条警告消息,说文件格式和xls的扩展名不匹配

I've initialized, added rows and finalized the document as per example and it generates a usable .xls file as expected but when I open it Excel 2010 throws a warning message saying the file format and extension of xls don't match.

该文件仍然可用,可以正常打开,但是对于客户端,我更希望警告不会显示。

The file is still usable and can be opened fine but as this is for a client I would much prefer for the warning to not show up at all.

我用于初始化,添加行并完成文档的代码。

The code I use to initialize, add rows and finalize the document.

$mailing_list = $event->getMailingList(); //returns an array

$exporter = new ExportDataExcel('browser', 'mailing_list.xls');
$exporter->initialize();

foreach($mailing_list as $mail){
    $exporter->addRow($mail);
}

$exporter->finalize();

当查看有关此错误的Microsoft文档时,它归结为 .xls 文件被重命名为 .xlsx 文件,反之亦然。我尝试使用 mailing_list.xlsx 而不是 mailing_list.xls ,但Excel无法打开该文件。

When looking at the Microsoft documentation about this error it comes down to .xls files being renamed to .xlsx files and vice versa. I've tried using mailing_list.xlsx instead of mailing_list.xls but then Excel can't open the file.

我没有改变任何图书馆,所以也许问题在那里?

I haven't changed anything to the library so maybe the problem lays there?

推荐答案

出现警告,因为文件扩展名* .xls与XML内容不同。

The warning appears because the file extension *.xls is different from the content which is XML.

https://github.com/elidickinson/php-export-data 提到,这个库会以CSV导出数据,TSV ,或Excel XML(也称SpreadsheeML)格式到文件或直接浏览器。

As in https://github.com/elidickinson/php-export-data mentioned, this library will "export data in CSV, TSV, or Excel XML (aka SpreadsheeML) format to a file or directly to the browser".

因此,其导出的真实内容类型将是XML,而不是XLS或XLSX。如果你命名文件* .xml并用Excel打开这个* .xml,那么警告就会消失。但是,您不能确定此文件是通过双击在Excel中打开的。如果将另一个应用程序设置为* .xml文件的默认应用程序,则不会。

So the real content type of its exports will be XML and not XLS or XLSX. If you name the file *.xml and open this *.xml with Excel then the warning will disapear. But then you can't be sure that this file is opened in Excel by double click. It will not if there is another application set as the default application for *.xml files.

所以要么生活在这个警告中,或者命名文件* .xml或你使用可以真正导出XLS和/或XLSX的库。 https://github.com/PHPOffice/PHPExcel

So either you live with that warning or name the file *.xml or you use a library which can really export XLS and/or XLSX. https://github.com/PHPOffice/PHPExcel for example.

这篇关于文件格式和扩展名不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆