Home > Backend Development > PHP Tutorial > Two PHP export excel examples_PHP tutorial

Two PHP export excel examples_PHP tutorial

WBOY
Release: 2016-07-13 10:58:22
Original
917 people have browsed it

Two php tutorials to export excel examples

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";
$sql2="select * from php168_item_content_1 where id='$rs[id]'";
$query2=mysql_query($sql2);
While($rs2=mysql_fetch_array($query2)){
echo $rs2[content]."t";
echo "n";
                     
}
                                                                      }

?>

When exporting excel, if a certain column exports an ID number, you will find after opening the excel file that the ID number automatically uses scientific notation. No matter how you modify the column attributes, you will not be able to achieve your requirements. Some people on the Internet said that after changing the column attribute to text, there will be no problem when inputting it. This is indeed the case in Excel, but it cannot be done when exporting from the PHP program

//Experimental data, in actual operations, the data should be obtained from the database
           $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 the 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.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632027.htmlTechArticleTwo php tutorials to export excel examples?php header(content-type:application/vnd.ms-excel; charset =gbk); header(content-disposition:attachment;filename=test_data.xls); $link=mysql tutorial_c...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template