大佬教程收集整理的这篇文章主要介绍了使用PHPExcel导出Excel表,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例为大家分享了PHPExcel导出Excel表的具体代码,供大家参考,具体内容如下
//创建新的phpExcel对象
$objphpExcel = new \phpExcel();
$objProps = $objphpExcel->getProperties();
//设置表头
$key = ord("A");
$key2 = ord("A");
$colum2 = '';
$objActSheet = $obj<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel->getActiveSheet();
$obj<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel->getActiveSheet()->getcolumnDimension('A')->setWidth(25);
foreach($headArr as $v){
$colum = chr($key);
$obj<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel->setActiveSheeTindex(0) ->setCellValue($colum2.$colum.'1',$v);
if($key < 90){
$key += 1;
}else{
$key = ord("A");
$colum2 = chr($key2);
$key2++;
}
}
//exit;
$column = 2;
foreach($data as $key => $rows){ //行写入
$span = ord("A");
$span2 = ord("A");
$j2 = '';
foreach($rows as $keyName=>$value){// 列写入
$j = chr($span);
//$objActSheet->setCellValue($j.$column,$value);
//把每个单元格设置成分文本类型
//dump($j2.$j.$column);
$objActSheet->setCellValueExplicit($j2.$j.$column,$value,\<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel_Cell_DataType::TYPE_StriNG);
if($span < 90){
$span += 1;
}else{
$span = ord("A");
$j2 = chr($span2);
$span2++;
}
}
$column++;
}
// exit;
$filename = iconv("utf-8","gb2312",$fileName);
//重命名表
$objphpExcel->getActiveSheet()->settitle('Simple');
//设置活动单指数到第<a href="http://code.js-code.com/tag/yige/" target="_blank" class="keywords">一个</a>表,所以Excel打开这是第<a href="http://code.js-code.com/tag/yige/" target="_blank" class="keywords">一个</a>表
$obj<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel->setActiveSheeTindex(0);
//将<a href="http://code.js-code.com/tag/shuchu/" target="_blank" class="keywords">输出</a><a href="http://code.js-code.com/tag/zhongdingxiang/" target="_blank" class="keywords">重定向</a>到<a href="http://code.js-code.com/tag/yige/" target="_blank" class="keywords">一个</a>客户端web浏览器(Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Cache-Control: max-age=0');
$objWriter = \<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel_IOFactory::createWriter($obj<a href="http://code.js-code.com/tag/php/" target="_blank" class="keywords">php</a>Excel,'Excel2007');
// if(!empty($_GET['excel'])){
// $objWriter->save('PHP://output'); //文件通过浏览器下载
// }else{
// $objWriter->save($fileName); //脚本方式运行,保存在当前目录
// }
$objWriter->save('PHP://output');
exit;
}
以上是大佬教程为你收集整理的使用PHPExcel导出Excel表全部内容,希望文章能够帮你解决使用PHPExcel导出Excel表所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。