amjad islam amjad

amjad islam amjad

  • 1.7k
  • 87
  • 1.3k

UnMerge Complete Excel Sheet Cell and copy the value in unmerge cells

Jan 31 2022 5:21 PM

Excel.Application app = new Excel.Application();
    app.AskToUpdateLinks = false;
    app.DisplayAlerts = false;
    app.ScreenUpdating = false;

    Excel.Workbook workbook = null;
    try
    {
        workbook = app.Workbooks.Open(path);
        workbook.CheckCompatibility = false;
        workbook.UpdateLinks = Excel.XlUpdateLinks.xlUpdateLinksNever;
        //workbook.UpdateLink(null, null);
        workbook.SetLinkOnData(null, null);
        //workbook.Connections.Item(0).Delete();
        workbook.LinkSources(null);
        //workbook.BreakLink(string.Empty, Excel.XlLinkType.xlLinkTypeExcelLinks);

        foreach (Excel.Worksheet sheet in workbook.Worksheets)
        {
            sheet.Unprotect();
            if (sheet.Name == "Additional")
            {
                foreach (Excel.Range cell in ((Excel._Worksheet)workbook.ActiveSheet).UsedRange)
                {
                    if ((bool)cell.MergeCells)
                    {
                        var joinedCells = cell.MergeArea;
                        //cell.UnMerge();
                        cell.MergeCells = false;
                        joinedCells.Value = string.IsNullOrEmpty(cell.Value.ToString()) ? string.Empty : cell.Value;
                    }
                }
            }
        }

        workbook.Save();
        app.Quit();


Attachment: mort_rates.rar