public ExcelNotifyPropertyManager(ExcelApplication excelApplication) { contextItems = new BlockingCollection <ExcelNotityPropertyContext>(); ExcelApplication = excelApplication; thread = new Thread(Execute); thread.Name = "NotifyPropertiesChanged"; thread.IsBackground = true; thread.Start(); }
public void ClearRange(ExcelInterop.Range from, ExcelInterop.Range to, ExcelInterop.Range with) { if (from == null) { return; } ExcelInterop.Worksheet concernedSheet = null; bool isProtected = false; try { concernedSheet = from.Worksheet; isProtected = concernedSheet.ProtectContents; if (isProtected) { concernedSheet.Unprotect(Type.Missing); } if (to == null) { to = concernedSheet.UsedRange; } from = from.Resize[to.Rows.Count - from.Rows.Count - 1, to.Columns.Count - from.Columns.Count - 1]; from.Clear(); if (with != null) { ExcelInterop.Interior withInterior = with.Interior; ExcelInterop.Font withFont = with.Font; ExcelInterop.Interior interior = from.Interior; ExcelInterop.Font font = from.Font; font.Color = withFont.Color; interior.Color = withInterior.Color; ExcelApplication.ReleaseComObject(interior); ExcelApplication.ReleaseComObject(font); ExcelApplication.ReleaseComObject(withInterior); ExcelApplication.ReleaseComObject(withFont); interior = null; font = null; withInterior = null; withFont = null; } } catch { if (concernedSheet != null) { ExcelApplication.ReleaseComObject(concernedSheet); } } finally { if (concernedSheet != null && isProtected) { ProtectSheet(concernedSheet); } } }