Free Support Forum - aspose.com

Horizontal Merge Issue

Hi

I have the following code to merge two cells in table

private void HorizontallyMergeCells(Aspose.Words.Tables.Cell firstCell, Aspose.Words.Tables.Cell secondCell)

{

firstCell.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First;

foreach (Node child in secondCell.GetChildNodes(NodeType.Run, true))

firstCell.LastParagraph.AppendChild(child);

secondCell.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.Previous;

}

And i called the method like as follows

HorizontallyMergeCells(row.Cells[0], row.Cells[1]);

its working for to merge cells 0 and 1

My Isuue is how to merge cells 0,1 and 2, that is more than 2 cells

Please give me a solution

Regards

Ajeesh M J

Hi Ajeesh,


Thanks for your inquiry. To ensure a timely and accurate response please supply us with the following information, if you cannot supply us with this information we will not be able to investigate your issue and raise a ticket.

  • Please supply us with the input Word document that is causing the issue
  • Please supply us with the output document showing the undesired behavior
  • Please supply us with the expected document showing the desired behavior. You can create this document manually by using Microsoft Word. We will investigate as to how you would like your final output to be generated like.

As soon as you get these pieces of information to us we’ll start our investigation into your issue.

Many thanks,

HI Awais Hafeezv

Thanks for your replay.Here by amm attaching 3 word document.Input.docx,CurrentOutPut.docx and requiredoutput.docx.

In my CurrentOutput,Cell1 and Cell2 are horizontally merged

In my RequirdOutput i need Cell1,Cell2 and Cell3 horizontally merge

in my previous mail i send how i did Cell1 and Cell2 Horizotal merge

Now i need a code that can horizotally merge Cell1,Cell2 and cell3

Regards

Ajeesh M J

Hi Ajeesh,


Thanks for the additional information. Sure, you can achieve this by using the following code snippet:

Document
doc = new Document(@“C:\Temp\Input.docx”);

Table tab = doc.FirstSection.Body.Tables[0];

for (int i = 1; i < tab.Rows.Count; i++)

{

for (int j = 0; j < 3; j++)

{

Cell cell = tab.Rows[i].Cells[j];

if (j == 0)

cell.CellFormat.HorizontalMerge = CellMerge.First;

else

cell.CellFormat.HorizontalMerge = CellMerge.Previous;

}

}

doc.Save(@"C:\temp\out.docx");


I hope, this helps.

Moreover, I would suggest you please read the following article for more details on how to merge Table Cells:
http://www.aspose.com/docs/display/wordsnet/Working+with+Merged+Cells

Best regards,