Search code examples
c#htmlasp.netopenxml

Null exception while converting html


HtmlConverter converter = new HtmlConverter(mainPart);

var paragraphs = converter.Parse(textData);

While parsing, it shows null exception while I pass the below html as textData:

<div id='divgrid' style='float: left; width: 100%'>
<hr style='width: 100%; border: 5px solid;' />
<br />
<table id='tbl1' style='width: 100%; border:1px solid black; border-collapse:collapse;'>
    <tr>
        <td colspan='2' style='border:1px solid black; background-color: black; color: white; text-align: center'>
            <h3>INFORMATION FROM CURRENT</h3>
        </td>
    </tr>
    <tr>
        <td style='border:1px solid black;'><b>Goal #: 1</b>
        </td>
        <td style='border:1px solid black;'><b>Specific Focus:</b> STAIRS</td>
    </tr>
</table>
<br /><b>Current Level:</b> data here
<hr style='width:100%; border:.5px solid grey;' />
<br />2.0
<br />
<hr style='width:100%; border: 1px solid black;' /><b>Measurable Goal:</b> data here
<br />How will we know?
<hr style='width:100%; border:.5px solid grey;' />
<br />2.0
<br />
<hr style='width:100%; border: 1px solid black;' /><b>Benchmark/Objectives:</b> What they need to do to complete this goal?
<hr style='width:100%; border:.5px solid grey;' />
<br />2.0
<br />
<hr style='width:100%; border: 1px solid black;' />
<br />
</td>
</tr>
</table>
</div>

Its working when I pass some other sample html data. So what's the problem with my current html?


Solution

  • Your HTML is not valid, you have extra closing brackets at the end of your file:

    </td></tr></table>