我想用MySQL數據庫中的PHP腳本生成XLS文件。這裏最大的問題是,當我打開新的導出的.xls文件時,我看到值正確(即格式正確),但字段顏色變爲白色。但是,我需要顏色保持不變,如在Excel中默認。使用PHP腳本從MySQL數據庫創建XLS文件
以下是我用於從我的數據庫中提取數據的PHP腳本。
<?php
include 'connect.php';
$result = mysql_query('SELECT * FROM projects2');
?>
<center><h1>Lista valorilor din tabela</h1>
<h2><a href="lec_datepm.php?exporta_lista_clienti=1" title="Exporta lista clienti in Excell" target="_blank">Exporta lista Clienti</a></h2></center>
<?php
include_once 'tabel_clientipm.php';
?>
用於生成XLS文件中的PHP文件是:
<?php
include 'connect.php';
$result = mysql_query('SELECT * FROM projects2');
if (isset($_GET['exporta_lista_clienti'])) {
$filename = 'raportnou.xls';
header("Content-type: application/ms-excel");
header("Content-Disposition: attachment; filename=$filename");
include_once 'tabel_clientipm.php';
exit();
}
?>
我加了tabel_clientipm.php:
<center>
<table border="1">
<tr>
<th>surname</th>
<th>name</th>
<th>age</th>
</tr>
<?php
while ($client = mysql_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $client['surname'];?></td>
<td><?php echo $client['name'];?></td>
<td><?php echo $client['age'];?></td>
</tr>
<?php
}
?>
</table>
</center>
如果我可能會問,你的表代碼在哪裏 – Satya
顯示'tabel_clientipm.php'的代碼 –