I have a C# program in which I read data from an excel file that contains about 40000 numbers. This is a part of my code:
Microsoft.Office.Interop.Excel.Application _excelApp = new Microsoft.Office.Interop.Excel.Application();
_excelApp.Visible = true;
string fileName = "D:\\data.xlsx";
Workbook workbook = _excelApp.Workbooks.Open(fileName, Type.Missing);
Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
Range excelRange = worksheet.UsedRange;
Object[,] valueArray = (object[,])excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);
int num = worksheet.UsedRange.Rows.Count;
workbook.Close(false, Type.Missing);
_excelApp.Quit();
for (int row = 1; row <= num; ++row)
{
data1.Add(Convert.ToDouble(valueArray[row, 1]));
data2.Add(Convert.ToDouble(valueArray[row, 2]));
}
Every time I run the program, the excel file appears for a moment and is closed. But there are some opened excel file in the background process of windows, and consume ram and reduce speed of windows. How can I completely close excel file and quit them from the memory in my code?
Thank you.