Tuesday, 16 August 2011 02:18

How to Merge Cells in Excel

Merge Cells in Excel

Sometimes, we work on excel spreadsheet and need merge cells in no matter row or column. Merge multiple cells into one can help readers easily distinguish data information. And sometimes when a title is to be centered over a particular section of a worksheet, author usually will merge cells to make it look better.

How to Use C#/VB.NET to Achieve Cells Merge in Excel?

Spire.XLS for .NET, a .NET Excel component which enables .NET applications to fast generate, read, write and modify Excel document without Microsoft Office Excel Automation can help us decrypt Excel worksheet by using C#/VB.NET.

Microsoft Excel offers a Merge and Center button for uses to merge cells and center the content in cell. On the other hand, Spire.XLS for .NET also allows developers/programmers use C#/VB.NET to merge cells in Excel worksheet.

Through Spire.XLS for .NET, merge cells in Excel via C#/VB.NET can be as easy as in Microsoft Excel. Download Spire.XLS for .NET (or Spire.Office) with .NET framework 2.0 (or above) together and use the sample code below, we can easily use C#/VB.NET achieve cells merge in Excel.

[C#]
Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xls");
workbook.Worksheets[0].Rows[0].Merge();
workbook.SaveToFile("result.xls");
[VB.NET]
Dim workbook As New Workbook()
workbook.LoadFromFile("test.xls")
workbook.Worksheets(0).Rows(0).Merge()
workbook.SaveToFile("result.xls")

Spire.XLS allows user to operate Excel document directly such as save to stream, save as web response, copy, lock/unlock worksheet, set up workbook properties, etc. As a professional .NET Excel component, it owns the ability of inserting content into Excel document, formatting cells and converting Excel documents to popular office file formats. Spire.XLS for .NET supports Excel 97-2003, Excel 2007 and Excel 2010.

Published in Cells