Search code examples
c#ms-wordoffice-interop

HTML to Doc : Add minimum space between tables


I am generating word doc from HTML content using Microsoft.Office.Interop.Word dll. Word doc file is generated properly. but I am getting much padding space issue. I have two tables and I want to give a minimum space between two tables. I have tried to apply padding and margin on the table but both are not working. If I place an extra line then it is showing much space between two tables.

Is there any way to give minimum space between tables?

Result if we add a line between two tables.

enter image description here

Result if we do not place the extra line between two tables. enter image description here


Solution

  • Word requires a paragraph (not a "line") between two tables in order for them to be separate tables. If there is none, as in the second screen shot in the question, then Word regards them as a single table. This may or may not be a problem for the document in question, but should be understood.

    • If the tables should be a single Word table, it would be possible to insert a row between them and format the row with an exact height.
    • If the tables should indeed be two, separate entities, then a paragraph (ANSI 13 / \n or \r) needs to come between them. The paragraph mark is not just a character code - behind the scenes it stores important formatting information, including positioning of the table on the page.

    If the paragraph mark between the tables is too "tall" there are various formatting possibilities that can be applied to reduce this:

    • Apply a smaller font size (Word supports a minimum font size of 1 pt)
    • Reduce the paragraph settings Space Before and/or Space After

    Properly, especially if this multi-table content format is used more than once, the formatting attributes should be set in a paragraph style. Then using them is a simple matter of applying the style to the paragraph.