Reputation: 260
I'm using PHPExcel 1.8
in my application. What I want to do is to download my file generated.html
and this is the content.
<!DOCTYPE html>
<html>
<head>
<title>PHPExcel</title>
<style>
table, td, th {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<td bgcolor="#FF0000">Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Jack</td>
<td>Paper</td>
<td>123</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td bgcolor="#FF0000">John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
For now, I have dl.php
to perform the download but example.xls
doesn't have the styles and colors applied to it.
<?php
require_once 'PHPExcel-1.8/Classes/PHPExcel.php';
$objReader = new PHPExcel_Reader_HTML();
$objPHPExcel = @$objReader->load($file_path.'generated.html');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="example.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
What modifications should I do?
Upvotes: 2
Views: 5740
Reputation: 1416
I think, PHPexcel is not supporting the css and styles. Here is a example code for doing it directly.
This is my excel.php
file, gives download of table generated inside this file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<title>TESTING</title>
</head>
<style type="text/css">
body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
margin:0px;
padding:0px;
}
</style>
<html>
<body>
<?php
$table = '<table border="0" cellpadding="0" cellspacing="0"><tr><td>';
$table .= '<tr><td rowspan="2" style="background-color:#000099;color:#FFFFFF;">test</td>';
$table .= '<td colspan="2" style="background-color:#FFFF33">TEst</td>';
$table .= '<td colspan="2" style="background-color:#FFFF33">teST</td>';
$table .= '<td rowspan="2" style="background-color:#000099;">Test<br>test</td>';
$table .= '</tr><tr><td style="background-color:#FFFCCC">Test</td>';
$table .= '<td style="background-color:#FFFCCC">test</td>';
$table .= '<td style="background-color:#FFFCCC">test</td>';
$table .= '<td style="background-color:#FFFCCC">test</td>';
$table .= '</tr><tr></td></tr></table>';
header("Content-type: application/x-msdownload");
header('Content-Disposition: attachment; filename="filename.xls"');
header("Pragma: no-cache");
header("Expires: 0");
echo $table;
?>
</body>
</html>
Upvotes: 1