php export data to execl file format

WBOY
Release: 2016-07-25 09:08:27
Original
1083 people have browsed it
php将数据导出为execl文件格式
  1. ? session_start();
  2. $sql_excel="";
  3. if(isset($_SESSION["excel"]))
  4. {
  5. $sql_excel=$_SESSION["excel"];
  6. }
  7. //unset($_SESSION["excel"]);
  8. $conn=mysql_connect("localhost","root","");
  9. mysql_select_db("test");
  10. mysql_query("set names utf8",$conn);
  11. $result=mysql_query($sql_excel);
  12. header("Content-type:application/vnd.ms-excel");
  13. header("Content-Disposition:attachment;filename=export_data.xls");
  14. //$result=mysql_query($sql_excel);
  15. $result=mysql_query($sql_excel);
  16. while($arr = mysql_fetch_assoc($result)){
  17. $content[]=$arr;
  18. }
  19. // print_r($content);
  20. $table = '
  21. $table .= '
  22. $table .= '
  23. foreach($content as $key=>$value){
  24. $table .= "
  25. $table .= "
  26. $table .= "
  27. $table .= "
  28. $table .= "
  29. $table .= "
  30. $table .= "
  31. $table .= "
  32. $table .= '
  33. }
  34. $table .= '
  35. $table .= '
  36. '; '; '; "; '; '; '; '; '; '; '; '; ';
    id 标题 电话 地址 审核状态 内容 留言时间
    ".$value['id'].'".$value['title'].'".$value['phone'].'".$value['address'].'".$value['ischeck'].'".$value['content'].'".substr($value['datetime'],0,11).'
    ';
  37. echo $table;
  38. ?>
复制代码
php export data to execl file format
  1. session_start();
  2. $link= mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
  3. mysql_query("set names utf8",$link);
  4. mysql_select_db("test");
  5. $sqls = "select * from news order by id desc ";
  6. $_SESSION["excel"]=$sqls;
  7. $rs1 = mysql_query($ sqls);
  8. while($arr = mysql_fetch_assoc($rs1)){
  9. $content[]=$arr;
  10. }
  11. echo '
  12. echo '
  13. echo '
  14. echo '
  15. echo '
  16. echo '
  17. echo '
  18. echo '
  19. echo '
  20. echo '
  21. echo '< /thead>';
  22. echo '
  23. foreach ($content as $k => $v){
  24. echo "
  25. echo "
  26. echo "
  27. echo "
  28. echo "
  29. echo "
  30. echo "
  31. echo "
  32. }
  33. echo '';
  34. echo '
  35. echo '
  36. '; '; '; '; '; '; '; '; '; '; '; "; "; "; "; "; "; "; "; ';
    Video list (index: Display on the homepage lanmu: Display on the video page)
    serial numberuser uid< /th>';
  37. echo '
  38. Display locationFile nameVideo name
  39. echo '
  40. Video introductionUpload time
    $k{$v['title']}< ;/td>";
  41. echo "
  42. {$v['phone']}{$v['address']}{$v['ischeck']}{$v['content']}{$v['datetime']}
    ';
  43. //var_dump($content);
  44. mysql_free_result($ rs1);
  45. mysql_close($link);
  46. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!