Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Open an existing excel file, Merge some cells in the first worksheet in the workbook and save the excel file.
Following are the parallel code snippets for VSTO (C#, VB) and Aspose.Cells for .NET (C#, VB).
C#
.......
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using System.Reflection;
.......
//Instantiate the Application object.
Excel.Application excelApp = new Excel.ApplicationClass();
//Specify the template excel file path.
string myPath=@"d:\test\MyBook.xls";
//Open the excel file.
excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//Get the range of cells i.e.., A1:C1.
Excel.Range rng1 = excelApp.get_Range("A1", "C1");
//Merge the cells.
rng1.Merge(Missing.Value);
//Save the file.
excelApp.ActiveWorkbook.Save();
//Quit the Application.
excelApp.Quit();
C#
.......
using Aspose.Cells;
.......
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Specify the template excel file path.
string myPath=@"d:\test\MyBook.xls";
//Open the excel file.
workbook.Open(myPath);
//Get the range of cells i.e.., A1:C1.
Aspose.Cells.Range rng1 = workbook.Worksheets[0].Cells.CreateRange("A1", "C1");
//Merge the cells.
rng1.Merge();
//Save the file.
workbook.Save(@"d:\test\MyBook.xls");
To unmerge the cell(s), use the following lines of code for VSTO (C#, VB) and Aspose.Cells for .NET (C#, VB).
C#
//Get the A1 cell (Merged Cell).
Excel.Range rng1 = excelApp.get_Range("A1", Missing.Value);
//UnMerge the cell.
rng1.UnMerge();
C#
//Get the A1 cell (Merged Cell).
Cells rng1 = workbook.Worksheets[0].Cells;
//UnMerge the cell.
rng1.UnMerge(0, 0, 1, 3);
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.