• tp3.2 excel导出


    //导出操作
    function exportExcel($expTitle,$expCellName,$expTableData,$names,$width){
    $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
    $fileName = $expTitle.date('_Ymd_His');//or $xlsTitle 文件名称可根据自己情况设定
    $cellNum = count($expCellName);
    $dataNum = count($expTableData);
    vendor("PHPExcel.PHPExcel");
    vendor("PHPExcel.PHPExcel.IOFactory");
    $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->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle.' Export time:'.date('Y-m-d H:i:s'));//第一行标题
    for($i=0;$i<$cellNum;$i++){
    $objPHPExcel->getActiveSheet()->getColumnDimension($cellName[$i])->setWidth($width[$i]);
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i]);
    }

    for($i=0;$i<$dataNum;$i++){
    for($j=0;$j<$cellNum;$j++){
    if ($names[$j]=='way' && $expTableData[$i][$names[$j]]==1) {
    $string="充币";
    }else if($names[$j]=='way' && $expTableData[$i][$names[$j]]==2) {
    $string="提币";
    }else if($names[$j]=='way' && $expTableData[$i][$names[$j]]==3) {
    $string="转币";
    }else if ($names[$j]=='status' && $expTableData[$i][$names[$j]]==1) {
    $string="成功";
    }elseif ($names[$j]=='status' && $expTableData[$i][$names[$j]]==2) {
    $string="失败";
    }else if ($names[$j]=='status' && $expTableData[$i][$names[$j]]==0) {
    $string="处理中";
    }else{
    $string=$expTableData[$i][$names[$j]];
    }
    $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $string);
    }
    }
    header('pragma:public');
    header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
    header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
    exit;
    }

  • 相关阅读:
    五险一金
    mysql支持批量备份表的存储过程
    支持批量执行的mysql存储过程
    Json数组转表格
    linux 基础知识
    如何处理win2008报错—IIS服务器500
    快照劫持的原理与JS跳转的分析
    如何在Win2008+IIS7环境下设置404状态默认错误页?
    如何在Win2008+IIS7环境下设置301特定目录站内跳转?
    CPU温度过高,小设置降温处理
  • 原文地址:https://www.cnblogs.com/gjclr/p/9155382.html
Copyright © 2020-2023  润新知