在网上找了phpexcel 生成了个简单的文件, 但最后他是用save方法 保存下来的 ,好像是输出到php://output( 我的理解),后台权限没过(好像不能访问这个地址,我已经登录了后台) 然后下载的文件是登录的那个网页 生成到服务器端 然后重定向下载是没问题的 但这样 我不好删除这个文件 对phpexcel不熟 求解 还是说换个库~~~
$objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5');$objwriter->save(str_replace('.php', '.xls', __file__));$callendtime = microtime(true);$calltime = $callendtime - $callstarttime;
回复讨论(解决方案) 上面代码搞错了 具体生成文件代码如下 :
getproperties()->setcreator(maarten balliauw) ->setlastmodifiedby(maarten balliauw) ->settitle(office 2007 xlsx test document) ->setsubject(office 2007 xlsx test document) ->setdescription(test document for office 2007 xlsx, generated using php classes.) ->setkeywords(office 2007 openxml php) ->setcategory(test result file);// add some data$objphpexcel->setactivesheetindex(0) ->setcellvalue('a1', 'hello') ->setcellvalue('b2', 'world!') ->setcellvalue('c1', 'hello') ->setcellvalue('d2', 'world!');// miscellaneous glyphs, utf-8$objphpexcel->setactivesheetindex(0) ->setcellvalue('a4', 'miscellaneous glyphs') ->setcellvalue('a5', 'éàèùâêîôûëïüÿäöüç');// rename worksheet$objphpexcel->getactivesheet()->settitle('simple');// set active sheet index to the first sheet, so excel opens this as the first sheet$objphpexcel->setactivesheetindex(0);// redirect output to a client’s web browser (excel2007)header('content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');header('content-disposition: attachment;filename=01simple.xlsx');header('cache-control: max-age=0');// if you're serving to ie 9, then the following may be neededheader('cache-control: max-age=1');// if you're serving to ie over ssl, then the following may be neededheader ('expires: mon, 26 jul 1997 05:00:00 gmt'); // date in the pastheader ('last-modified: '.gmdate('d, d m y h:i:s').' gmt'); // always modifiedheader ('cache-control: cache, must-revalidate'); // http/1.1header ('pragma: public'); // http/1.0$objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007');$objwriter->save('php://output');exit;
从 61 都 71 行都是为了向浏览器输出做的准备工作
如果你只是想保存到文件只需
$objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007');
$objwriter->save('文件名');
即可
换csv吧。 现在还用什么xls
fgetcsv 读
fputcsv 写
单纯导出excel文件
http://jingyan.baidu.com/article/915fc414f4c2e451384b205c.html
导出带图片的excel文件:
http://jingyan.baidu.com/article/4f7d5712aea37f1a201927d7.html