/// <summary> /// Освобождение объекта MS Excel /// </summary> /// <param name="bEnded"></param> protected void dispose(bool bEnded) { if (_newInstance == TYPE_INSTANCE.NEW) { CloseExcelAllDocs(); } else { ; } Range = null; WorkSheet = null; WorkSheets = null; WorkBook = null; WorkBooks = null; Marshal.ReleaseComObject(oExcel); if (bEnded == true) { _newInstance = TYPE_INSTANCE.UNKNOWN; oExcel = null; GC.GetTotalMemory(true); } else { ; } }
/// <summary> /// Создать объект для работы с COM-приложением /// </summary> /// <param name="typeInstance">Тип экземпляра COM-приложения</param> /// <returns>Объект с экземпляром COM-приложения</returns> public static object Create(out TYPE_INSTANCE typeInstance) { object objRes = null; try { objRes = System.Runtime.InteropServices.Marshal.GetActiveObject(UID); typeInstance = TYPE_INSTANCE.ACTIVE; } catch { try { objRes = Activator.CreateInstance(Type.GetTypeFromProgID(UID)); typeInstance = TYPE_INSTANCE.NEW; } catch (Exception e2) { typeInstance = TYPE_INSTANCE.ERROR; Logging.Logg().Exception(e2, string.Format("MSExcelIO::Create () - ..."), Logging.INDEX_MESSAGE.NOT_SET); } } return(objRes); }