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

Free Support Forum - aspose.com

Wrong cells merge in table in header

I need to merge some cells in a table in a header. If I try to merge some cells in the middle of a table, the right number of cells are merged but they are always the rightmost cells in the table. The attached console app, to my great relief, reproduces the problem.
Thanks,
Bill Below

Hi Bill,
Thanks for your inquiry. I have tested the scenario using latest version of Aspose.Words for .NET 15.7.0 and have not found the shared issue. Please use Aspose.Words for .NET 15.7.0. I have attached the output document with this post for your kind reference.

Hi Tahir,
I updated from 15.6.0 to 15.7.0 but I still got the same result whereas you got a correct result. Why should our results be different? I am running VS2013 Update 5 on a 32-bit W7 computer. I am looking at the docx file with Word 2010. How can we proceed?
Bill

Hi Bill,
Thanks for your inquiry. Please make sure that you are using Aspose.Words for .NET 15.7.0. To
check version of the library, right click on the dll, select Properties
from the context menu, then select Version tab. You will see File
version. Please check the screenshot of MS Word 2010 in attachment.
Could you please share at which operating system you are running the application? Does this problem also occur on other machines?

Hi Tahir,
I rechecked the versions.
I have been compiling and running on a 32-bit Windows 7 computer. I tried it on a 64-bit Windows 10 computer with Word 2007 installed. Same results.
I also tried setting the Aspose license in my example console. It made no difference.
If I change the width of the table and the cells to use FromPoints() instead of FromPercent(), the same wrong cells are affected but they are deleted instead of merged.
Bill

Hi Bill,
Thanks for your inquiry. I have tested this scenario again using the shared code in the first post of this thread and have not found the shared issue. I have tested this issue with Aspose.Words version 15.6.0 and v15.7.0. Please check the attachment.
Could you please share output Docx generated at 32-bit Windows 7 and Widows 10 here for our reference?

Hi Tahir,
Here are the files you requested. In addition I have included program.cs which is the current source for my example console app.
Bill

Hi Bill,

Thanks for sharing the detail. Please call Document.UpdatePageLayout method before merging table’s cell. This method rebuilds the page layout of the document. I have attached the output document with this post for your kind reference.

Moreover, Document.UpdateTableLayout method updates widths of cells and tables in the document according to their preferred widths and content. You do not need to call this method if the tables appear correct in the output document.

doc.UpdatePageLayout();
for (int k = 8; k < 14; k++)
{
    Cell c = getcell(mtab, 0, k);
    if (k == 8)
        c.CellFormat.HorizontalMerge = CellMerge.First;
    else
        c.CellFormat.HorizontalMerge = CellMerge.Previous;
}
for (int k = 9; k < 12; k++)
{
    Cell c = getcell(mtab, 2, k);
    if (k == 9)
        c.CellFormat.HorizontalMerge = CellMerge.First;
    else
        c.CellFormat.HorizontalMerge = CellMerge.Previous;
}
tabletrace(mtab, 1);
doc.Save(@"Example v15.7.docx");

Thanks, Tahir,
Calling UpdatePageLayout() did the trick. My example app now works correctly. It is still a mystery why my example worked in your environment without this call and needs it in mine.
Meanwhile I abandoned merging on my real app and I just create the table cells where I need them along with large cells to the left to position them.
Thanks again,
Bill

Hi Bill,

Thanks for your inquiry. I am also getting the same output as of yours. The reason i am getting the correct output without calling UpdatePageLayout method is that i was saving the document before and after merging cells while testing your scenario. Please call UpdatePageLayout method before merging table’s cell to fix this issue.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.