Blogger Information
Blog 33
fans 0
comment 1
visits 43138
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP将HTML表格导出为Excel文件
萝卜温的博客
Original
3729 people have browsed it
/**
 * 把html table内容导出到xls文件
 * @param  [type] $filename 文件名
 * @param  [type] $table    html table代码
 * @return [type]           file
 */
function export_xls($filename,$table){
    //可以修改样式,控制字号、字体、表格线、对齐方式、表格宽度、单元格padding等,在下边的<style></style>
    $header="<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\nxmlns=\"http://www.w3.org/TR/REC-html40\">\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html>\n<head>\n<meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\" />\n<style>\ntd{padding:4px;mso-ignore:padding;color:windowtext;font-size:10.0pt;font-weight:400;font-style:normal;text-decoration:none;font-family:Arial;mso-generic-font-family:auto;mso-font-charset:134;mso-number-format:General;text-align:general;vertical-align:middle;border:.5pt solid windowtext;mso-background-source:auto;mso-pattern:auto;mso-protection:locked visible;white-space:nowrap;mso-rotate:0;}\n</style>\n</head><body>\n";
    $footer="\n</body></html>";
    $exportString=$header.$table.$footer;
 
    header("Cache-Control:public");
    header("Pragma:public");
    header("Content-type: Content-type:application/vnd.ms-excel");
    header("Accept-Ranges: bytes");
    header("Content-Disposition:attachment; filename=".$filename);
    header("Content-length:".strlen($exportString));
    echo $exportString;
    exit;
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post