导出时在php中扩展excel列宽的代码

导出时在php中扩展excel列宽的代码,php,export-to-excel,Php,Export To Excel,我是PHP新手,尝试将一些DB数据导出到Excel文件,如下所示。但在输出中,我希望自动调整列宽以查看整个内容。请参阅我用于导出数据的代码。我没有使用任何第三方库进行导出 <?php require_once("db.php"); $contents="email,time_in,v_id,time_out\n"; $user_query = mysql_query('SELECT * FROM table'); while($row = mysql_fe

我是PHP新手,尝试将一些DB数据导出到Excel文件,如下所示。但在输出中,我希望自动调整列宽以查看整个内容。请参阅我用于导出数据的代码。我没有使用任何第三方库进行导出

<?php    
require_once("db.php");   

$contents="email,time_in,v_id,time_out\n";   

$user_query = mysql_query('SELECT  * FROM table');   

while($row = mysql_fetch_array($user_query))
{
$contents.=$row['email'].",";
$contents.=$row['time_in'].",";

$contents.=$row['v_id'].",";
$contents.=$row['time_out']."\n";
}

// remove html and php tags etc.
$contents = strip_tags($contents); 

//header to make force download the file

header("Content-Disposition: attachment; filename=Report".date('d-m-Y').".xls");
print $contents;


?>


有没有办法格式化输出?

您正在输出一个CSV文件,并将其扩展名设置为错误的“XLS”。有了CSV,就没有办法按你的要求去做。Excel可以做到这一点,您需要找到一种创建Excel文件的方法……正如前面提到的,我是PHP新手。那么,有人可以帮助将数据从PHP导出到Excel吗