Why to Merge Excel cells
While we are working within a Microsoft Excel spreadsheet, many of us may face this
problem: we have to merge two or more cells together to form one big cell. Spire.XLS, as a professional and powerful Excel
component, it enables developers to merge Excel cells into one with C#/VB.NET effortlessly. The whole process is very simple,
we just need choose the cells and everything will be cool with two main sentence of code.
How to Merge Excel
Cells via Spire.XLS
Please make sure Spire.XLS and Visual Studio are correctly installed on system. Follow the
simple steps below to merge Excel cells with C#/VB.NET.
Step 1 Create Project
Create a C#/VB.NET project in your visual studio. Add Spire.XLS.dll as reference. The default setting of Spire.Xls.dll is
placed under "C:Program Filese-iceblueSpire.XlsBin. Select assembly Spire.Xls.dll and click OK to add it to the project.
static void Main(string args)
Step 2 Load Excel File
Use the code below to load Excel file in which we will merge Excel files.
//load the excel template
Workbook workbook = new Workbook();
Step 3 Merge Excel Files
Select the cells which we need merge into one. Follow the samples below and we can merge cells at will.
A2-D4 to one cell
Worksheet sheet = workbook.Worksheets;
//merge D5-E6 to one cell
Step 4 Save and Preview
After finish merging Excel cells, save the modified Excel file as .xls format. And we can preview what weve done by pressing
F5 to launch the project.
//save the workbook
//launch the workbook