How to Merge Cells in Excel.
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.
using Spire.Xls; namespace MergeCells { class Program { static void Main(string[] args) { Workbook workbook = new Workbook(); workbook.LoadFromFile("test.xls"); workbook.Worksheets[0].Rows[0].Merge(); workbook.SaveToFile("result.xls"); } } }
Imports Spire.Xls Namespace MergeCells Class Program Private Shared Sub Main(args As String()) Dim workbook As New Workbook() workbook.LoadFromFile("test.xls") workbook.Worksheets(0).Rows(0).Merge() workbook.SaveToFile("result.xls") End Sub End Class End Namespace
Spire.XLS allows user to operate Excel document directly such as save to stream,.