// Create an xlsx file stream FileStream outputStream = new FileStream("AutoMerge.xlsx", FileMode.Create); //create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); Stream fileStream = this.GetResourceStream("xlsx\\Regional_Product_List.xlsx"); workbook.Open(fileStream); var worksheet = workbook.ActiveSheet; //Add auto merge range with restricted mode and merged selection mode. worksheet.AutoMerge(worksheet.UsedRange, AutoMergeDirection.Column, AutoMergeMode.Restricted, AutoMergeSelectionMode.Merged); //The IncludeAutoMergedCells is true, the automatically merged cells will become normal merged cells. XlsxSaveOptions options = new XlsxSaveOptions { IncludeAutoMergedCells = true }; workbook.Save(outputStream, options); // Close the xlsx stream outputStream.Close();
' Create an xlsx file stream Dim outputStream = File.Create("AutoMerge.xlsx") ' Create a new Workbook Dim workbook As New Workbook Dim fileStream As Stream = GetResourceStream("xlsx\Regional_Product_List.xlsx") workbook.Open(fileStream) Dim worksheet As IWorksheet = workbook.ActiveSheet 'Add auto merge range with restricted mode and merged selection mode. worksheet.AutoMerge(worksheet.UsedRange, AutoMergeDirection.Column, AutoMergeMode.Restricted, AutoMergeSelectionMode.Merged) 'The IncludeAutoMergedCells is true, the automatically merged cells will become normal merged cells. Dim options As New XlsxSaveOptions With { .IncludeAutoMergedCells = True } workbook.Save(outputStream, options) ' close the xlsx stream outputStream.Close()