我找到了一个代码,帮助我获得了我的数据库的Excel表格,除了“日期”列之外,它可以很好地处理所有列,它只是给了我#######。
这个“日期”列是sqlite中的DATETIME类型(它默认输入当前日期(yyyy-mm-dd)),数据来自HTML的输入类型日期。
这是我的PHP代码:
<?php
namespace Chirp;
include "./_pdo.php";
$db_file = "./test.sqlite";
PDO_Connect("sqlite:$db_file");
$data = PDO_FetchAll("SELECT * FROM test");
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// file name for download
$filename = "website_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
foreach($data as $row) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\n";
$flag = true;
}
array_walk($row, __NAMESPACE__ . '\cleanData');
echo implode("\t", array_values($row)) . "\n";
}
exit;
?>
答案 0 :(得分:1)
你会踢自己......
在Excel中使日期列更宽; - )