计算机网络/计算机科学与应用/系统/运维/开发

PHPExcel 创建Excel文档

<?php 
    require 'vendor/autoload.php';
    
    $phpexcel = new PHPExcel();
    
    // 创建excel文档 方法1
    $phpwriter = PHPExcel_IOFACTORY::createWriter($phpexcel,'Excel5');
    //$phpwriter = PHPExcel_IOFACTORY::createWriter($phpexcel,'Excel2007');
    
    // 方法2
    $phpwriter = new PHPExcel_Writer_Excel5($phpexcel);
    //$phpwriter = new PHPExcel_Writer_Excel2007($phpexcel);
    
    // 直接生成文件
    //$phpwriter->save('test.xls');
    
    // 输出Excel表格到浏览器下载
    header('Content-Type:application/vnd.ms-excel');// 设置文档类型
    header('Content-Type:application/force-download');
    header('Content-Type:application/octet-stream');
    header('Content-Type:application/download');
    header('Content-Disposition:attachment;filename="filename.xls"');  // 设置文件名
    $phpwriter->save('php://output');


世间最珍贵的不是“得不到”和“已失去”,而是现在能把握的幸福。

评论

^