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

Free Support Forum - aspose.com

Word export to html produces table with > 100% width

I have a word doc with a table that is exported to html with a width greater than 100%.

widetable.zip (12.0 KB)

The table tag is

<table cellspacing="0" cellpadding="0" style="width:100.36%; border-collapse:collapse">

in the output from Aspose.Words

MS Word export to html produces:

<table class=MsoNormalTable border=1 cellspacing=0 cellpadding=0 width=“100%”
style=‘width:100.36%;border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
mso-yfti-tbllook:480;mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:
.5pt solid windowtext;mso-border-insidev:.5pt solid windowtext’>

Note that the style width is the same 100.36% but there as a class of width=“100%” too!

Is there an Aspose.Words bug here? I am not sure.

I am using Aspose.Words for java 18.6

@steve1elsevier

We have tested the scenario using the latest version of Aspose.Words for Java 19.3 and have not found the shared issue. So, please use Aspose.Words for Java 19.3.

Hi Tahir,

I have tried 19.3 but see the same behaviour as with 18.3. Could you post the code you are using? Perhaps I am missing a setting.

Could you show the table tag and attributes your code produces?

thanks
Steve

@steve1elsevier

We used the following code example to convert DOCX to HTML. We have attached the output HTML with this post for your kind reference. output.zip (1.2 KB)

Document doc = new Document(MyDir + "widetable.docx");
HtmlSaveOptions options = new HtmlSaveOptions();
options.setPrettyFormat(true);
doc.save(MyDir + "output.html", options);

I see in the output.html in the attached zip the width on the table tag is still 100.36%. I would want it to be 100% or less.

<table cellspacing=“0” cellpadding=“0” style=“width:100.36%; border:0.75pt solid #000000; border-collapse:collapse”>

@steve1elsevier

The table’s width is 100.3% in your input document. You can set the table’s width as shown below. Hope this helps you.

Document doc = new Document(MyDir + "widetable.docx");
HtmlSaveOptions options = new HtmlSaveOptions();
options.setPrettyFormat(true);

for(Table table : (Iterable<Table>) doc.getChildNodes(NodeType.TABLE, true))
{
    table.setPreferredWidth(PreferredWidth.fromPercent(100));
}
doc.save(MyDir + "output.html", options);

Yes, I have implemented a similar work around. I just wanted to check if this was a bug in Aspose.words or not. I take it that it is not.
thanks

@steve1elsevier

Thanks for your feedback. Yes, it is not a bug.