HTML 表格到 excel - PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3437745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML table to excel - PHP
提问by Mohd Viqar
I am creating a report in Table format. This report is displayed on the browser. I want to provide a download report in excel format link so that the report can be available in excel file also. How can I do this
我正在创建表格格式的报告。该报告显示在浏览器上。我想以 excel 格式链接提供下载报告,以便报告也可以在 excel 文件中使用。我怎样才能做到这一点
回答by Shubham
Either you can use CSV functionsor PHPExcelOr there is even a better and a simple solution. Just put the Table HTML in a file and save it as XLS file but that might give variety of problems.
您可以使用CSV 函数或PHPExcel或者甚至有更好更简单的解决方案。只需将表格 HTML 放在一个文件中并将其另存为 XLS 文件,但这可能会产生各种问题。
回答by Vibin TV
<?php
$file="test.xls";
$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $test;
?>
回答by Brennan
I've used a service called DocRaptorwhich does awesome html to excel conversion. It also does html to pdf conversion.
我使用了一个名为DocRaptor的服务,它可以将 html 转换为 excel。它还可以将 html 转换为 pdf。
If there are better solutions out there as far as retaining the look of your original html and css in Excel, I haven't seen them.
如果有更好的解决方案来保留 Excel 中原始 html 和 css 的外观,我还没有看到它们。

