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. Here i would like to recommend a solution via Spire.XLS. 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
rogram Filese-iceblueSpire.XlsBin”. Select assembly Spire.Xls.dll and click OK to add it to the project.
using Spire.Xls;
namespace CellsMerge
{
class Program
{
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();
workbook.LoadFromFile(@"....parts.xls", ExcelVersion.Version97to2003);
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.
//merge A2-D4 to one cell
Worksheet sheet = workbook.Worksheets[0];
sheet.Range[A2:B4].Merge();
//merge D5-E6 to one cell
sheet.Range[D5:E6].Merge();
Step 4 Save and Preview
After finish merging Excel cells, save the modified Excel file as .xls format. And we can preview what we’ve done by pressing F5 to launch the project.
//save the workbook
workbook.SaveToFile(@"....cellsMerge.xls", ExcelVersion.Version97to2003);
//launch the workbook
System.Diagnostics.Process.Start(@"....cellsMerge.xls");
For more Excel question, click http://www.e-iceblue.com/Knowledgebase/Spire.XLS/Program-Guide.html to learn more. Hope to be helpful.
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
using Spire.Xls;
namespace CellsMerge
{
class Program
{
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();
workbook.LoadFromFile(@"....parts.xls", ExcelVersion.Version97to2003);
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.
//merge A2-D4 to one cell
Worksheet sheet = workbook.Worksheets[0];
sheet.Range[A2:B4].Merge();
//merge D5-E6 to one cell
sheet.Range[D5:E6].Merge();
Step 4 Save and Preview
After finish merging Excel cells, save the modified Excel file as .xls format. And we can preview what we’ve done by pressing F5 to launch the project.
//save the workbook
workbook.SaveToFile(@"....cellsMerge.xls", ExcelVersion.Version97to2003);
//launch the workbook
System.Diagnostics.Process.Start(@"....cellsMerge.xls");
For more Excel question, click http://www.e-iceblue.com/Knowledgebase/Spire.XLS/Program-Guide.html to learn more. Hope to be helpful.