Working with Tables

We use Aspose Words ver. 4.4.1 and are moving code from a VB 6 app to the web. I need to know if the follwing code using the word object in vb6 is something that can be accomlished with Words.
The template used for a find and replace has a table with 3 columns. The app replaces a tag in the 1st column with text from the database. The problem arises when the text is long enough to force the text to wrap. This causes wxtra lines in the 1st column but not the 2nd coulmn. The VB6 code goes thru and corrects the table.
I have atatched a word doc that contains the VB6 code and examples of the tables (good and bad)
Thanks
Russ Vaughn

Hi Russ,

Thanks for your inquiry. After an initial analysis of your requirements, I would suggest you please migrate to the latest version of Aspose.Words for .Net i.e. 10.8.0. You can download the latest version from the following link:
https://releases.aspose.com/words/net

Moreover, please note that you can use Aspose.Words for .NET to build any type of a 32-bit or 64-bit .NET application including ASP.NET and WCF web apps. Again, migrating to this new version is pretty easy; please read out the following article:
https://docs.aspose.com/words/net/release-notes/

Once you’re done with this up-gradation, should you have any questions please don’t hesitate to ask. We are always glad to help you.

Best Regards,

I have moved to version 10.8. Now I get an error on the line of code:
Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)

The error is:
‘Aspose.Words.Node’ cannot be converted to ‘System.Web.UI.WebControls.Table’.
I have declared doc like:

Dim doc As New Document(System.Web.HttpContext.Current.Server.MapPath("~/Templates/") & lcDocGen.Document)

Hi Russ,

Thanks for your inquiry. Please use this

> ‘Aspose.Words.Node’ cannot be converted to ‘System.Web.UI.WebControls.Table’.
Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Aspose.Words.Tables.Table)

Hope this will help.

Hi Russ,

Thanks for your inquiry. Please use following code snippet.

> ‘Aspose.Words.Node’ cannot be converted to ‘System.Web.UI.WebControls.Table’.

Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Aspose.Words.Tables.Table)

Hope this will help.

Hi Russ,

Thanks for your inquiry.

It sounds like you have a System.Web.UI import that also has a class called Table. The line of code giving you the exception is trying to cast an Aspose.Words table to a System.Web.UI table.

You can avoid this issue by using the fully qualified name in your code:

Dim table as Aspose.Words.Tables.Table = CType(doc.GetChild(NodeType.Table, 0, True), Aspose.Words.Tables.Table)

Thanks,

That worked, Thanks.
Now would you please be able to provide me with some code to access a column in the table and write text to each cell in that column for every row. I think it would be something like:

Dim column As Column = column.FromIndex(Aspose.Words.Tables.Table, 1)

' Add some text to each of the column cells.
For Each cell As Cell In column.Cells
' Code to add text. Next cell

Any help is greatly appricated.

Hi Russ,

Thanks for your inquiry.

First of all, please note that there is no “column” concept in the Word table. By Microsoft Word design rows in a table in a Microsoft Word document are completely independent. It means each row can have any number of cells.

Moreover, to be able to dynamically grow portions in your Word document, I would suggest you try using the approach suggested in the following article:
https://docs.aspose.com/words/java/types-of-mail-merge-operations/

If we can help you with anything else, please feel free to ask.

Best Regards,

My situation is that I have a table inwhich the mail merge cause the first column to grow. I need to and the ‘)’ character to the second column so that it has the same number of rows as the first column. I attached an example of a document showing this to my initial post.

Hi Russ,

Thanks for your inquiry and sorry for the delayed response.

What I understand, you are trying to maintain equal number of lines in both first and second cells in the first row of a table. Also, you’re filling content of first cell dynamically and while doing so sometimes the first cell grows more vertically than the second one.

If this is the case, please note that unfortunately there is no functionality to calculate lines count inside table cell to be able to have equal number of text lines in two different cells.

Please let us know if you need more information, we are always glad to help you.

Best Regards,