Two PHP export Excel instance _php tutorial

Source: Internet
Author: User
Tags mysql tutorial
Two PHP tutorials Export Excel instances

Header ("Content-type:application/vnd.ms-excel; CHARSET=GBK ");
Header ("Content-disposition:attachment;filename=test_data.xls");


$link =mysql tutorial _connect (' localhost ', ' root ', ' hhhkkk ');
if ($link) {

mysql_select_db (' Dataui ', $link);
mysql_query ("Set names ' GBK '");
echo "Database Tutorial connection has been successful! ";
}else{
echo "Database connection failed! ";
}

echo "Project name". " T ";
echo "Project Details". " T ";
$sql = "SELECT * from Php168_item_content where fid= ' 11";
$query =mysql_query ($sql);
while ($rs =mysql_fetch_array ($query)) {
echo $rs [title]. " T ";
$sql 2= "SELECT * from php168_item_content_1 where id= ' $rs [id] '";
$query 2=mysql_query ($sql 2);
while ($rs 2=mysql_fetch_array ($query 2)) {
Echo $rs 2[content]. " T ";
echo "n";

}

}


?>

When you export Excel, if a column exports a social security number, open the Excel file will find that the Social Security number automatically adopted scientific notation, regardless of modifying the column properties, can not achieve their own requirements. Some people on the internet said that the first time to change the column properties to text, and then input there is no problem, the actual operation of Excel is true, but the PHP program can not be exported

Experimental data, actual work, this should be obtained from the database data
$emps tutorial [0][' id '] = ' 00001 ';
$emps [0][' name '] = ' abc ';
$emps [0][' sexual '] = ' male ';
$emps [0][' age '] = 28;

$emps [1][' id '] = ' 00002 ';
$emps [1][' name '] = ' BBC ';
$emps [1][' sexual '] = ' male ';
$emps [1][' age '] = 23;

$emps [2][' id '] = ' 00003 ';
$emps [2][' name '] = ' CBA ';
$emps [2][' sexual '] = ' female ';
$emps [2][' age '] = 20;

Ini_set (' include_path ', '/data/website/htdocs/includes ');
Require_once (' smarty.php ');
$smarty = new Smarty ();

$smarty->assign (' Emps ', $emps);

Output file header, indicating that the Excel file is to be output
Header ("Content-type:application/vnd.ms-excel");
Header ("content-disposition:attachment; Filename=test.xls ");
$smarty->display (' Excel-xml.tpl ');
?>

http://www.bkjia.com/PHPjc/632027.html www.bkjia.com true http://www.bkjia.com/PHPjc/632027.html techarticle Two PHP Tutorials export an Excel instance? PHP header (content-type:application/vnd.ms-excel; charset=gbk); Header (content-disposition: Attachment;filename=test_data.xls); $link =mysql Tutorial _c ...

  • Related Article

    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.