PHPExcel_Reader_HTML
を使用していますが、HTML
を渡してExcelファイルを生成していますが、 'HTML'テーブルのようにExcelセルの色を強調表示しないという問題があります。私はLaravel5ExcelExcel_Reader_HTMLでExcelセルを書式設定する方法
<?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のセルを強調表示します。 – Drone
イメージは、 'PHPExcel_IOFactory :: createWriter'オブジェクトを使用していて、以前に質問されたコードを適用していたので追加されましたが、私にとってはうまくいきませんでした(私の不運) –
見てください:http://stackoverflow.com/questions/36745376/how-to-apply-css-on-html-to-excel-export – Drone