HtmlPhpExcel
A php library based on PHPExcel to convert html tables to excel files.
Install / Use
/learn @Ticketpark/HtmlPhpExcelREADME
HtmlPhpExcel
This is a php library based on FastExcelWriter, simplifying converting html tables to excel files. It allows styling right within the html template with specific attributes.
Installation
Add HtmlPhpExcel to your composer.json:
composer require ticketpark/htmlphpexcel
Simple example
<?php
require_once('vendor/autoload.php');
$html = '<table><tr><th>Column A</th><th>Column B</th></tr><tr><td>Value A</td><td>Value B</td></tr></table>';
$htmlPhpExcel = new \Ticketpark\HtmlPhpExcel\HtmlPhpExcel($html);
$htmlPhpExcel->process()->save('myFile.xlsx');
For a more complex example see example directory.
Styling
Styles are set with an html attribute _excel-styles. The attribute expects the content to be in json format.
Example:
<table>
<tr _excel-styles='{"height": 50}'>
<td _excel-styles='{"font-size": 16, "font-color": "#FF0000", "width": 200}'>
Cell value
</td>
</tr>
</table>
You can use any style supported by fast-excel-writer, of which the most common are:
- border-color
- border-style
- fill-color
- fill-pattern
- font-color
- font-size
- format
- format-text-wrap
- height
- hyperlink
- text-align
- text-color
- text-rotation
- text-wrap
- vertical-align
- width
More information (though unfortunately limited) is available in the docs of FastExcelWriter.
Adding links to cells
Links are treated like styles and added with the hyperlink key:
Example:
<table>
<tr>
<td _excel-styles='{"hyperlink": "http://www.google.com"}'>
Cell value
</td>
</tr>
</table>
Adding comments to cells
To add comments, use the _excel-comment attribute.
Example:
<table>
<tr >
<td _excel-comment="This is a comment.">
Cell value
</td>
</tr>
</table>
History
- v2.x of this library is based on
FastExcelWriter - v1.x of this library was based on
PhpSpreadsheet - v0.x of this library was based on
PhpExcel
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
