PhpSpreadsheet

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

"require-dev": {
     "phpoffice/phpspreadsheet": "^1.6"
},

 

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->setTitle('工作表格1');

$spreadsheet->getActiveSheet()->setTitle('Hello');
//表头
$k = 1;
$worksheet->setCellValue('A'.$k, '业务类型');
$worksheet->setCellValue('B'.$k, '商品总价');
$worksheet->setCellValue('C'.$k, '被推荐费');
$worksheet->setCellValue('D'.$k, '推荐费');
$worksheet->setCellValue('E'.$k, '成本费');
$worksheet->setCellValue('F'.$k, '商家应得');

//设置单元格内容
if($order){



    $k = 2; //从第二行开始
    foreach ($order as $key =>$val) {

        $worksheet->setCellValue('A'.$k, $val['pl_alias']);
        $worksheet->setCellValue('B'.$k, $val['price_total']);
        $worksheet->setCellValue('C'.$k, $val['be_recNum']);
        $worksheet->setCellValue('D'.$k, $val['be_recNum']);
        $worksheet->setCellValue('E'.$k, $val['recNum']);
        $worksheet->setCellValue('F'.$k, $val['deserved']);
        $k++;

    }
}





$fileName = '每日收益--'.$get['start_time'].'.xlsx';


header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$fileName.'"');
header('Cache-Control: max-age=0');


$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');

转载于:https://my.oschina.net/u/3371661/blog/3048130

你可能感兴趣的:(PhpSpreadsheet)