Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
Merging Cells in Tables in Word
Posted on: 10 Mar 2010

I have a table in Word with 3 rows and 20 columns.  I am trying to take the 1st row and merge the 1st 8 cells into one to make a "header" over the 2nd, 3rd, and 4th columns.  When I execute the merge code below, it merges the columns together, but moves all the other columns to the left.  I want to perform the merge much like you do it in Word where you highlight the cells, select merge and the 3 cells become one leaving the same width.
object startRange = oTable.Rows[1].Cells[2].Range.Start;
object endRange = currentRow.Cells[4].Range.End;
Word.
Range mergeRange = aDoc.Range(ref startRange, ref endRange);
mergeRange.Cells.Merge();

Thanks,
Robert

 

AuthorReply
Re: Merging Cells in Tables in Word
Posted on: 11 Mar 2010  
hi friend,

try following code:

oTable.Rows[1].Cells[1].Merge(oTable.Rows[1].Cells[2]);

This line will merge two cells. i have already used it.

Please mark as answer if  it helps you.

=====================================
Amit Choudhary
MicrosoftMVP MindcrackerMVP Blog: www.cshandler.com
Follow @vendettamit

Re: Merging Cells in Tables in Word
Posted on: 11 Mar 2010  

Thanks for the help Amit, but the merge does fine.  The problem that I am having is that when I merge cell 1 with cell 2 it moves all the other cells left 1 and removes the alignment.  I am trying to merge cell #1 and cell #2 together and make them the width of both cells to keep the other cells in the row from sliding over one to the left. 
This is what I have
|Cell1     |Cell2     |Cell3     |Cell4     |
This is what I want to do.  Merge 1 & 2, but keep 3 and 4 in their original position
|Cell1&2               |Cell3     |Cell4     |
But this is what the merge is doing.  It is merging 1 & 2 and shifting 3 & 4 over
|Cell1&2|Cell3  |Cell4 |
I tried doing this in Word and creating a macro to see what VBA code was generated, but it just does the following
Selection.MoveRight Unit:=wdCell
Selection.Cells.Merge
Not sure how to accomplish this in C#

Re: Merging Cells in Tables in Word
Posted on: 25 Dec 2010  

Hi friend,


Your code for merging cells in c# is very usefull for me.
Thank you.

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.