We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Width difference in Word doc and HTML formats

Hi,

Please find the below code to reproduce the scenario. This code is actually generated according to the business requirement [ you may wonder why we repeat some sections like setting font to “Verdana” again and again, but this is purely based on the business requirement]. The document created is saved as both Doc and HTML. Please see the out put and see that there is width difference in the first row of the first table. Please review the code and tell me what is wrong in this.

Note : The width of the first row of first tabel is 325 [ two cells are merged to one cell]

The width of the first row of second tabel is also 325 [ two cells are merged to one cell]

The width of the first cell in second row of the second table is 100

The width of the second cell in the second row of the second table is 225.

**********Code***************

Document asposeDoc = new Document();

DocumentBuilder builder = new DocumentBuilder(asposeDoc);

PageSetup asposePageSetup = builder.PageSetup;

asposePageSetup.BottomMargin = 0;

asposePageSetup.LeftMargin = 1;

asposePageSetup.RightMargin = 1;

asposePageSetup.TopMargin = 1;

builder.MoveToDocumentEnd();

builder.CellFormat.FitText = true;

builder.RowFormat.Height = 19;

builder.InsertCell();

builder.CellFormat.Width = 325;

builder.InsertCell();

builder.CellFormat.Width = 1;

builder.EndRow();

builder.EndTable();

builder.MoveToDocumentEnd();

builder.MoveToCell(0, 0, 0, 0);

builder.CellFormat.Borders.Color = Color.Black;

builder.CellFormat.Borders.LineWidth = 1;

builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;

builder.CellFormat.Width = 325;

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.Shading.Texture = TextureIndex.TextureNone;

builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(255, 255, 255);

builder.Font.ClearFormatting();

builder.Font.Name = "Verdana";

builder.Font.Size = 8;

builder.Font.Bold = false;

builder.Font.Italic = false;

builder.Font.StrikeThrough = false;

builder.Font.Color = Color.FromArgb(50, 50, 50);

builder.ParagraphFormat.LeftIndent = 3;

builder.CellFormat.TopPadding = 0;

builder.ParagraphFormat.RightIndent = 3;

builder.CellFormat.BottomPadding = 0;

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;

builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

builder.Write("Table0Row0Col0Span2");

builder.MoveToDocumentEnd();

builder.MoveToCell(0, 0, 1 , 0);

builder.CellFormat.Width = 0;

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;

builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

builder.CellFormat.Borders.Top.LineStyle = LineStyle.None;

builder.MoveToDocumentEnd();

builder.CellFormat.FitText = true;

builder.RowFormat.Height = 23;

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.InsertCell();

builder.CellFormat.Width = 225;

builder.EndRow();

builder.RowFormat.Height = 23;

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.InsertCell();

builder.CellFormat.Width = 225;

builder.EndRow();

builder.EndTable();

builder.MoveToDocumentEnd();

builder.MoveToCell(1, 0, 0, 0);

builder.CellFormat.Borders.Color = Color.Black;

builder.CellFormat.Borders.LineWidth = 1;

builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;

builder.CellFormat.Width = 325;

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.Shading.Texture = TextureIndex.TextureNone;

builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(255, 255, 255);

builder.Font.ClearFormatting();

builder.Font.Name = "Verdana";

builder.Font.Size = 8;

builder.Font.Bold = false;

builder.Font.Italic = false;

builder.Font.StrikeThrough = false;

builder.Font.Color = Color.FromArgb(50, 50, 50);

builder.ParagraphFormat.LeftIndent = 3;

builder.CellFormat.TopPadding = 0;

builder.ParagraphFormat.RightIndent = 3;

builder.CellFormat.BottomPadding = 0;

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;

builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

builder.Write("Table1Row0Col0Span2");

builder.MoveToDocumentEnd();

builder.MoveToCell(1, 0, 1, 0);

builder.CellFormat.Width = 0;

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;

builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

builder.CellFormat.Borders.Top.LineStyle = LineStyle.None;

builder.MoveToDocumentEnd();

builder.MoveToCell(1, 1, 0, 0);

builder.CellFormat.Borders.Color = Color.Black;

builder.CellFormat.Borders.LineWidth = 1;

builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.Shading.Texture = TextureIndex.TextureNone;

builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(255, 255, 255);

builder.Font.ClearFormatting();

builder.Font.Name = "Verdana";

builder.Font.Size = 8;

builder.Font.Bold = false;

builder.Font.Italic = false;

builder.Font.StrikeThrough = false;

builder.Font.Color = Color.FromArgb(50, 50, 50);

builder.ParagraphFormat.LeftIndent = 3;

builder.CellFormat.TopPadding = 0;

builder.ParagraphFormat.RightIndent = 3;

builder.CellFormat.BottomPadding = 0;

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;

builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

builder.Write("Table1Row1Col0Span1");

builder.MoveToDocumentEnd();

builder.MoveToCell(1, 1, 1, 0);

builder.CellFormat.Borders.Color = Color.Black;

builder.CellFormat.Borders.LineWidth = 1;

builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.Shading.Texture = TextureIndex.TextureNone;

builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(255, 255, 255);

builder.Font.ClearFormatting();

builder.Font.Name = "Verdana";

builder.Font.Size = 8;

builder.Font.Bold = false;

builder.Font.Italic = false;

builder.Font.StrikeThrough = false;

builder.Font.Color = Color.FromArgb(50, 50, 50);

builder.ParagraphFormat.LeftIndent = 3;

builder.CellFormat.TopPadding = 0;

builder.ParagraphFormat.RightIndent = 3;

builder.CellFormat.BottomPadding = 0;

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;

builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

builder.Write("Table1Row1Col1Span1");

builder.MoveToDocumentEnd();

asposePageSetup.PageWidth = 700;

asposePageSetup.Orientation = Aspose.Words.Orientation.Portrait;

asposeDoc.Save(@"C:\TestDoc.Doc");

asposeDoc.Save(@"C:\TestHTML.html",SaveFormat.Html);

******************************

Please advice,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks and Regards,

Ali

Hello!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your interesting question.

This is really strange since the first table has the same width as rows in second one if all cells are accumulated. When I tried converting the resulting DOC to HTML using MS Word it was okay. As a workaround you can try using one table in place of two.

This code is slightly easier and reproduces the problem:

private static void TestChangingWidth()

{

Document asposeDoc = new Document();

DocumentBuilder builder = new DocumentBuilder(asposeDoc);

builder.CellFormat.FitText = true;

builder.CellFormat.Borders.LineStyle = LineStyle.Single;

builder.RowFormat.Height = 19;

builder.InsertCell();

builder.Write("Table0Row0Col0Span2");

builder.CellFormat.Width = 325;

builder.EndRow();

builder.EndTable();

builder.InsertCell();

builder.Write("Table");

builder.CellFormat.Width = 100;

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.CellFormat.Width = 225;

builder.EndRow();

builder.RowFormat.Height = 23;

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.Write("Table");

builder.CellFormat.Width = 100;

builder.InsertCell();

builder.Write("Table");

builder.CellFormat.Width = 225;

builder.EndRow();

builder.EndTable();

asposeDoc.Save(@"ChangeWidth_TestDoc.doc");

asposeDoc.SaveOptions.ExportPrettyFormat = true;

asposeDoc.Save(@"ChangeWidth_TestHTML.html", SaveFormat.Html);

}

Regards,