We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML Table Position is not working with Word Conversion

Hi, We are trying to create word document from HTML . The HTML document has tables with inline styles specified to position them accordingly. However the css property ‘position’ is seems to be not entertained and the table are resulted one after the other. We would like to know if this possible with aspose.word licensed version 21.7.0. Attached zip file with sample input, converted output & expected output.
PS: To quickly analyze the HTML to Word conversion we have used aspose free online conversion from here
HTML_Table_Word.zip (16.5 KB)

@ksheriff This is an expected behavior. If you open your HTML in MS Word you will see exactly the same result.
I suspect, in your case you need to have header and footer in MS Word document. If so, you can use Aspose.Words roundtrip information in HTML, for example see the following HTML:

<html>
<body>
    <div>
        <div style="-aw-headerfooter-type:header-primary; clear:both">
            <p>This is primary header</p>
        </div>
        <p>This is the main body.</p>
        <div style="-aw-headerfooter-type:footer-primary; clear:both">
            <p>This is primary footer</p>
        </div>
    </div>
</body>
</html>

As you can see two divs are marked with special -aw-headerfooter-type style, which is recognized by Aspose.Words and content of these divs will be imported as header and footer of the document. See the attached document. out.docx (7.8 KB)

@alexey.noskov thanks for quick turnaround with examples for header and footer. Sorry if i have phrased my question in way that we would like have headers and footers but its not the requirement we are trying to achieve.
The intention of this clarification however i position my tables in html it should also reflect back in word i.e(if i would like to position my table/div leaving space from top 50px and the next table/div with margin top 10px this will give me two tables with proper spacing which i want to achieve in a webpage JS fiddle the same is what we want when its converted to a word document. how can we achieve this with HTML to word conversion?

<style>

    #products {

        border-collapse: collapse;

        width: 100%;

        position: relative;

        top: 50px;

    }

    #products th,

    #products td {

        border: 1px solid #0000FF;

        background-color: #C0C0C0;

        padding: 3px 2px 7px 5px;

    }

    #products th {

        font-size: 20px;

        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;

        color: #0000FF;

        padding-top: 4px;

        padding-bottom: 5px;

        background-color: green;

    }

    #products1 {

        border-collapse: collapse;

        width: 100%;

        position: relative;

        margin-top: 100px;

    }

    #products1 th,

    #products1 td {

        border: 1px solid #0000FF;

        background-color: #C0C0C0;

        padding: 3px 2px 7px 5px;

    }

    #products1 th {

        font-size: 20px;

        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;

        color: #0000FF;

        padding-top: 4px;

        padding-bottom: 5px;

        background-color: green;

    }

</style>
<table id="products">

    <tr>

        <th><span></th>

        <th>Free Version</th>

        <th>Lite Version</th>

        <th>Full Version</th>

    </tr>

    <tr>

        <td>Advertising</td>

        <td id="td">X</td>

        <td><span></td>

        <td><span></td>

    </tr>

    <tr class="alt">

        <td>Catering Software</td>

        <td><span></td>

        <td id="td">X</td>

        <td id="td">X</td>

    </tr>

</table>

<table id="products1">

    <tr>

        <th><span></th>

        <th>Free Version</th>

        <th>Lite Version</th>

        <th>Full Version</th>

    </tr>

    <tr>

        <td>Advertising</td>

        <td id="td">X</td>

        <td><span></td>

        <td><span></td>

    </tr>

    <tr class="alt">

        <td>Catering Software</td>

        <td><span></td>

        <td id="td">X</td>

        <td id="td">X</td>

    </tr>

</table>

above sample HTML shows how we wanted to structure the elements. Thanks in advance.

@ksheriff Unfortunately, there is no way to convert HTML to MS Word document preserving exactly the same layout. While importing HTML into the Document Object Model. Aspose.Words mimics MS Word behavior. As I mentioned earlier in your case MS Word does exactly the same as Aspose.Words does - makes the tables inline.