Forum


Replies: 3   Views: 267
Convert html table to excel
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpxlsx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpxlsx version and check the Documentation available.

Posted by jeroen8087  · 09-02-2023 - 09:39

It would be nice to convert a HTML table to Excel.

In this example I use the non-existing function addHtmlTable:

$table = <<<HTML
<table>
    <tr>
        <td>Some content here</td>
        <td>More content here</td>
    </tr>
    <tr>
        <td>Some content for the next row</td>
        <td>More content!</td>
    </tr>
</table>    
HTML;

$xlsx = new CreateXlsx();

// This will add the table to cell A1. The table has two rows and two columns, so the table will be put in cell range A1:B2.
$xlsx->addHtmlTable($table, 'A1');

// This will add the table to cell C5. The table has two rows and two columns, so the table will be put in cell range C5:D6.
$xlsx->addHtmlTable($table, 'C5');

The contents of each <td> can be added by using addHtml internally, while putting all nodes in the td in one cell. See my other forum topic.