This short tutorial describes how to merge cells in Word using C#. It has the details to set the IDE, a list of steps, a predefined function for combining the cells, and a sample code showing how to merge tables in Word using C# with the help of this predefined function. There is no need for any other third-party tool for accomplishing this task.
Steps to Merge Cells in Word Table using C#
- Set the IDE to use Aspose.Words for .NET to combine cells in a table
- Declare a predefined method MergeCells for use in your application
- Load the source Word file into the Document object having one or more tables in it
- Access the table in the loaded Word file for merging cells
- Access the starting cell of the target merge range
- Access the ending cell of the merge range
- Call the MergeCells() method by providing the starting and ending cells and save the document
These steps assist in how to merge cells in Word using C#. Add the predefined method in your project and call it by providing the starting and ending cell you want to merge. It will change the source file, therefore, you may save the loaded Word file with a different name having the merged cells.
Code to Combine Cells in Word using C#
This code demonstrates how to combine tables in Word using C#. We have added a predefined method MergeCells along with its definition and then call it in our application wherever required. You can select the section, a list of tables in that section, and access the target table using its index to choose the starting and ending cells for merging. You may repeat this process to merge cells as many as required.
We have learned how to merge cells in Microsoft Word using C#. If you want to merge complete Word documents, refer to the article on How to merge Word documents using C#.