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

Free Support Forum - aspose.com

Unable to generate div boxes in html to word conversion


I am using the below code to convert a html to docx document, word is not respecting the height and width of the div boxes. How can i export div boxes with their respective dimensions.

input html
image.png (184 Bytes)

output word
image.png (11.9 KB)

code i used:

Aspose.Words.License lic = new Aspose.Words.License();
            string inputHtml = @"<html>
                                    <style type='text/css'>.box{width:50px;height:50px}.red{background:#f00}.green{background:#0f0}.blue{background:#00f}</style>
                                    <div class='box red'></div>
                                    <div class='box green'> </div>
                                    <div class='box blue'> </div>

            var destinationDoc = new Document();
            var builder = new DocumentBuilder(destinationDoc);
            destinationDoc.Save("output.docx", SaveFormat.Docx);




Thanks for your inquiry. Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Hi @tahir.manzoor,

here is the file. output divs.zip (17.0 KB)



Thanks for sharing the detail. Please note that the HTML and Word documents are different file formats. The DIV tag as shown below is imported as Paragraph node into Aspose.Words’ DOM. However, MS Word does not allow to set paragaphs’s width and height as shared in .box style.

<div class=‘box red’> & nbsp; </div>

If you add & nbsp; in DIV tag, the output will be as shown in following screenshot.

In your shared expected output document, there are nested tables in row’s cells. For your case, we have logged this feature request as WORDSNET-18114 in our issue tracking system. We will check the possibility of the implementation of this feature and let you know once there is an update available on it. We apologize for your inconvenience.