C# Answers Forum - How to Merge Excel Cells via Spire.xls

The Artima Developer Community
Sponsored Link

C# Answers Forum
How to Merge Excel Cells via Spire.xls

2 replies on 1 page. Most recent reply: May 29, 2019 3:24 AM by Synkronizer Excel Tool

Welcome Guest
Sign In

Flat View: This topic has 2 replies on 1 page
George Eric

Posts: 1
Nickname: peterman
Registered: Mar, 2012

How to Merge Excel Cells via Spire.xls Posted: Mar 20, 2012 7:18 PM
Advertisement
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 Files\e-iceblue\Spire.Xls\Bin". 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");

Hope to be helpful.


Lucy Keating

Posts: 1
Nickname: kerrey
Registered: Mar, 2012

Re: How to Merge Excel Cells via Spire.xls Posted: May 9, 2012 7:21 PM
Really thanks for your informative article. it helps me much after my huge search. Does Spire.xls can export data ?

Synkronizer Excel Tool

Posts: 1
Nickname: exceltool
Registered: May, 2019

Re: How to Merge Excel Cells via Spire.xls Posted: May 29, 2019 3:24 AM
Thanks for sharing. Really Helpful code to Merge Excel cells. Also, I use SYnkronizer Excel Add-in to Merge Multiple Excel files. Check This - https://synkronizer.com

Flat View: This topic has 2 replies on 1 page

Sponsored Links



Web Artima.com

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use

AltStyle によって変換されたページ (->オリジナル) /