zoukankan      html  css  js  c++  java
  • 通过PHPExcel创建Excel文档

     

    1、创建PHPExcel类(相当于打开Excel软件)

    $phpexcel=new PHPExcel();
    

    2、创建Excel文档

    方法一、使用createWriter创建

    初始化phpwriter类对象,第二个参数:excel5代表是2003版本,excel2007表示高版本

    $phpwriter=PHPExcel_IOFACTORY::createWriter($phpexcel,'excel5');
    

    方法二、使用PHPExcel_Writer_EXCEL5创建

    $phpwriter=new PHPExcel_Writer_EXCEL5($phpexcel);
    

    3、直接成生Excel文件

    $phpwriter->save('test.xls');
    

    4、输出Excel表格到浏览器下载

    header('Content-Type: application/vnd.ms-excel');//设置文档类型
    header('Content-Disposition: attachment;filename="filename.xls"');//设置文件名
    header('Cache-Control: max-age=0');
    $phpwriter = new PHPExcel_Writer_Excel5($objPHPExcel);
    $phpwriter->save('php://output');
    

    其它header 属性设置

    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="resume.xls"');
    header("Content-Transfer-Encoding:binary");
    $objWriter->save('php://output');
  • 相关阅读:
    [BJOI2019] 光线
    [BJOI2019]奥术神杖
    [HNOI2014]江南乐
    [SDOI2018]荣誉称号
    [APIO2015]雅加达的摩天楼
    [TJOI2015]线性代数
    【CF163E 】e-Government
    【CF917D】Stranger Trees
    网络流(四)dinic算法
    网络流(三)最大流最小割定理
  • 原文地址:https://www.cnblogs.com/yangchunlong/p/8305183.html
Copyright © 2011-2022 走看看