2013-10-19 67 views
0

我試圖轉換PHP頁面中名爲「Update2」的表的內容。將PHP輸出導出到Microsoft Excel中

這是轉換器:

header("Content-type: application"); 
header("Content-Disposition: attachment; filename=myfilename.xls"); 

,這是代碼部分:

<?php 
$output_sql="select * from update2 where update_com_ag=1 order by update_fullname ASC"; 
$output_query=mysql_query($output_sql,$con); 
while($output=mysql_fetch_array($output_query)){?> 
<tr> 
    <td valign="top"><?php echo strtoupper($output['telephone_number']);?></td> 
</tr> 
<?php }?> 

然而,讓我們說,電話號碼是1601000021056,在Excel文件中的輸出將是1.601E + 12。有沒有解決這個問題的方法?我嘗試了幾種方法,但仍然無法正常工作。

謝謝你們!

+0

你爲什麼不把電話號碼的區號與空格隔開? – reporter

回答

0

轉到excel,突出顯示電話號碼列。右鍵單擊並轉到格式單元格。轉到號碼標籤。然後在左側,您可以選擇不同的格式。像0位小數的數字可能會這樣做。

0

由於空間限制,Excel程序以該格式顯示。增加列寬,它會正確顯示數字。

0

在excel中,如果用一個單引號加上一個值,它會將該值視爲字符串,即使它是一個數字。不知道它是否適用於您的導出方法,但值得一試。

<tr> 
    <td valign="top">'<?php echo strtoupper($output['telephone_number']);?></td> 
</tr>