我是PHP新手并尝试将一些数据库数据导出到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;
?>
有没有办法格式化输出?