如何将MYSQL中的数据导入到EXCEL中??

我想知道怎么样可以用PHP实现把数据表中的内容导入EXCEL,并自动生成.xls文件,谢了先。
---------------------------------------------------------------

 1   
 2// 转载请注明phpteam   
 3$title = "数据库名:test, 数据表:test, 备份日期:" . date("Y-m-d H:i:s");   
 4$sep = "\t";   
 5$crlf = "\n";   
 6  
 7$conn = @mysql_connect("localhost", "root", "") or die("不能连接数据库");   
 8@mysql_select_db("test", $conn);   
 9header("Content-Type: application/vnd.ms-excel");   
10header("Content-Disposition: attachment; filename=test.xls");   
11header("Pragma: no-cache");   
12header("Expires: 0");   
13  
14echo $title . $crlf . $crlf;   
15  
16$query = "select * from test";   
17$result = mysql_query($query) or die(mysql_error());   
18$fields = mysql_num_fields($result);   
19for($i = 0; $i < $fields; $i++) {   
20echo mysql_field_name($result, $i) . $sep;   
21}   
22echo $crlf;   
23while($row = mysql_fetch_row($result)) {   
24$line = "";   
25for($i = 0; $i<$fields; $i++) {   
26$line .= $row[$i] . $sep;   
27}   
28echo $line . $crlf;   
29}   

---------------------------------------------------------------

application->Workbooks->Open($workbook) or Die ("打不开!!!"); $sheets = $book->Worksheets($sheet); $sheets->activate; for($m_i=0;$m_i<$col;$m_i++) { for($m_j=0;$m_j<4;$m_j++) { $cell=$sheets->Cells($m_i+2,$m_j+1); $cell->activate; $cell->value=$m_array[$m_i][$m_j]; } } $ex->Application->ActiveWorkbook->SaveAs("c:\c1.xls"); $ex->Application->ActiveWorkbook->Close("False"); unset ($ex); }
Published At
Categories with Web编程
comments powered by Disqus