作者cleanwind (骨傲風清(掛網))
看板PHP
標題Re: [請益] 資料表裡的資料寫入excel
時間Tue Sep 4 00:16:34 2007
Excel 檔案欄位分隔是用 \t
分行則是用 \r
至於 \n 我就不清楚有啥用途了 :p
※ 引述《nbaby19 (sh~~)》之銘言:
: 要把資料表3個欄位(department,education,class)的所有值寫到excel裡
: 我要讓excel裡的資料看起來是
: | number
: 3個欄位的值 |
: 3個欄位... |
: 3個欄位... |
: |
: 以下是當中一段程式
: 因為寫入excel的方法我第一次用
: 所以不對的地方請指正
: 還有就是..excel檔開起來
: $row["department"] $row["education"] $row["class"] 是亂碼且只顯示一列@@
: //------------------------------------
: $sql = "SELECT * FROM xxx ";
: $result = mysql_query($sql, $link);
: $row = mysql_fetch_array($result);
: $string="\tnumber";
: for( $i=1;$i<=mysql_num_rows($result);$i++ )
: {$stringg="\n ".$row["department"]." ".$row["education"]."
: ".$row["class"]." \n ";
: $row = mysql_fetch_array($result);
: }
: $fp = fopen("texcel.xls", "w");
: fputs($fp,$string.$stringg);
: fclose($fp);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.117.204.78
推 alpe:在win下分行應該是 /r/n 09/04 09:06
推 cleanwind:excel內的分行, \r 就可以了... 09/04 09:36