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

Free Support Forum - aspose.com

Issue with vertical merging in table

Hi,

I have an issue with merging cells vertical.
When I specify in a table AllowAutoFit to false, it doesn’t take in account the row marked as first.
Here is an example :
var t1 = DocBuilder.StartTable();

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 1");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 2");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 3");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 4");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.EndRow();


            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 2 cell 2");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 2 cell 4");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.EndRow();


            DocBuilder.InsertCell();
            DocBuilder.Write("row 3 cell 1");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 3 cell 4");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.EndRow(); 


            t1.SetBorders(Aspose.Words.LineStyle.Single, 1, Color.Black);
            t1.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100);
            //t1.AllowAutoFit = false;
            DocBuilder.EndTable();

The result is :
t1.png (4.6 KB)

And if uncomment my line to AllowAutoFit to false :

t2.png (3.2 KB)

The behavior is different, the row marked as first is not taked into account.

Any ideas?

I really need to have fixed columns so I can’t let allowautofit to true.

Thanks in advance

@RTech2016

Thank you for your inquiry. We have investigated using Aspose.Words for .NET API version 17.11.0 with your provided sample source code and found no issues OutputDocuments.zip (4.1 KB). If you are using older version of Aspose.Words API then we suggest you to upgrade to latest version.

I am using the 17.11 too

Here is my full test code program :

using System;
using System.Collections.Generic;
using System.Linq; 

namespace MyNamespace
{
    static class Program
    {
        /// <summary>
        ///  
        /// </summary>
        [STAThread]
        static void Main()
        { 
            WriteDocument(true);
            WriteDocument(false); 
        }

        public static void WriteDocument(bool autofit)
        {
            Aspose.Words.Document doc = new Aspose.Words.Document();
            Aspose.Words.DocumentBuilder DocBuilder = new Aspose.Words.DocumentBuilder(doc);


            var t1 = DocBuilder.StartTable();

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 1");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 2");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 3");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 1 cell 4");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.EndRow();


            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 2 cell 2");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 2 cell 4");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.EndRow();


            DocBuilder.InsertCell();
            DocBuilder.Write("row 3 cell 1");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.InsertCell();
            DocBuilder.Write("row 3 cell 4");
            DocBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
            DocBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(25);

            DocBuilder.EndRow();


            t1.SetBorders(Aspose.Words.LineStyle.Single, 1, System.Drawing.Color.Black);
            t1.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100);
            t1.AllowAutoFit = autofit;
            DocBuilder.EndTable();



            doc.Save(@"c:\autofit_"+ autofit + ".docx", Aspose.Words.SaveFormat.Docx); 
        }
    }
}

It really do not work.
If you make a save, change the value, and save again, the table will be ok, but not in my example.

@RTech2016

Thanks for your feedback. We have investigated it further and found this issue only appears while saving document as DOCX format and works fine while saving document as DOC format Output_Documents.zip (14.3 KB). We have logged this ticket against your reported issue. We will notify you as soon as this issue is resolved.

WORDSNET-16216: Issue with vertical merging in table while saving as DOCX when AllowAutoFit is false

We are sorry for the inconvenience.

Thanks, it make the same with PDF format, I didnt try other format.

@RTech2016

Thanks for your feedback. We will notify you as soon as this issue is resolved.

@RTech2016,

The issues you have found earlier (filed as WORDSNET-16216) have been fixed in this Aspose.Words for .NET 18.2 update and this Aspose.Words for Java 18.2 update.

Please also check the following articles: