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