我想打印爲excel作爲csv。這是我迄今爲止的答案。打印語法輸出爲csv
<?php
$dbh = dbh_get();
header('Content-type: application/csv');
header("Content-Disposition: inline; filename=file.csv");
readfile('file.csv');
$sql = 'select t.*
from old t
where t.entered >= ? and t.entered < ?
and t.status <> \'cancel\'
and t.ccy = \'USD\'
order by id desc';
$stmt = $dbh->prepare($sql);
$v = array();
$v[] = $date->format(DateTime::ISO8601);
$v[] = $dateEnd->format(DateTime::ISO8601);
$numRows = 0;
$stmt->execute($v);
while (true) {
$r = $stmt->fetch();
if (is_bool($r)) break;
$numRows++;
$bop = $r['comments'];
$bop1 = strtok($bop, " "); //remove all but first word
$bop2 = substr(strstr($bop," "), 1); //remove first word and space
$headers = ['PLACE','YEAR','MONTH','COY','NT','TOPS','BOP','COUNTRY','REC','SENT','DESC'];
$fields = ["Old",2015,$textDate,$r['cols'],$r['nt'],$bop1,"NTR",$r['name'],$r['first_name'],$r['last_name'],$bop2];
$fp = fopen('file.csv', 'w');
fputcsv($fp, $headers);
fputcsv($fp, $fields);
fclose($fp);
}
dbh_free($dbh);
仍然不能使用這個我得到一行代碼打印到屏幕上,沒有下載。我需要的是下載csv文件,以便我可以用excel打開它。
如何撤消所有編輯並返回到原始問題,我沿着錯誤的軌道 – Kilisi