简体   繁体   English

HTML表格excel - PHP

[英]HTML table to excel - PHP

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. 我想以excel格式链接提供下载报告,以便报告也可以在excel文件中使用。 How can I do this 我怎样才能做到这一点

Either you can use CSV functions or PHPExcel Or there is even a better and a simple solution. 你可以使用CSV函数PHPExcel或者甚至有一个更好,更简单的解决方案。 Just put the Table HTML in a file and save it as XLS file but that might give variety of problems. 只需将表格HTML放在一个文件中并将其保存为XLS文件,但这可能会带来各种问题。

<?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;
?>

I've used a service called DocRaptor which does awesome html to excel conversion. 我使用了一个名为DocRaptor的服务,该服务可以实现卓越的html转换。 It also does html to pdf conversion. 它也做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的外观有更好的解决方案,我还没有看到它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM