Word Table Conversion to HTML

Hi,

is is possible to read out a table structure from a Word file and recreate it one to one as a table (not with div/span) with the same look as in Word (I know there are restrictions) ?

Kind regards,
Guido

@Nachti

Aspose.HTML for .NET does not read the Word documents. Could you please share some more detail about your requirement along with input and expected output documents? We will then provide you more information on it.

Hi Tahir,

we can read out Word files with Aspose.Words.

The question is if there is way to read out the properties like length, height, amount of columns and rows to auto create the table. Or is it like in Aspose.Word that you have to create each table manually row by row, column by column ?

Kind regards,
Guido

@Nachti There is no concept of column in MS Word tables, since each row in MS Word table is independent and can contain any number of cells.
To read MS Word table structure, you can either loop through rows and cells in the table or use DocumentVisitor.

If you need to convert a table to HTML, you can simply use Node.ToString method:

Document doc = new Document(@"C:\Temp\in.docx");
Table table = doc.FirstSection.Body.Tables[0];
Console.WriteLine(table.ToString(SaveFormat.Html));

Or save the document with table to HTML.

To make a table in HTML, use the <table> tag. Within this table tag, you’ll place the <tr>, <th>, and <td> tags. The <tr> tag defines a table row. The <th> tag defines the table header.

Regards,
Will

1 Like