for my application I am calling an excel file to read or write data, which is working fine, but I did notice that there are 'Microsoft Excell' processes piling up in my task manager. Although this does not seem to impact the application, it will impact my pc's speed in the long run.
I tried to close excell using the .Quit() method, but this only appears to exit the session while still leaving the process in place.
Here is the context in which I am calling excell:
While reading data:
public List<string> GetLeverancierInfo(int Index)
{
List<string> Output = new List<string>();
int Positie = 0;
bool DataGrabbing = true;
DataSheet DataSheet = new DataSheet(@"C:\Users\Melvin\source\repos\ShopITScanner\Shop-IT FactuurScanner\Properties\Resources\DataFile.xlsx", 1);
while (DataGrabbing)
{
string HuidigeCell = DataSheet.ReadCell(Form1.nieuwBedrijf.BedrijfsIndex, Positie);
if(HuidigeCell != null)
{
Output.Add(HuidigeCell);
Positie++;
}
else
{
DataGrabbing = false;
}
}
DataSheet.Exit();
return Output;
}
The DataSheet.ReadCell() method is as follows:
public string ReadCell(int X, int Y)
{
X++;
Y++;
if(ProductSheet.Cells[X, Y].Value2 != null)
{
return ProductSheet.Cells[X, Y].Value2;
}
else
{
return null;
}
}
The code for writing to Excell:
public void SetLeverancierInfo(List<string> Attributen)
{
DataSheet DataSheet = new DataSheet(@"C:\Users\Melvin\source\repos\ShopITScanner\Shop-IT FactuurScanner\Properties\Resources\DataFile.xlsx", 1);
int YPositie = 0;
int XPositie = 0;
foreach(string Attribuut in Attributen)
{
bool Added = false;
while (!Added)
{
if (DataSheet.ReadCell(XPositie, YPositie) == null)
{
DataSheet.WriteCell(XPositie, YPositie, Attribuut);
Added = true;
}
else
{
XPositie++;
}
}
YPositie++;
}
DataSheet.Exit();
}
The code for DataSheet.WriteCell() is as follows:
public void WriteCell(int X, int Y, string S)
{
X++;
Y++;
if(ProductSheet.Cells[X, Y].Value2 == null)
{
ProductSheet.Cells[X, Y].Value2 = S;
}
else
{
if(MessageBox.Show("Met de volgende operatie worden uw instellingen overgeschreven. \nDit kan niet ongedaan gemaakt worden. \nWeet u het zeker?", "Waarschuwing", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
ProductSheet.Cells[X, Y].Value2 = S;
}
}
DataFile.Save();
}
And lastly when I finished my operations with Excell I run this:
public void Exit()
{
Excel.Quit();
}
When using the .Quit() method, I assumed it would get rid of the entire excell process, but in reality that is not happening. I am not getting errors either, except for an occasional "file is opened by another process" message, which is logical when the processes aren't killed.