我正在使用PHPExcel_Reader_HTML
并将其传递给我HTML
以生成 excel 文件,但问题是它没有像“HTML”表中那样突出显示 excel 单元格颜色(参见图片打击),我使用的是 Laravel5
<?php
$content = $title;
$content .= '<table border="1">';
$content .= '<tr>';
foreach($fields as $f )
{
if($f['download'] =='1') $content .= '<th style="background:#f9f9f9;">'. $f['label'] . '</th>';
}
$content .= '</tr>';
foreach ($rows as $row)
{
$content .= '<tr>';
foreach($fields as $f )
{
if($f['download'] =='1'):
$conn = (isset($f['conn']) ? $f['conn'] : array() );
$content .= '<td> '. htmlentities(AjaxHelpers::gridFormater($row->$f['field'],$row,$f['attribute'],$conn)) . '</td>';
endif;
}
$content .= '</tr>';
}
$content .= '</table>';
$path = "../storage/app/".time().".html";
file_put_contents($path, $content);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($path);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
// Delete temporary file
unlink($path);
// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');
// It will be called file.xls
header('Content-disposition: attachment; filename="'.$title.' '.date("d/m/Y").'.xlsx"');
// Write file to the browser
$objWriter->save('php://output');
注意:(我的问题与在stackoverflow上提出的问题不同,我的编码方案也不同......)