Is there a way to have it imported in the Word document as it is in the then html code? If so, where in the code behind (cs file) is this done. (i.e. Builder.ParagraphFormat.x = true?)
Thanks. Ok, so now I can bring in the html table. However, the table is compressed. You can not read any of the data in it. I can manually expand each of the columns in Word, but I would think that the table should already have the spacing set correctly, especially given that Could the catch be that the html code / table is nested inside a table I directly created using Aspose? I.E. builder.StartTable();
Hi
Thanks for your inquiry. I cannot reproduce the problem with table width on my side using the latest version of Aspose.Words (9.5.0). Regarding creating a table (a nested table) directly, please try using the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.StartTable();
// Insert a cell
builder.InsertCell();
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Writeln("This is row 1 cell 1 table 1");
// Insert a cell
builder.InsertCell();
// Insert nested table
builder.StartTable();
// Insert a cell
builder.InsertCell();
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Writeln("This is row 1 cell 1 table 2");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 1 cell 2 table 2");
builder.EndRow();
// Apply new row formatting
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = HeightRule.Exactly;
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 1 table 2");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 2 table 2");
builder.EndRow();
builder.EndTable();
builder.EndRow();
// Apply new row formatting
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = HeightRule.Exactly;
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 1 table 1");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 2 table 1");
builder.EndRow();
builder.EndTable();
doc.Save("out.doc");
Thank you, but your example does not import html for the nested table that I have in my situation. Did you by chance try doing that way? The data I need for the nested table is already pre-rendered as html, so I have no choice, but to read the html source and have aspose handle the conversion to word.
Hi there,
Thanks for this additional information.
I was unable to reproduce any issue using the simple HTML snippet you provided. The table appears expanded in the document. You were mentioning that you are using nested tables, is that prehaps the cause of the issue? Could you attach the full HTML code you are using (in a .txt file) and also the output document you are getting?
Thanks,
Attached is an example of the output data, and the test html code I’ve been using. I plugged in the html into the code you gave above and the same problem occurred. I used my html code directly and as a variable to builder.InsertHtml(). Below is the code. Any ideas would be great. Thanks!
Here is that code:
// insert a break, to make sure Word doesn't merge those tables
builder.CellFormat.ClearFormatting();
builder.InsertHtml(product.Content);
builder.StartTable();
// Insert a cell
builder.InsertCell();
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Writeln("This is row 1 cell 1 table 1");
// Insert a cell
builder.InsertCell();
// Insert nested table
builder.StartTable();
// Insert a cell
builder.InsertCell();
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Writeln("This is row 1 cell 1 table 2");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 1 cell 2 table 2");
builder.EndRow();
// Apply new row formatting
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = HeightRule.Exactly;
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 1 table 2");
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 2 table 2");
builder.EndRow();
builder.EndTable();
builder.EndRow();
// Apply new row formatting
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = HeightRule.Exactly;
// Insert a cell
builder.InsertCell();
builder.Writeln("This is row 2 cell 1 table 1");
// Insert a cell
builder.InsertCell();
builder.InsertHtml("<p>"+
"<table cellpadding=\"1\" border=\"1\">" +
"<tbody>"+
" <tr>"+
"<td>dddd</td>"+
"<td>f</td>"+
" </tr>"+
"<tr>"+
" <td>fd</td>"+
"<td>ddf</td>"+
"</tr>"+
"<tr>"+
" <td>f</td>"+
"<td>f</td>"+
"</tr>"+
"</tbody>"+
"</table>"+
"</p>" );
//Writeln("This is row 2 cell 2 table 1");
builder.EndRow();
builder.EndTable();
Thank you for additional information. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.5.0). Which version of Aspose.Words you are using? I have attached the document produced on my side using your code with one small changes (please see the code bellow):
// insert a break, to make sure Word doesn't merge those tables
builder.CellFormat.ClearFormatting();
// Set width
builder.CellFormat.Width = 500;
builder.InsertHtml("");
builder.StartTable();
Looks like I’ve got version 4.0.2. I thought it was newer, but maybe not. Could this be a problem with having different versions? Do you have access to older versions that you can verify?
Thank you for additional information. The latest version of Aspose.Words for Net is 9.5.0. You can download the latest version from here: https://releases.aspose.com/words/net
Please try using the latest version and let me know how it goes on your side.
Also please note, usually we always check with the latest version. There is no sense to check with old versions.
Best regards,