& Lt ;? Phpheader (& quot; content-type: applicationvndms-excel; charsetgbk & quot;); header (& quot; content-disposition: attachment; filenametest_dataxls & quot;); $
-
- Header ("content-type: application/vnd. ms-excel; charset = gbk ");
- Header ("content-disposition: attachment?filename=test_data.xls ");
-
- $ Link = mysql_connect ('localhost', 'root', 'hhhkkk ');
- If ($ link ){
- Mysql_select_db ('dataui', $ link );
- Mysql_query ("set names 'gbk '");
- Echo "the database connection is 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 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.
-
- // Experiment data. in actual operations, the data is obtained from the database.
- $ Emps [0] ['id'] = '000000 ';
- $ Emps [0] ['name'] = 'abc ';
- $ Emps [0] ['sexual'] = 'male ';
- $ Emps [0] ['age'] = 28;
- $ Emps [1] ['id'] = '000000 ';
- $ Emps [1] ['name'] = 'BBC ';
- $ Emps [1] ['sexual'] = 'male ';
- $ Emps [1] ['age'] = 23;
- $ Emps [2] ['id'] = '000000 ';
- $ Emps [2] ['name'] = 'CBA ';
- $ Emps [2] ['sexual'] = 'female ';
- $ Emps [2] ['age'] = 20;
- Ini_set ('include _ path', '/data/website/htdocs/upload ');
- 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 ');
- ?>