How to close an Excel application in C #

Asked

Viewed 79 times

-1

I have this c# function that converts an excel file into another excel format, the problem is that when the application runs it does not end with the _app quit function.();

The excel application is started in this code snippet: var _app = new Excel.Application();

It starts three processes:

Gerenciador de tarefas - processo

I don’t have Excel installed on my machine, I use WPS Oficce 2019, an alternative, free software.

How do I close this application?

    private void Convert_CSV_To_Excel()
{
    try
    {
        // Rename .csv To .xlsm
        System.IO.File.Move(File, File);

        var _app = new Excel.Application();
        var _workbooks = _app.Workbooks;

        _workbooks.OpenText(File,
                                 DataType: Excel.XlTextParsingType.xlDelimited,
                                 TextQualifier: Excel.XlTextQualifier.xlTextQualifierNone,
                                 ConsecutiveDelimiter: true,
                                 Semicolon: true);

        // Convert To Excle 97 / 2003
        _workbooks[1].SaveAs(File + "OK.xlsm", Excel.XlFileFormat.xlOpenXMLWorkbookMacroEnabled);
        _workbooks.Close();
        _app.Quit();
    }

1 answer

3

_workbooks.Close(0);
_app.Quit();

or else

_workbooks.Close(true);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.