Free Support Forum - aspose.com

Cell alignments and table broders

Hi I have few questions.

With this post I am attaching a word document with a table which was generated with aspose. The first table is what I can/have generated with aspose and the second table is what I need to have.

1 - Table cell alignment - In word I see there are 9 ways to align text in the cells 3 horizontal and 3 vertical (giving you combo of 9). In aspose I only see VerticalAlignment and I don't see HorizontalAlign. How can I do this?

2 - I need to put border of type grid on the table. What is the best way to do this?

Thanks,

Balvinder

Hi Balvinder,

  1. Horizontal alignment is controlled by the ParagraphFormat.Alignment property. Notice this is the way Microsoft Word aligns table cell contents as well.
  2. The best way of putting a grid-like border to a table is iterating over all rows of the table and setting a positive value to the Row.RowFormat.Borders.LineWidth property (and adjusting other border properties if required):

foreach (Row row in table.Rows)

row.RowFormat.Borders.LineWidth = 1.0;

Please feel free to post your future questions here Smile [:)]

Hi Dmitry,

Thanks for you reply, both of your sugestions worked.

I have 2 more questions regarding tables.

1. When you generate a table it seems to start a new paragraph. I there a way to get rid of the paragraph at the start of a table?

2. Is there a way to tell words to skip to next page if it can only display the header of the table on the current page. With this reply I have attached a document for you to look at if you look at page 2 you will see that it only displays the table header (i.e. the first row of the table), but no data, the data is on page 3.

Once again thank you for your help.

Balvinder

  1. Basically, tables we are talking about are inline nodes located at the same level as paragraphs are. So when you insert a new table after a paragraph, no new paragraph started but a paragraph break inserted to mark the end of the previous paragraph node. Do you mean this paragraph mark? It seems to be impossible to get rid of it but I can hardly suppose why it would be needed. Please clarify this point, maybe I just misunderstood you.
  2. Yes, it is possible. If you insert a table dynamically, just set DocumentBuilder.ParagraphFormat.KeepWithNext to true before insertion. The same idea applies to an existing table, just iterate through its child paragraphs and set the property as appropriate.