大家推荐一个PHP生成excel文件的东东吧。

2013-07-04 01:22:19 +08:00
 meteor2013
简单,好用
4600 次点击
所在节点    PHP
23 条回复
CoX
2013-07-04 02:16:28 +08:00
有个东东就叫phpExcel,还不错
meteor2013
2013-07-04 02:55:08 +08:00
@CoX 谢谢啊。试了一下phpExcel. 的确不错,还挺好用的。
但是看了一下协议是 LGPL。 请问能随便拿来商用吗?
meteor2013
2013-07-04 02:59:16 +08:00
这是phpExcel 的协议:好像读起来没有限制商业用途啊?
GNU 和 LGPL ?


* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.9, 2013-06-02
holystrike
2013-07-04 07:43:15 +08:00
如果仅仅是查看表格的话,直接用 fputcsv 输出csv最省事
meteor2013
2013-07-04 08:32:44 +08:00
@holystrike 需要生成excel标准文件。
gDD
2013-07-04 08:37:54 +08:00
之前同事的做法是直接写<style></style><table></table>,然后存成xls后缀,Excel也能认识,很有想象力。。。
lucky215
2013-07-04 08:39:25 +08:00
@gDD 这种方法不标准,如果需要再解析这样生成的文件是很麻烦的。
meteor2013
2013-07-04 08:43:46 +08:00
@gDD 行是行,但是做成的文件兼容性有点问题。以前试过,在某些版本的excel 上可以打开,有些不能。在某个Mac 的excel上出现少数乱码。
moxuanyuan
2013-07-04 08:56:51 +08:00
@gDD http://www.cnblogs.com/cannel/archive/2011/06/30/2094189.html 你说的就是这种方法,我也常用,直接当成模版,输出成文件,很方便
iscraft
2013-07-04 10:06:46 +08:00
最近在用网上找来的这段东西
<?
session_start();
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=lesson_list_data.xls");
include "./s/inc.php";
include "./s/fun.php";

$sql = $_GET[code];
//$tx='表头';
//echo $tx."\n\n";
//输出内容如下:
echo "序号"."\t";
echo "课程名称"."\t";
echo "专题名称"."\t";
echo "年度"."\t";
echo "季度"."\t";
$list=l($sql);
foreach ($list as $key=>$ll)
{
echo "\n";
echo $now_num=($key+1)."\t";
echo $ll[lessonname]."\t";
echo show_subject_name($ll[subject])."\t";
echo $ll[year]."\t";
if ($ll[season]=='1'){echo "春季"."\t";}
if ($ll[season]=='2'){echo "秋季"."\t";}
}
?>
导入用PHPExcel
voidman
2013-07-04 10:14:37 +08:00
recih
2013-07-04 10:52:04 +08:00
excel 对 CSV 的支持不好,不支持 utf-8 编码。
可以保存成 XML Spreadsheet,excel 能够直接双击打开。具体格式可 google “XML Spreadsheet”
另外也可以把一个 xslx 用excel另存为 “XML 电子表格 2003” 格式来研究下格式
shiny
2013-07-04 11:05:34 +08:00
以前写过基于 XML 的Excel 格式,好处是简单,兼容性还不错,而且可以自定义某些单元格的格式和样式。同楼上,可以自己搜索下。
https://gitcafe.com/daijie/php_xml_excel/blob/master/xml_excel.php
meteor2013
2013-07-04 11:31:50 +08:00
看来大家用PHPexcel 还不少,这东西的确也挺方便的。

但是大家觉得PHPexcel可以拿来做商业用途吗?
loveminds
2013-07-04 11:38:44 +08:00
@gDD
@meteor2013
@moxuanyuan
@lucky215
估计你们指的是xlsx
meteor2013
2013-07-04 11:44:02 +08:00
@loveminds xlsx 和 xls

顺便说一句,loveminds的头像好漂亮。
loveminds
2013-07-04 12:11:11 +08:00
@meteor2013 额,一般般而已,论外貌我从来都只是中等或者中上而已
Mr01
2013-07-04 13:05:13 +08:00
@loveminds 头像真漂亮 是本人?中等偏上什么的最好了
看头像 属于微胖界?抱歉失礼
graypants
2013-07-04 17:22:36 +08:00
我们公司发布的项目是用的phpExcel。关于po主关心的是否能商用,可参考“LGPL允许商业软件通过类库引用(link)方式使用LGPL类库而不需要开源商业软件的代码。这使得采用LGPL协议的开源代码可以被商业软件作为类库引用并发布和销售”
meteor2013
2013-07-04 22:51:14 +08:00
@graypants 太好了。 这样的话就直接用phpexcel 了.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/74689

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX