我想用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'的代码 –