I want to make the group of DIV elements in the attached HTML file appear as a table in a Word document created by Aspose.Words for .NET. However, Aspose.Words never creates a table format for these DIVs: it always breaks every DIV in a new row in the Word file.
If you drag and drop the HTML file in any browser (IE, FF, Chrome, etc.) you’ll see that all browsers will properly create the table layout (rows and cells) for the group of DIVs.
To replicate the issue, just copy and paste the piece of C# code below in the Main() method of a console project, put the attached “Test.html” file in the C:\ directory and make sure you’re loading the Aspose.Words.dll 10.6.0.0 assembly (you can get the issue with the newest component version):
License license = new License();
LoadOptions lo = new LoadOptions();
lo.LoadFormat = LoadFormat.Html;
SaveOptions soOptions = SaveOptions.CreateSaveOptions(SaveFormat.Docx);
Document doc = new Document(@“C:\Test.txt”, lo);
Another interesting thing: I see that the “RW1” CSS style is never applied to the internal DIVs as well. It only works if I explictly assign class=“RW1” for each inner DIV like you can see for the RW2 CSS style in the first DIV (the one loading the image). Duhh… How could I easily apply the CSS style across all of the internal DIVs in an easy, simple way?
Does anybody know what I’m missing here?
Thanks for your request. I am afraid it will not be possible to achieve this using Aspose.Words. Aspose.Words interprets DIVs as paragraphs that is why you see each div as a separate line of text in the output document. By the way, MS Word does the same.
The reason is because, in MS Word documents there is no similar concept as DIV, so DIVs are interpreted as paragraphs.
In your case, I can only suggest you use table in your HTML instead of DIVs.