使用Php7和Mysql无法导出到Excel

我需要将MySQL数据导入到excel文件中。 我正在使用php7。 我写了一个代码,但问题是所有的数据打印在Excel文件中的单个列。 任何人都可以帮助我的代码来更改Excel文件中的行和列。 这是我的代码:`

$connect= mysqli_connect("localhost", "root", "", "crmweb"); $output='';$output2=''; $sql="SELECT name,hname,cno FROM hencus "; $result= mysqli_query($connect, $sql); if(mysqli_num_rows($result)>0) { $output.=' <table class="table" border="1> <tr> <th>Name</th> <th>House</th> <th>Contact</th> </tr>'; while($row= mysqli_fetch_array($result)) { $output.=' <tr> <td>'.$row['name'].'</td> <td>'.$row['hname'].'</td> <td>'.$row['cno'].'</td> </tr>'; } $output.='</table>'; header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=download.xls"); echo $output; // echo $output2; } ?> ` 

尝试使用这个:

 header ("Content-Type: application/vnd.ms-excel"); header ("Content-Disposition: inline; filename=download.xls"); 

代替

 header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=download.xls"); 

在这里你可以find一个很好的教程。