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 admin  · 09-02-2023 - 10:02

Hello,

The next stable release of phpxlsx will include support to transform HTML tables:

- HTML to XLSX supports transforming tables.

For example:

$html = '
<style>
    .cstable2 {
        data-style: TableStyleMedium2;
    }
    tr.rowstyles {
        font-family: Arial;
        font-weight: bold;
        text-decoration: underline;
        color: #2CA87A;
    }
</style>
<table class="cstable2">
    <tbody>
        <tr>
            <td style="background-color: yellow;">Cell 1 1</td>
            <td>Cell 1 2</td>
        </tr>
        <tr>
            <td>Cell 2 1</td>
            <td></td>
        </tr>
        <tr class="rowstyles">
            <td><em>Cell</em> 3 1</td>
            <td><em>Cell</em> 3 2</td>
        </tr>
    </tbody>
</table>
<p>Paragraph after table.</p>
';
$xlsx->addHtml($html, 'B3');

// table with th tags, that are added as table headers
$html = '
<style>
    tr.rowstyles {
        font-family: Arial;
        font-weight: bold;
        text-decoration: underline;
        color: #2CA87A;
    }
</style>
<table>
    <tbody>
        <tr>
            <th>Col A</th>
            <th>Col B</th>
        </tr>
        <tr>
            <td>Cell 2 1</td>
            <td>Cell 2 2</td>
        </tr>
        <tr class="rowstyles">
            <td><em>Cell</em> 3 1</td>
            <td><em>Cell</em> 3 2</td>
        </tr>
    </tbody>
</table>
';
$xlsx->addHtml($html, 'G3');

Regards.