I am using PHPExcel_Reader_HTML
and passing it my HTML
to generate excel file, but the problem is that it does not highlight the excel cell color as in the 'HTML' table (see image blow), I am using 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');
Note: ( My question is different then the questions been asked on stackoverflow, my coding scenario is different then all..)
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2do5hwD
via IFTTT
Aucun commentaire:
Enregistrer un commentaire