Php exports data to execl file format

Source: Internet
Author: User
Php exports data to execl file format
Php exports data to execl file format

  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. }
  33. $ Table. ='
  34. $ Table. ="
  35. $ Table. ='
  36. '; '; '; "; '; '; '; '; '; '; '; '; ';
    Id Title Phone Number Address Review status Content Message time
    ". $ Value ['id'].'". $ Value ['title'].'". $ Value ['phone'].'". $ Value ['address'].'". $ Value ['ischeck'].'". $ Value ['content'].'". Substr ($ value ['datetime'], 0, 11 ).'
    ';
  37. Echo $ table;
  38. ?>

  1. Session_start ();
  2. $ Link = mysql_connect ("localhost", "root", "") or die ("cocould 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'
  22. Echo'
  23. Echo'
  24. Echo'
  25. Foreach ($ content as $ k => $ v ){
  26. Echo"
  27. Echo"
  28. Echo"
  29. Echo"
  30. Echo"
  31. Echo"
  32. Echo"
  33. Echo"
  34. }
  35. Echo'
  36. Echo"
  37. Echo'';
  38. Echo'
  39. '; '; '; '; '; '; '; '; '; '; '; '; '; '; "; "; "; "; "; "; "; "; "; ';
    Video List (index: lanmu displayed on the home page: displayed on the video page)
    Serial NumberUser uidDisplay positionFile nameVideo nameVideo introductionUpload time
    $ K{$ V ['title']}{$ V ['phone']}{$ V ['address']}{$ V ['ischeck']}{$ V ['content']}{$ V ['datetime']}
    ';
  40. // Var_dump ($ content );
  41. Mysql_free_result ($ rs1 );
  42. Mysql_close ($ link );
  43. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.