wugg 3 سال پیش
والد
کامیت
d24a93e478
2فایلهای تغییر یافته به همراه53 افزوده شده و 1 حذف شده
  1. 52 0
      application/Admin/common.php
  2. 1 1
      application/Admin/controller/Order.php

+ 52 - 0
application/Admin/common.php

@@ -221,3 +221,55 @@ function deldir($path){
     return rmdir($path);
 }
 
+function excelExport($fileName = '', $headArr = [], $data = [])
+{
+    $objPHPExcel = new PHPExcel();
+    $objPHPExcel->getProperties();
+    $keyA = 0; // 设置表头
+    foreach ($headArr as $v) {
+        $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
+        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
+        $keyA += 1;
+    }
+
+    $column = 2;
+    $objActSheet = $objPHPExcel->getActiveSheet();
+
+    foreach ($data as $key => $rows) { // 行写入
+        $span = 0;
+        foreach ($rows as $keyName => $value) { // 列写入
+            //判断数据是否有数组,如果有数组,转换成字符串
+
+            if(is_array($value)){
+                $value = implode("、", $value);
+            }
+            $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
+            $span++;
+        }
+        $column++;
+    }
+    //  var_dump($objActSheet->getActiveCell());
+    $fileName .= "_" . date("Y_m_d", time()) . ".xls";
+    //$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
+    //$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
+
+    $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
+    // Redirect output to a client’s web browser (Excel2007)
+    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+    header('Content-Disposition: attachment;filename="'.$fileName.'"');
+    header('Cache-Control: max-age=0');
+// If you're serving to IE 9, then the following may be needed
+    header('Cache-Control: max-age=1');
+
+// If you're serving to IE over SSL, then the following may be needed
+    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
+    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
+    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
+    header ('Pragma: public'); // HTTP/1.0
+
+    // header("Content-Type: application/octet-stream");                           # 流文件输出
+    //  header("Content-Transfer-Encoding: binary");                                # 告诉浏览器,这是二进制文件
+    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
+    $objWriter->save('php://output'); // 文件通过浏览器下载
+    exit();
+}

+ 1 - 1
application/Admin/controller/Order.php

@@ -181,7 +181,7 @@ FROM
         array_walk($list, function (&$v) {
             $v = array_values($v);
         });
-        excelSave(date("Y-m-d")."未发货订单", $header, $list);
+        excelExport(date("Y-m-d")."未发货订单", $header, $list);
     }
 
 }