Browse Source

excel导出测试

曹鹤洋 1 year ago
parent
commit
59ed952c41
1 changed files with 6 additions and 0 deletions
  1. 6 0
      application/api/controller/PackagingCountDocument.php

+ 6 - 0
application/api/controller/PackagingCountDocument.php

@@ -656,9 +656,15 @@ class PackagingCountDocument extends Api
             }
         }
         $writer = new Xlsx($spreadsheet);
+// 将 Excel 文件转换为二进制数据
+        $excelData = $writer->writeToString();
+
+// 返回 Excel 数据给前端
+        $this->success('成功', $excelData);
 
         header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+
         $writer->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
 
     }