• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

A Solution about How to Merge Excel Cells

chand

New Member
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:program 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.
 
if you want to merge excel cell using vb.net you can write like this


chartRange = xlWorkSheet.Range("b2", "e3")

chartRange.Merge()

http://vb.net-informations.com/excel-2007/vb.net_excel_page_format.htm


the above link provide more formating sample using vb.net.


legard.
 
Chand


Firstly, Welcome to the Chandoo.org forums.


Thanx for this info


As some general advice I generally recommend that people don't merge Cells together

It creates all sorts of difficulties and simply isn't worth the hassle


I do recommend that People use the Centre Across Selection formatting which serves a similar function and doesn't have the same baggage.
 
hello I
Code:
m Gonzalo from Colombia and I
ve got a question


How can I merge cells with a command? ctrl+ something I really need it


many thanks
 
Back
Top