php生成excel文件并输出到浏览器
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-11 20:00:56 浏览: 评论:0
本文介绍了php spreadsheet_excel_writer与如何生成excel文件.
第一步,安装spreadsheet_excel_writer 由于这包使用ole包,您可能需要安装它,执行以下命令来执行更新:更新pear.php.net ole - 0.5 spreadsheet_excel_writer - 0.9.1
看一个实例,myfile.xls是文件名,包括路径,工作簿包含一个具有学生名单表,PHP实例代码如下:
- <?php
- require_once 'spreadsheet/excel/writer.php';
- // creating workbook
- $workbook = new spreadsheet_excel_writer('myfile.xls');
- // adding worksheet
- $worksheet =& $workbook->addworksheet('students');
- // data input
- $worksheet->write(0, 0, 'name');
- $worksheet->write(0, 1, 'grade');
- $worksheet->write(1, 0, 'ivancho');
- $worksheet->write(1, 1, 7);
- $worksheet->write(2, 0, 'mariika');
- $worksheet->write(2, 1, 7);
- $worksheet->write(3, 0, 'stoyancho');
- $worksheet->write(3, 1, 8);
- // saving file
- $workbook->close();
- ?>
下面来看一款把数据导出给用户保存吧,代码如下:
- <?php
- require_once 'spreadsheet/excel/writer.php';
- // creating workbook
- $workbook = new spreadsheet_excel_writer();
- // sending headers to browser
- $workbook->send('students.xls');
- // adding worksheet
- $worksheet =& $workbook->addworksheet('students');
- // data input
- $worksheet->write(0, 0, 'name');
- $worksheet->write(0, 1, 'grade');
- $worksheet->write(1, 0, 'ivancho');
- $worksheet->write(1, 1, 7);
- $worksheet->write(2, 0, 'mariika');
- $worksheet->write(2, 1, 7);
- //开源代码phpfensi.com
- $worksheet->write(3, 0, 'stoyancho');
- $worksheet->write(3, 1, 8);
- // sending the file
- $workbook->close();
- ?>
Tags: php生成excel php浏览器
相关文章
- ·php 生成excel xls文档(2014-09-10)
- ·php生成excel列名,超过26列大于Z问题解决办法(2014-09-10)
- ·php与浏览器缓存机制介绍(2014-08-28)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)