本文目录一览:
php格式怎么用excel文件
PHP 输出EXCEL文件有种简单的方式:
定义header() 头部输出格式:
---头部输出格式的步骤有两种:
.header("Content-type:application/vnd.ms-excel");
.header("Content-Disposition:filename=php100.xls");
举例如下:
?php
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=php100.xls");
echo "A1\t B1\t C1\n";
echo "A2\t B2\t C2\n";
echo "A3\t B3\t C3\n";
?
显示的结果:
一个3行3列的excel 文件
A1 B1 C1
A2 B2 C2
A3 B3 C3
php生成excel完整实例代码
下载phpexcel类库 代码如下:
?php
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');
$objPHPExcel=new PHPExcel();
$iofactory=new IOFactory();
//获得数据 ---一般是从数据库中获得数据
$data=array(
0=array('id'=2013,'name'='张某某','age'=21),
1=array('id'=201,'name'='EVA','age'=21)
);
//设置excel列名
$objPHPExcel-setActiveSheetIndex(0)-setCellValue('A1','编号');
$objPHPExcel-setActiveSheetIndex(0)-setCellValue('B1','姓名');
$objPHPExcel-setActiveSheetIndex(0)-setCellValue('C1','年龄');
//把数据循环写入excel中
foreach($data as $key = $value){
$key+=2;
$objPHPExcel-setActiveSheetIndex(0)-setCellValue('A'.$key,$value['id']);
$objPHPExcel-setActiveSheetIndex(0)-setCellValue('B'.$key,$value['name']);
$objPHPExcel-setActiveSheetIndex(0)-setCellValue('C'.$key,$value['age']);
}
//excel保存在根目录下 如要导出文件,以下改为注释代码
$objPHPExcel-getActiveSheet() - setTitle('SetExcelName');
$objPHPExcel- setActiveSheetIndex(0);
$objWriter = $iofactory - createWriter($objPHPExcel, 'Excel2007');
$objWriter - save('SetExcelName.xlsx');
//导出代码
// $objPHPExcel-getActiveSheet() - setTitle('SetExcelName');
// $objPHPExcel- setActiveSheetIndex(0);
// $objWriter = $iofactory - createWriter($objPHPExcel, 'Excel2007');
// $filename = 'SetExcelName.xlsx';
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename="' . $filename . '"');
// header('Cache-Control: max-age=0');
// $objWriter - save('php://output');
?
php 创建excel时wamp怎样设置
进入php源程序目录中的ext目录中,这里存放着各个扩展模块的源代码,选择你需要的模块,比如curl模块:cd curl
执行phpize生成编译文件,phpize在PHP安装目录的bin目录下
/usr/local/php5/bin/phpize
运行时,可能会报错:Cannot find autoconf. Please check your autoconf installation and
the $PHP_AUTOCONF
environment variable is set correctly and then rerun this
script.,需要安装autoconf:
yum install autoconf(RedHat或者CentOS)、apt-get install
autoconf(Ubuntu Linux)
/usr/local/php5/bin/php -v
执行这个命令时,php会去检查配置文件是否正确,如果有配置错误,
这里会报错,可以根据错误信息去排查!