Hi,
I did all my best to remove Excel:
book.Close(true,miss,miss);
excel.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
but from the Windows Task Manager I can see EXCEL.EXE still there until I stoped the program. What I was missing?
Following is the full code:
private void button1_Click(object sender, EventArgs e)
{
Excel.Application excel = new Excel.Application();
Excel.Range range;
object miss = System.Reflection.Missing.Value;
//excel.Visible = true;
string fileName = Application.StartupPath + "\\Book1.xlsx";
Excel.Workbook book = excel.Workbooks.Open(fileName, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss);
Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1];
range = (Excel.Range)sheet.Cells[1, 1];
MessageBox.Show(range.Font.Name.ToString());
MessageBox.Show(range.Font.Size.ToString());
book.Close(true,miss,miss);
excel.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
}
Thank you in advance.
I did all my best to remove Excel:
book.Close(true,miss,miss);
excel.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
but from the Windows Task Manager I can see EXCEL.EXE still there until I stoped the program. What I was missing?
Following is the full code:
private void button1_Click(object sender, EventArgs e)
{
Excel.Application excel = new Excel.Application();
Excel.Range range;
object miss = System.Reflection.Missing.Value;
//excel.Visible = true;
string fileName = Application.StartupPath + "\\Book1.xlsx";
Excel.Workbook book = excel.Workbooks.Open(fileName, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss);
Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1];
range = (Excel.Range)sheet.Cells[1, 1];
MessageBox.Show(range.Font.Name.ToString());
MessageBox.Show(range.Font.Size.ToString());
book.Close(true,miss,miss);
excel.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
}
Thank you in advance.