sergey-tihon / Clippit

Fresh PowerTools for OpenXml
https://sergey-tihon.github.io/Clippit/
MIT License
47 stars 18 forks source link

rowspan causing error Object reference not set to an instance of an object. at Clippit.HtmlToWml.HtmlToWmlConverterCore.AddPseudoCells(XElement html) #34

Closed nmase88 closed 3 years ago

nmase88 commented 3 years ago

Trying to convert a html table to wml and it is throwing errors I believe due to the rowspan, when I remove the rowspan it works fine. Below is the html for the table (I've replaced the table data with test data as it's client sensitive)


    <thead>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" colspan=\"5\" width=\"690\">
            <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; background: #1F497D; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"background: #1F497D; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"background: #1F497D; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"background: #1F497D; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"background: #1F497D; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"2\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"2\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"2\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"2\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"7\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"2\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"3\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"3\" width=\"112\">
                <p>test</p>
                <p>test</p>
                <p>test</p>
                <p>test</p>
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"3\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"3\" width=\"112\">
                <p>test</p>
                <p>test</p>
                <p>test</p>
                <p>test</p>
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; background: white; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" rowspan=\"3\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; background: white; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; background: white; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
        <tr>
            <td style=\"border: solid windowtext 1.0pt; padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"93\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"295\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"78\">
                <p>test</p>
            </td>
            <td style=\"padding: 0cm 1.4pt 0cm 1.4pt;\" width=\"112\">
                <p>test</p>
            </td>
        </tr>
    </thead>
</table>```
nmase88 commented 3 years ago

On further testing, the problem seems to occur if you have 2 row spans overlapping. The row span 7 has some rows within it that have additional row span on another column for 2 rows. If I remove either the 2 row span or the 7 row span it works fine.

sergey-tihon commented 3 years ago

@nmase88 thank you for reporting this. I do not personally use this part of the library and cannot offer quick fix to you. But if you are interested to take a look at implementation and create PR with test that reproduce the bug and fix for this test I'll be happy to merge it and release new version on NuGet.

You may also want to take a look at the list of open PRs for Open-Xml-PowerTools repo. There already may be one with the fix that you need.

nmase88 commented 3 years ago

I've just submitted a pull request with a fix, apologies if I've done something incorrect, this is the first time I've done a pull request on github!

sergey-tihon commented 3 years ago

Fixed in v1.7.1