PhpSpreadsheet 原

2019-05-21 23:31:48 浏览数 (1)

为什么80%的码农都做不了架构师?>>>

代码语言:javascript复制
"require-dev": {
     "phpoffice/phpspreadsheet": "^1.6"
},
代码语言:javascript复制
use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetIOFactory;
代码语言:javascript复制
$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');

0 人点赞