什么是在PHP中创建XLS文件的最好方法 [英] What is the best way to create XLS file in PHP

查看:211
本文介绍了什么是在PHP中创建XLS文件的最好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正试图找出从PHP创建.xls文件的最佳方法。对我来说,所有我需要做的是将标题内容类型更改为application / vnd.ms-excel,然后以逗号分隔格式输出数据。

I am currently trying to figure out the best way to create a .xls file from PHP. It seems like to me that all I need to do is change the header content type to "application/vnd.ms-excel", and then output data in a comma separated format. Is this the best way to do this?

感谢您的帮助!
Metropolis

Thanks for any help!
Metropolis

EDIT

只是将数据输出为HTML会不好吗?我已经有一个类,我想扩展这个问题,所以我宁愿远离第三方解决方案。我只需要知道什么是输出数据的最好方法是为了获得最好的文件格式。

Would it be bad to just output the data as HTML? I already have a class that I would like to extend for this problem, so I would prefer to stay away from a third party solution. I just need to know what the best way to output the data would be in order to get the most out of that file format.

看看PHPExcel后,似乎是这个问题的最佳解决方案。我欣赏你的所有答案,如果我可以哈哈,我会给出三个正确的答案。但是投票必须:)

After looking at PHPExcel it seems to be the best solution for this issue. I appreciate all of your answers and I would have given three correct answers if I could lol. But up votes will have to do :)

推荐答案

取决于你想要一个CSV文件还是一个XLS文件。 XLS文件可以包括单元格的格式化信息,以及行/列锁定,保护和CSV文件中不可能的其他功能。此外,请记住,当打开CSV文件时,Excel不能正确支持UTF-8编码的内容。

Depends if you want a CSV file or an XLS file. An XLS file can include formatting information for the cells, as well as row/column locking, protections and other features that are impossible in a CSV file. Also, keep in mind that Excel does not correctly support UTF-8 encoded content when opening CSV files.

如果你想要一个格式化的XLS文件,作为可以使用该格式编写文件的 PHPExcel ,如果服务器正在Windows上运行,则为COM已安装Excel

If you want a formatted XLS file, then you need a library such as PHPExcel that can write a file with that formatting, or COM if you're server is running on Windows with Excel installed

这篇关于什么是在PHP中创建XLS文件的最好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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