php导出Excle表

public function exportExcel($expTitle, $expCellName, $expTableData)
{
    $cellNum = count($expCellName);
    $dataNum = count($expTableData);

    vendor("PHPExcel");

    $objPHPExcel = new \PHPExcel();
    $cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
    //$objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setWrapText(true);
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '序号');
    for ($i = 0; $i < $cellNum; $i++) {
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i + 1] . '1', $expCellName[$i][1]);
    }

    // Miscellaneous glyphs, UTF-8
    for ($i = 0; $i < $dataNum; $i++) {
        $objPHPExcel->getActiveSheet(0)->setCellValue('A' . ($i + 2), $i + 1);
        for ($j = 0; $j < $cellNum; $j++) {
            $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j + 1] . ($i + 2), $expTableData[$i][$expCellName[$j][0]]);
        }
    }

    header('pragma:public');
    header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $expTitle . '.xls"');
    header("Content-Disposition:attachment;filename=$expTitle.xls");//attachment新窗口打印inline本窗口打印
    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
    exit;
}
public function nursingExportInfo(){
    vendor("PHPExcel");
    $res=db('nursing_consumables')->select();
    //dump($res);die();
    $xlsCell = array(
        array('nursing_consumables_id', '编号'),
        array('nursing_consumables_input_code', '输入码'),
        array('nursing_consumables_name', '名称'),
        array('nursing_consumables_specifications', '规格'),
        array('nursing_consumables_manufacturer_name', '厂家名称'),
        array('nursing_consumables_company', '单位'),
        array('nursing_consumables_whole_number', '整包数量'),
        array('nursing_consumables_bulk_number', '散装数量'),
        array('nursing_consumables_wholesale_price','批发售价'),
        array('nursing_consumables_retail_price','零售价'),
        array('nursing_consumables_use_company','使用单位'),
        array('nursing_consumables_packing_number','包装内数量'),
    );
    $xlsName = '护理耗材表';

    $this->exportExcel($xlsName, $xlsCell, $res);
}
文章来源: php导出Excle表

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:php导出Excle表