【发布时间】:2017-02-07 17:22:29
【问题描述】:
我正在使用 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 上提出的问题不同,我的编码方案也不同..)
【问题讨论】:
-
图片在哪里,你想在excel中应用css,真的
different then the questions been asked on stackoverflow。 -
添加了图片,因为我正在使用
PHPExcel_IOFactory::createWriter对象,并且我正在应用以前提出的问题的代码,但它对我不起作用(我的运气不好)
标签: php laravel-5 phpexcel phpexcelreader