private static void KillExcel() { Process[] AllProcesses = Process.GetProcessesByName("excel"); foreach (Process ExcelProcess in AllProcesses) { ExcelProcess.Kill(); } }
/* Zabijamy proces ktory nie znajduje sie w hashtable */ public void killExcel(int processID) { Process[] AllProcesses = Process.GetProcessesByName("excel"); foreach (Process ExcelProcess in AllProcesses) { if (ExcelProcess.Id == processID) { ExcelProcess.Kill(); } } }
public static void KillExcel() { Process[] AllProcesses = Process.GetProcessesByName("excel"); foreach (Process ExcelProcess in AllProcesses) { ExcelProcess.Kill(); } AllProcesses = null; }
/// <summary> /// Metodo che chiude tutti i processi Excel attivi /// </summary> /// public void KillExcel() { Process[] AllProcesses = Process.GetProcessesByName("excel"); // Fai un check per Killare tutti i processi Excel foreach (Process ExcelProcess in AllProcesses) { //if (myHashtable.ContainsKey(ExcelProcess.Id) == true) ExcelProcess.Kill(); } AllProcesses = null; }
/// <summary> /// This method kills excel process. /// </summary> private void KillExcel() { Process[] AllProcesses = Process.GetProcessesByName("excel"); // check to kill the right process foreach (Process ExcelProcess in AllProcesses) { if (_myHashtable.ContainsKey(ExcelProcess.Id) == false) { ExcelProcess.Kill(); } } AllProcesses = null; }
public static void KillExcel() { Process[] AllProcesses = Process.GetProcessesByName("excel"); foreach (Process ExcelProcess in AllProcesses) { if (myHashtable.ContainsKey(ExcelProcess.Id) == false) { ExcelProcess.Kill(); } } AllProcesses = null; openExcel(); }
private void KillExcel() { Process[] AllProcesses = Process.GetProcessesByName("excel"); // check to kill the right process foreach (Process ExcelProcess in AllProcesses) { if (myHashtable.ContainsKey(ExcelProcess.Id) == true) { ExcelProcess.Kill(); } } Console.Beep(2000, 1000); AllProcesses = null; }
public void KillExcel(ref Microsoft.Office.Interop.Excel.Application application) { if (application != null) { uint ExcelPID = 0; int Hwnd = 0; Hwnd = application.Hwnd; System.Diagnostics.Process ExcelProcess; GetWindowThreadProcessId((IntPtr)Hwnd, out ExcelPID); ExcelProcess = System.Diagnostics.Process.GetProcessById((int)ExcelPID); ExcelProcess.Kill(); System.Runtime.InteropServices.Marshal.ReleaseComObject(application); application = null; } }
void KillExcelProcessThatUsedByThisInstance() { Process[] AllProcesses = Process.GetProcessesByName("EXCEL"); foreach (Process ExcelProcess in AllProcesses) { if (myHashtable == null) { return; } if (ExcelProcess.Id == MyExcelProcessId) { ExcelProcess.Kill(); } } AllProcesses = null; }
public void KillExcel() // Kill excel's process method { // Quit the Excel Application //exApp.Quit(); Process[] AllProcesses = Process.GetProcessesByName("excel"); // check to kill the right process foreach (Process ExcelProcess in AllProcesses) { if (myHashtable.ContainsKey(ExcelProcess.Id) == false) { ExcelProcess.Kill(); } } AllProcesses = null; EndStamp(); }
private void Clear() { Process[] AllProcesses = Process.GetProcessesByName("excel"); // check to kill the right process foreach (Process ExcelProcess in AllProcesses) { try { if (new Hashtable().ContainsKey(ExcelProcess.Id) == false) { ExcelProcess.Kill(); } } catch (Win32Exception) { } } AllProcesses = null; }
public bool ImportFidersFile() { this.Cursor = Cursors.WaitCursor; int i = 1; int ImportCount = 0; bool result = true; //ExcelTools.CheckExcellProcesses(); Excel.Application ExcelImportFile = new Excel.Application { DisplayAlerts = false }; Excel.Workbook workbook = null; Excel.Worksheet worksheet = null; try { // Открываем книгу из папки с запускаемым файлом workbook = ExcelImportFile.Workbooks.Open(eImportFile.Text); // Получаем первую таблицу worksheet = workbook.ActiveSheet as Excel.Worksheet; while (true) { i++; string FiderName = worksheet.Cells[i, 1].Text; if (FiderName == "") { break; } string TP = worksheet.Cells[i, 2].Text; if (TP == "") { TP = "0"; } string SZO = worksheet.Cells[i, 3].Text; if (SZO == "") { SZO = "0"; } string NP = worksheet.Cells[i, 4].Text; if (NP == "") { NP = "0"; } string population = worksheet.Cells[i, 5].Text; if (population == "") { population = "0"; } //Новое в версии 1.0.4.0 string P_load_l = worksheet.Cells[i, 6].Text; if (P_load_l == "") { P_load_l = "0,000"; } string P_load_z = worksheet.Cells[i, 7].Text; if (P_load_z == "") { P_load_z = "0,000"; } int FiderType = cbTypeVL.SelectedIndex; if (Mysql.FindFiderInBase(FiderName)) { MessageBox.Show("В базе уже содержится " + FiderName + "\nДобавить объект с таким же именем невозможно!"); } else { if (!Mysql.AddNewFiderInBase(FiderName, FiderType, Config.Reses[cbRes.Text].Id, Config.Companies[cbCompany.Text].Id, Convert.ToInt32(TP), Convert.ToInt32(SZO), Convert.ToInt32(NP), Convert.ToInt32(population), Convert.ToDecimal(P_load_l), Convert.ToDecimal(P_load_z))) { MessageBox.Show("Ошибка при импорте объекта - " + FiderName); break; } else { ImportCount++; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); result = false; } finally { MessageBox.Show("Импортировано - " + ImportCount.ToString() + " объектов"); workbook.Close(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(worksheet); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(workbook); ////Подготовка к убийству процесса Excel int ExcelPID = 0; int Hwnd = 0; Hwnd = ExcelImportFile.Hwnd; System.Diagnostics.Process ExcelProcess; GetWindowThreadProcessId((IntPtr)Hwnd, out ExcelPID); ExcelProcess = System.Diagnostics.Process.GetProcessById(ExcelPID); ////Конец подготовки к убийству процесса Excel ExcelImportFile.Quit(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ExcelImportFile); GC.Collect(); GC.WaitForPendingFinalizers(); ////Убийство процесса Excel ExcelProcess.Kill(); ExcelProcess = null; //ExcelTools.KillExcel(); this.Cursor = Cursors.Default; } return(result); }
public static void KillProcess() { try { int l = 0; int m = 0; Array.Resize(ref dup_process, 0); if (s_process.Length > 0) { int i = 0; //for (int i = 0; i < e_process.Length; i++) foreach (Process EndProcess in e_process) { m = 0; //for (int k = 0; k < s_process.Length; k++) foreach (Process StartProcess in s_process) { if (StartProcess.Id == EndProcess.Id) { m = 0; break; } else { m++; } } if (m > 0) { Array.Resize(ref dup_process, dup_process.Length + 1); dup_process[l] = e_process[i]; l++; } i++; } } else { for (int i = 0; i < e_process.Length; i++) { Array.Resize(ref dup_process, dup_process.Length + 1); dup_process[l] = e_process[i]; l++; } } myHashtable = new Hashtable(); int iCount = 0; foreach (Process ExcelProcess in dup_process) { myHashtable.Add(ExcelProcess.Id, iCount); iCount = iCount + 1; } foreach (Process ExcelProcess in dup_process) { try { if (myHashtable.ContainsKey(ExcelProcess.Id) == true) { ExcelProcess.Kill(); } } catch (Exception) { } } dup_process = null; s_process = null; e_process = null; } catch (Exception) { } }
public bool ImportMastersFile() { this.Cursor = Cursors.WaitCursor; int i = 1; int ImportCount = 0; bool result = true; //ExcelTools.CheckExcellProcesses(); Excel.Application ExcelImportFile = new Excel.Application { DisplayAlerts = false }; Excel.Workbook workbook = null; Excel.Worksheet worksheet = null; try { // Открываем книгу из папки с запускаемым файлом workbook = ExcelImportFile.Workbooks.Open(eImportFile.Text); // Получаем первую таблицу worksheet = workbook.ActiveSheet as Excel.Worksheet; while (true) { i++; string fio = worksheet.Cells[i, 1].Text; string dol = worksheet.Cells[i, 2].Text; string tel = worksheet.Cells[i, 3].Text; if ((fio == "") || (dol == "") || (tel == "")) { break; } if (Mysql.FindMasterInBase(fio)) { string addition = "(число)"; for (int add = 1; add < 99999; add++) { addition = "(" + add.ToString() + ")"; if (!Mysql.FindMasterInBase(fio + addition)) { break; } } MessageBox.Show("Работник " + fio + " уже содержится в базе.\nВ базу " + fio + " будет импортирован под именем - " + fio + addition + "\nВ Форму 4 данный работник будет выгружен без дополнения '" + addition + "'"); fio += addition; if (!Mysql.AddNewMasterInBase(fio, dol, tel, ResId, Config.Companies[cbCompany.Text].Id)) { MessageBox.Show("Ошибка при импорте работника - " + fio); break; } else { ImportCount++; } } else { if (!Mysql.AddNewMasterInBase(fio, dol, tel, ResId, Config.Companies[cbCompany.Text].Id)) { MessageBox.Show("Ошибка при импорте работника - " + fio); break; } else { ImportCount++; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); result = false; } finally { MessageBox.Show("Импортировано - " + ImportCount.ToString() + " работников"); workbook.Close(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(worksheet); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(workbook); ////Подготовка к убийству процесса Excel int ExcelPID = 0; int Hwnd = 0; Hwnd = ExcelImportFile.Hwnd; System.Diagnostics.Process ExcelProcess; GetWindowThreadProcessId((IntPtr)Hwnd, out ExcelPID); ExcelProcess = System.Diagnostics.Process.GetProcessById(ExcelPID); ////Конец подготовки к убийству процесса Excel ExcelImportFile.Quit(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ExcelImportFile); GC.Collect(); GC.WaitForPendingFinalizers(); ////Убийство процесса Excel ExcelProcess.Kill(); ExcelProcess = null; //ExcelTools.KillExcel(); this.Cursor = Cursors.Default; } return(result); }
public ActionResult LoadCatalogOfItems(HttpPostedFileBase file) { Excel.Workbook xlsBook = null; Excel.Workbooks xlsBooks = null; Excel.Application newApp = null; Excel._Worksheet xlsSheet = null; Hashtable myHashtable = null; try { Process[] AllProcesses = Process.GetProcessesByName("excel"); myHashtable = new Hashtable(); int iCount = 0; foreach (Process ExcelProcess in AllProcesses) { myHashtable.Add(ExcelProcess.Id, iCount); iCount = iCount + 1; } List <Item> list = new List <Item>(); List <bool> results = new List <bool>(); List <List <string> > values = new List <List <string> >(); newApp = new Excel.Application(); file.SaveAs(Server.MapPath("~/Files/" + file.FileName)); xlsBooks = newApp.Workbooks; xlsBook = xlsBooks.Open(Server.MapPath("~/Files/" + file.FileName)); xlsSheet = xlsBook.Sheets[1]; Excel.Range xlRange = xlsSheet.UsedRange; int rowCount = xlRange.Rows.Count; for (int i = 1; i <= rowCount; i++) { values.Add(new List <string>()); if (xlRange.Cells.Item[1][i] != null) { values[i - 1].Add(xlRange.Cells.Item[1][i].Value.ToString()); } else { values[i - 1].Add(String.Empty); } if (xlRange.Cells[2][i].Value != null) { values[i - 1].Add(xlRange.Cells[2][i].Value.ToString()); } else { values[i - 1].Add(String.Empty); } if (xlRange.Cells[3][i].Value != null) { values[i - 1].Add(xlRange.Cells.Item[3][i].Value.ToString()); } else { values[i - 1].Add(String.Empty); } if (xlRange.Cells[4][i].Value != null) { values[i - 1].Add(xlRange.Cells.Item[4][i].Value.ToString()); } else { values[i - 1].Add(String.Empty); } if (xlRange.Cells[5][i].Value != null) { values[i - 1].Add(xlRange.Cells.Item[5][i].Value.ToString()); } else { values[i - 1].Add(String.Empty); } if (String.Compare(values[i - 1][0], "") == 0) { break; } results.Add(false); Item item = new Item(); int pN = 0; if (!int.TryParse(values[i - 1][0], out pN)) { continue; } item.partNumber = pN; int cId = 0; if (int.TryParse(values[i - 1][1], out cId)) { if (repository.GetCategory(cId) != null) { item.categoryId = cId; } } else if (repository.GetCategories().Any(c => String.Compare(c.title, values[i - 1][1]) == 0)) { item.categoryId = repository.GetCategories() .Where(c => String.Compare(c.title, values[i - 1][1]) == 0).FirstOrDefault().id; } else { continue; } item.title = values[i - 1][2]; item.description = values[i - 1][3]; item.image = values[i - 1][4]; results[results.Count - 1] = true; list.Add(item); } repository.AddItems(list); ViewBag.CorrectFlags = results; ViewBag.Cells = values; ViewBag.Title = "Создание категории"; ViewBag.isRedactorView = true; return(View(values)); } finally { Process[] AllProcesses = Process.GetProcessesByName("excel"); // check to kill the right process foreach (Process ExcelProcess in AllProcesses) { if (myHashtable.ContainsKey(ExcelProcess.Id) == false) { ExcelProcess.Kill(); } } AllProcesses = null; } }