internal void Execute() { //Check target files. var files = GetTargetFiles(); if (files.Count == 0) { throw new ApplicationException(String.Format(Resource.NO_TARGET_FOUND)); } //Init excel, word, powerpoint. using (var excel = new ComWrapper <Excel.Application>(new Excel.Application() { Visible = false, DisplayAlerts = false })) using (var books = new ComWrapper <Excel.Workbooks>(excel.ComObject.Workbooks)) using (var word = new ComWrapper <Word.Application>(new Word.Application() { Visible = false, DisplayAlerts = Word.WdAlertLevel.wdAlertsNone })) using (var docs = new ComWrapper <Word.Documents>(word.ComObject.Documents)) using (var powerPoint = new ComWrapper <PowerPoint.Application>(new PowerPoint.Application() { DisplayAlerts = PowerPoint.PpAlertLevel.ppAlertsNone })) using (var ppts = new ComWrapper <PowerPoint.Presentations>(powerPoint.ComObject.Presentations)) { try { foreach (var file in files) { try { ConsoleLogger.WriteLog(String.Format(Resource.EXTRACTING_TEXT_PATH_ARG0, file)); if (IsExcel(file)) { ExportExcel(file, books); } else if (IsWord(file)) { ExportWord(file, docs); } else if (IsPowerPoint(file)) { ExportPowerPoint(file, ppts); } } catch (COMException e) { ConsoleLogger.WriteWarning(String.Format(Resource.SKIPPED_EXTRACTING_TEXT_PATH_ARG0_DETAILS_ARG1, file, e.ToString())); this.hasWarning = true; } } } finally { try { books.ComObject.Close(); } catch (Exception e) { ConsoleLogger.WriteError(e.ToString()); } try { excel.ComObject.Quit(); } catch (Exception e) { ConsoleLogger.WriteError(e.ToString()); } //No need to close docs, because there is no opened file.(And an error occurrs when closing here.) try { word.ComObject.Quit(); } catch (Exception e) { ConsoleLogger.WriteError(e.ToString()); } try { powerPoint.ComObject.Quit(); } catch (Exception e) { ConsoleLogger.WriteError(e.ToString()); } } } }