|
|
@@ -3,6 +3,8 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
|
|
/**
|
|
|
* 包装计件单据维护接口
|
|
|
@@ -551,8 +553,9 @@ class PackagingCountDocument extends Api
|
|
|
array_push($data,$subArray);
|
|
|
}
|
|
|
}
|
|
|
+ $this->Ex($req['file_name'],$data);
|
|
|
|
|
|
- $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
|
|
|
+// $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -633,6 +636,31 @@ class PackagingCountDocument extends Api
|
|
|
}
|
|
|
array_push($data,$subArray);
|
|
|
}
|
|
|
- $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
|
|
|
+ $this->Ex($req['file_name'],$data);
|
|
|
+// $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
|
|
|
}
|
|
|
+
|
|
|
+ public function Ex($file_name,$data)
|
|
|
+ {
|
|
|
+ $spreadsheet = new Spreadsheet();
|
|
|
+
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
+
|
|
|
+ $sheet->setTitle($file_name);
|
|
|
+
|
|
|
+ // 将数据逐行写入工作表
|
|
|
+ foreach ($data as $rowIndex => $rowData) {
|
|
|
+ // 将每个单元格的值写入对应的列
|
|
|
+ foreach ($rowData as $columnIndex => $cellData) {
|
|
|
+ $sheet->setCellValueByColumnAndRow($columnIndex + 1, $rowIndex + 1, $cellData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+
|
|
|
+ header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ return json($writer->save("php://output")); //表示在$path路径下面生成demo.xlsx文件
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|