【发布时间】:2011-10-01 00:20:38
【问题描述】:
我需要一种通过纯 PHP 编写具有格式的 excel 文件的方法。 警告:请,此 Q 不是关于库、插件等的 - 请勿打扰。 我用谷歌搜索了很多并没有找到答案,但是在 StackOverflow 上的一些文章中,有人提到了 HTML/CSS 格式方式 HTML format solutions that didn't work 我已经尝试过这样做,但是在保存的列中填充了标签并且没有任何反应的文件中。 可能有一些专业人士可以帮助我通过 PHP、HTML、CSS 之类的纯代码编写 Excel。
再举一个例子,我已经使用过这样的概念,但没有帮助:
// headers for excel
$headers .= "<div style='font:bold 14px Times;'>Журнал остатков и инкассаций</div>\n";
$headers .= "Начало периода\t ".date('d.m.Y')."0:00 \n";
$headers .= "Начало периода\t ".date('d.m.Y')."23:59 \n\n";
$headers .= "Терминал\t";
$headers .= "Место расположения\t";
$headers .= "Дата\t";
$headers .= "Время\t";
$headers .= "Сумма инкассации\t";
$headers .= "Банкноты\t";
// excel content with overloaded terminals
if (mssql_num_rows($resCollection)>0) {
while ($rowCollection = mssql_fetch_object($resCollection)) {
$data .= $rowCollection->Name."\t".$rowCollection->Address."\t"
.$rowCollection->TerminalNotes."\t".$rowCollection->TerminalAmount
."\t".$rowCollection->DayAmountAll."\t"
.$rowCollection->LastPaymentTime."\n";
}
}
$fileName = 'collection'.date('d_m_Y_H_i_s').'.xls';
header("Content-type: application/vnd.ms-excel");// application/excel had also been used
header("Content-Disposition: attachment; filename=$fileName");
echo iconv('utf-8', 'cp1251', "$headers\n$data");
我不仅使用了 div 和表格,但它没有用。
【问题讨论】: