C# Interop print and close Excel file -


have problem interop , editing existing excel file. excel app doesn't want close. if set code, when edit cells, comment, rest of code work need - excel open , after print dialog close.

excel.application excelapp = null; excel.workbook excelworkbook = null; excel.worksheet excelworksheet = null;  string workbookpath = ""; if (rbtype1.checked == true) { workbookpath = path.getfullpath("excel/mesto.xls"); } else if (rbtype2.checked == true) { workbookpath = path.getfullpath("excel/ulehly.xls"); } else if (rbtype3.checked == true) { workbookpath = path.getfullpath("excel/spolecenstvi.xls"); } else if (rbtype4.checked == true) { workbookpath = path.getfullpath("excel/vlastnici.xls"); }  excelapp = new excel.application(); excelapp.visible = true;  excelworkbook = excelapp.workbooks.open(workbookpath, 0, false, 5, "", "", true, excel.xlplatform.xlwindows, "\t", false, false, 0, true, 1, 0); excelworksheet = (excel.worksheet)excelworkbook.worksheets.get_item(1);   excelworksheet.cells[4, "j"] = requisitionnumberbox.text; excelworksheet.cells[9, "c"] = applicantbox.text; excelworksheet.cells[9, "g"] = streetbox.text; excelworksheet.cells[9, "j"] = cpboxc.text; excelworksheet.cells[10, "j"] = cbbox.text; excelworksheet.cells[11, "d"] = ctbox.text; excelworksheet.cells[11, "g"] = contactpersonbox.text; excelworksheet.cells[14, "b"] = repairbox.text; excelworksheet.cells[20, "b"] = itembox.text; if (pmoption1.checked == true) { excelworksheet.cells[23, "d"] = "x"; } if (pmoption2.checked == true) { excelworksheet.cells[24, "d"] = "x"; } excelworksheet.cells[23, "f"] = issuedate.text;  excelapp.dialogs[excel.xlbuiltindialog.xldialogprint].show();  excelworkbook.close(false, type.missing, type.missing); excelapp.quit();  releaseobject(excelworksheet); releaseobject(excelworkbook); releaseobject(excelapp); 

releaseobject code (found on internet)

try {      system.runtime.interopservices.marshal.releasecomobject(obj);      obj = null; } catch (exception ex) {      obj = null;      messagebox.show("unable release object " + ex.tostring()); } {      gc.collect(); } 

how should edit code, close excel when program edits cells?


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -