Skip to content

Commit

Permalink
exportExcel
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan committed Jun 13, 2019
1 parent d64a386 commit eb82bb0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit eb82bb0

Please sign in to comment.