From eb82bb0bb231694eed7b7090fcd7c1aa339bc82f Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 13 Jun 2019 16:33:36 +0800 Subject: [PATCH] exportExcel --- src/Excel.php | 17 ++++++++++++----- test/2.php | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Excel.php b/src/Excel.php index d507944..1551595 100755 --- a/src/Excel.php +++ b/src/Excel.php @@ -300,13 +300,20 @@ public static function toExcelFile($data, $map = array(), $filename = '', $workS */ public static function exportExcel($data, $map = array(), $filename = '', $workSheetName = 'Worksheet') { - //弹出下载对话框 - header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename=' . $filename); + $tempFile = static::toExcelFile($data, $map, '', $workSheetName); - $tempFile = tempnam(sys_get_temp_dir(), 'excel'); + if (empty($filename)) { + $filename = @date('YmdHis') . '.xlsx'; + } - static::toExcelFile($data, $map, $tempFile, $workSheetName); + if (strtolower(substr($filename, -5)) != '.xlsx') { + $filename .= '.xlsx'; + } + + //弹出下载对话框 + //header('Content-Type: application/octet-stream'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename=' . $filename); readfile($tempFile); unlink($tempFile); diff --git a/test/2.php b/test/2.php index b404d56..2e6bab9 100644 --- a/test/2.php +++ b/test/2.php @@ -10,4 +10,6 @@ array('created' => '2015-01-01', 'product_id' => 873, 'quantity' => 1, 'amount' => '44.00', 'description' => 'misc'), array('created' => '2015-01-12', 'product_id' => 324, 'quantity' => 2, 'amount' => '88.00', 'description' => 'none'), ); + + PFinal\Excel\Excel::exportExcel($data); \ No newline at end of file