Skip to content

Instantly share code, notes, and snippets.

@kiichi
Last active November 21, 2020 19:25
Show Gist options
  • Save kiichi/aeb3964b68d40f75246869c0c456c936 to your computer and use it in GitHub Desktop.
Save kiichi/aeb3964b68d40f75246869c0c456c936 to your computer and use it in GitHub Desktop.
Generate Excel using HTML format
function downloadExcel($table_html, $style_html){
$file="gmdi.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
$excel = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
<!--[if gte mso 9]>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet 1</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
<![endif]-->
'.$style_html.'
</head>
<body>
'.$table_html.'
</body>
</html>';
echo $excel;
exit();
}
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
<!--[if gte mso 9]>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet 1</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
<![endif]-->
<style>
* { }
</style>
</head>
<body>
<table><tr><td>hello</td></tr></table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment