12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace tools;
- class Report
- {
-
- private $fileName = 'user';
-
- private $_data = "";
-
- public function __construct($fileName = '')
- {
- $this->setFileName($fileName);
- }
-
- public function setFileName($fileName)
- {
- $this->fileName = $fileName;
- }
-
- public function setTitle($data = array())
- {
- array_walk($data,function(&$val,$key)
- {
- $val = "<th style='text-align:center;background-color:green;color:#fff;font-size:12px;vnd.ms-excel.numberformat:@'>".$val."</th>";
- });
- $this->_data .= "<tr>".join($data)."</tr>";
- }
-
- public function setData($data = array())
- {
- array_walk($data,function(&$val,$key)
- {
- $val = "<td style='text-align:center;font-size:12px;vnd.ms-excel.numberformat:@'>".$val."</td>";
- });
- $this->_data .= "<tr>".join($data)."</tr>";
- }
-
- public function toDownload($data = '')
- {
-
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename='.$this->fileName.'_'.date('Y-m-d').'.xls');
- header('Cache-Control: max-age=0');
-
- header('Cache-Control: max-age=1');
-
- header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
- header ('Cache-Control: cache, must-revalidate');
- header ('Pragma: public');
- $result = $data ? $data : "<table border='1'>".$this->_data."</table>";
- echo <<< OEF
- <html>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <body>
- {$result}
- </body>
- </html>
- OEF;
- }
- }
|