Free Support Forum -

HTML table widths and Word


I' trying out Aspose.word and would like to know how I can make an html table (720pixels) into a word document so that the table columns a) all fit on a A page and b) widths are sized in the same proportion as on the web. Now I get a very cluttered doc document that noone can read.

An example of the html I try to use:

  Members Stockholm


Yes, it is true - the results of HTML import in Aspose.Words look different from what you see in the browser. The explanation is that we are trying to mimic the behavior of MS Word and not browser during HTML import. If you open your HTML sample in MS Word you will see exactly the same result as produced by Aspose.Words. I don't know why MS Word renders HTML that way but we are following its wake for the time being.

The workaround is simple - you can transform your HTML to look like the following:

  Members Stockholm

and you will get correct import in MS Word as well as in Aspose.Words. That transform can be done using regular expression replace for example.

Hope that answers your question. Please be sure to let me know if there is any other information I can provide and I will be more than glad to.

Best regards,

Better but still won't do it properly. The table runs over the right side of the page and the Second table is a little bit indented compared to the first. How does the width=300 relate to the page size and borders? This is the html code produced now:

A benchmarking project
Answer date 15.6.2006 13:00:00 Form number 6 

  Members London

  Number of employees 250

  Personnel cost of turn over % 20

  Turn over miljon euros 60

  International sales miljon euros 6

  New equipment sales of turnover % 5

  Maintenance income of turn over % 8

Form number 6

width=300 means 300 pixels. Pixel size is related to screen resolution. At typical resolution of 96 dpi there are 96 pixels per inch. Taking into account that there are 72 points in 1 inch you can calculate the actual width in iches or in points and compare it to page width minus gutter and left and right margins.

Best regards,

So my 720 pixels will not be "adjusted" in any way just recalculated. This means that I have a too wide table for an A4 (21 cm wide): 1 inch = 2,54 cm = 96*8,27 = roughly 793 pixels - the margins I use? Is there a way of using tables that would resize in the Word document e.g. 50%,25%,25%?

thanks for your rapid answers, you do score well!

The automatic resize can be achieved when you build the table with DocumentBuilder. It cannot be done with table inserted as HTML as far as I know. Of course, with Aspose.Words you can always do table formatting after it is inserted from HTML and format it all the way you want.

Maybe if you describe you task requirements a little further I can provide a better recommendation on how Aspose.Words can be used in your task.

Best regards,

I know I can format the table as I wish with the documentbuilder (I've been using TxText quite a lot so the document formatting is familiar) but the need for the moment is to provide a word document format from the existing html-reports I give my customers. I'm in priciple happy with everything but the different indent I get for the tables. Could you give me a hint of what that could be?

I have not noticed any indent problems in your html. The cells from Members to Maintenance income are indented because there is an empty cell before them in each row. Please specify what exactly are the indent problems you are referring to.

Best regards,