Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Interop print and close Excel file
    primarykey
    data
    text
    <p>have problem with interop and editing existing excel file. Excel app doesn't want to close. If I set code, when I edit cells, as comment, rest of code work as I need - Excel open and after print dialog close.</p> <pre><code>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); </code></pre> <p>releaseObject code (found this on internet)</p> <pre><code>try { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); obj = null; } catch (Exception ex) { obj = null; MessageBox.Show("Unable to release the Object " + ex.ToString()); } finally { GC.Collect(); } </code></pre> <p>How I should edit this code, that it close Excel when program edits cells?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload