3
我要出口(強制下載)HTML(與CSS),以EXCEL表,現在我使用的PHPExcel庫執行此,它生成excel文件但刪除CSS(使用HTML標籤內聯),任何人都可以指導我,如何保持在Excel表中的CSS。PHPExcel:HTML到Excel,寫刪除Excel中的CSS文件
我使用這個代碼,但我也想保持CSS和力量下載
//html
$html = "<table>
<thead> <tr> <td colspan='2'> <h1> Main Heading </h1> <td> </tr> </thead>
<tbody>
<tr>
<th style='background:#ccc; color:red; font-size:15px'> Name <th>
<th style='background:#ccc; color:red; font-size:15px'> Class <th>
</tr>
<tr>
<td style='background:#fff; color:green; font-size:13px'> Jhon <th>
<td style='background:#fff; color:gree; font-size:13px'> 9th <th>
</tr>
</tbody>
</table>";
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $html);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('excelfile.xlsx');
// Delete temporary file
unlink($tmpfile);
嗨,@馬克您這句話的開發者文檔中記載,「除非你重寫PHPExcel的HTML閱讀器來處理樣式;「你可以給我鏈接或代碼,它處理所有的HTML與CSS等? – Qazi 2014-12-10 03:49:18
開源之美:它是HTML閱讀器文件....它被稱爲'HTML.php',你可以在'Classes/PHPExcel/Reader'文件夾中找到它.....它不處理任何CSS儘管如此,只有基本的HTML元素,表格以及表格單元 – 2014-12-10 07:57:57
的rowspan/colspan屬性等等,我必須爲CSS編寫新的代碼?對 ? 如果是的話,你能給我一個簡單的例子,這有助於我從HTML中讀取CSS,然後把它放在Excel中? – Qazi 2014-12-10 08:45:44