gpt4 book ai didi

php - EXCEL:如何在excel中添加背景标题颜色;使用 PHP 导出?

转载 作者:行者123 更新时间:2023-11-27 23:46:34 25 4
gpt4 key购买 nike

我正在使用 PHP 生成 Excel 工作表。我想为标题添加颜色。

我试过这样的:

$filename = "Stack_Rank_ReportV2_(".$fromdate."_".$todate.").xls";
header("Pragma: no-cache");
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Expires: 0");
echo "<table border='1'>
<tr>
<td style='background-color:#f00;'>header</td>
</tr>
</table>";
$head_row = "EmployeeId"."\t";
$head_row .= "EmployeeName"."\t";
$head_row .= "Actual Designation"."\t";
$head_row .= "Cluster"."\t";

echo $head_row;

但它从整个 Excel 工作表中弄乱了。不起作用。在网上也找不到任何东西。请帮帮我。

最佳答案

试试这个:

你必须只添加属性 bgcolor 然后用你自己的方式玩。

<?php

$filename = "Stack_Rank_ReportV.xls";
header("Pragma: no-cache");
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Expires: 0");
echo "<table border='1'>
<tr bgcolor='red'>
<td>header</td>
</tr>
</table>";
$head_row = "EmployeeId"."\t";
$head_row .= "EmployeeName"."\t";
$head_row .= "Actual Designation"."\t";
$head_row .= "Cluster"."\t";

echo $head_row;

enter image description here

关于php - EXCEL:如何在excel中添加背景标题颜色;使用 PHP 导出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56772173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com