使用php将HTML表导出到EXCEL文件

时间:2011-07-20 02:15:02

标签: export-to-excel

我想问一下将html表输出到excel的代码,因为html表在result.php中

谢谢!

3 个答案:

答案 0 :(得分:0)

如果您的数据是纯表(即没有图表),您应该考虑使用csv(http://en.wikipedia.org/wiki/Comma-separated_values)格式而不是excel。我不会在编程方面掌握你的技能,但这应该不难做到。

答案 1 :(得分:0)

$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";
header('Pragma: public');
header("Content-type: application/vnd.ms-excel"); 
header("Content-Disposition: attachment;filename=myfile.xls");
echo $test;

答案 2 :(得分:-1)

function exporttoexcel(){
var i;
var j;
var mycell;
var tableID = "crtfdetails";

var objXL = new ActiveXObject("Excel.Application");
var objWB = objXL.Workbooks.Add();
var objWS = objWB.ActiveSheet;

for (i=0; i < document.getElementById(tableID).rows.length; i++)
{
    for (j=0; j < document.getElementById(tableID).rows(i).cells.length; j++)
    {
        mycell = document.getElementById(tableID).rows(i).cells(j)
        objWS.Cells(i+1,j+1).Value = mycell.innerText;
    }
}
objWS.Range("A1", "Z1").EntireColumn.AutoFit();
objXL.Visible = true;
}