将数据从PHP导出到Excel [英] Exporting data from php to excel

查看:173
本文介绍了将数据从PHP导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据从php(从mysql数据库检索的数据)导出到excel.我正在使用Zend Framework.在导出到excel之前,我需要对数据进行一些更改.实际上,我真正需要的是每月产生现金簿.

I need to export data from php (data retrieved from mysql database) to excel. I'm using Zend Framework. I need to do some changes to my data before exporting to excel. Actually, what I really need is to generate a monthly cash book.

我看了很多文档,但结果一团糟.我真的不明白我应该如何开始.我真的需要梨吗?我需要下载任何类库吗?没有简单的方法吗?

I have read a lot of documents, but ended up in a mess. I really can't understand how I should begin. Do I really need PEAR? Do I need to download any class library?Isn't there a simple way to do this?

预先感谢

推荐答案

我建议您使用出色的PHPExcel库.它功能强大,支持多种格式,可以进行视觉格式化,并且易于使用.

I would suggest you to use great PHPExcel library. It is really powerful, supports variety of formats, can do visual formatting and is easy to use.

您可以在他们的网页上找到更多有关它的信息: http://phpexcel.codeplex.com/ . (PHPExcel已移至 https://github.com/PHPOffice/PHPExcel )

You can find more about it at their webpage: http://phpexcel.codeplex.com/. (PHPExcel has already moved at https://github.com/PHPOffice/PHPExcel)

PHPExcel现在已被 PhpSpreadsheet GitHub 取代

用法示例:

    $objPHPExcel = new PHPExcel();
    /** You can set many properties */
    $objPHPExcel->getProperties()->setCreator("My company")
                 ->setLastModifiedBy("John Doe")
                 ->setTitle("Annual report")
                 ->setSubject("Sales")
                 ->setDescription("Annual sales report by John Doe")
                 ->setCategory("Finance");

    /** Choose one of sheets */
    $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
    /** Simply set value of cell */
    $activeSheet->setCellValue("A1", 'plural');

您当然可以做更多的事情,阅读excel文件,设置视觉样式,创建图表,表达式等等.

You can do a lot more of course, reading excel files, setting visual styles, creating plots, expressions and lot more.

这篇关于将数据从PHP导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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