Two php excel export instances

Source: Internet
Author: User
Tags php excel
& Lt ;? Phpheader (& quot; content-type: applicationvndms-excel; charsetgbk & quot;); header (& quot; content-disposition: attachment; filenametest_dataxls & quot;); $
  1. Header ("content-type: application/vnd. ms-excel; charset = gbk ");
  2. Header ("content-disposition: attachment?filename=test_data.xls ");
  3.  
  4. $ Link = mysql_connect ('localhost', 'root', 'hhhkkk ');
  5. If ($ link ){
  6. Mysql_select_db ('dataui', $ link );
  7. Mysql_query ("set names 'gbk '");
  8. Echo "the database connection is successful! ";
  9. } Else {
  10. Echo "database connection failed! ";
  11. }
  12. Echo "project name". "t ";
  13. Echo "Project Details". "t ";
  14. $ SQL = "select * from php168_item_content where fid = '11 '";
  15. $ Query = mysql_query ($ SQL );
  16. While ($ rs = mysql_fetch_array ($ query )){
  17. Echo $ rs [title]. "t ";
  18. $ Sql2 = "select * from php168_item_content_1 where id = '$ rs [id]'";
  19. $ Query2 = mysql_query ($ sql2 );
  20. While ($ rs2 = mysql_fetch_array ($ query2 )){
  21. Echo $ rs2 [content]. "t ";
  22. Echo "n ";
  23. }
  24. }
  25. ?>

When exporting an excel file, if an ID card number is exported to a column, you will find that the ID card number is automatically calculated in scientific notation. no matter how you modify this column attribute, you cannot meet your requirements. Some people say on the Internet that it is okay to change the attribute of this column to text and then input the column. the actual excel operation is true, but the php program cannot export the column.

  1. // Experiment data. in actual operations, the data is obtained from the database.
  2. $ Emps [0] ['id'] = '000000 ';
  3. $ Emps [0] ['name'] = 'abc ';
  4. $ Emps [0] ['sexual'] = 'male ';
  5. $ Emps [0] ['age'] = 28;
  6. $ Emps [1] ['id'] = '000000 ';
  7. $ Emps [1] ['name'] = 'BBC ';
  8. $ Emps [1] ['sexual'] = 'male ';
  9. $ Emps [1] ['age'] = 23;
  10. $ Emps [2] ['id'] = '000000 ';
  11. $ Emps [2] ['name'] = 'CBA ';
  12. $ Emps [2] ['sexual'] = 'female ';
  13. $ Emps [2] ['age'] = 20;
  14. Ini_set ('include _ path', '/data/website/htdocs/upload ');
  15. Require_once ('smarty. php ');
  16. $ Smarty = new smarty ();
  17. $ Smarty-> assign ('emps', $ emps );
  18. // Output file header, indicating that the excel file is to be output
  19. Header ("content-type: application/vnd. ms-excel ");
  20. Header ("content-disposition: attachment; filename=test.xls ");
  21. $ Smarty-> display ('Excel-xml. tpl ');
  22. ?>
Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.