2

Estoy leyendo un archivo Excel de la siguiente forma y me funciona, pero siempre me sale este dialogo que me indica si deseo guardar cambios.

¿Qué puedo hacer para que no me aparezca?

Código C#:

public List<Person> LeerArchivo(string pathArchivo , IEngineTool Tool)
        {
            Person p = new Person();
            List<Person> lp = new List<Person>();
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(pathArchivo);
            Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;
            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;
            string strValue = string.Empty;

            for (int fila  = 2; fila <= rowCount; fila++)
            {
                for (int columna = 1; columna <= colCount; columna++)
                {
                    if (xlRange.Cells[fila, columna] != null && xlRange.Cells[fila, columna].Value != null)
                        strValue = strValue + xlRange.Cells[fila, columna].Value.ToString()  + "#" ;
                    else
                        strValue = strValue + "NO_DEFINIDO" + "#";
                }
                p=SetPerson(strValue);
                strValue = string.Empty;
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            Marshal.ReleaseComObject(xlRange);
            Marshal.ReleaseComObject(xlWorksheet);
            xlWorkbook.Close();
            Marshal.ReleaseComObject(xlWorkbook);
            xlApp.Quit();
            Marshal.ReleaseComObject(xlApp);

            return lp;
        }

Dialogo que nesecito eliminar:

introducir la descripción de la imagen aquí

1 respuesta 1

3

Probablemente el problema se soluciona con un simple

Excel.Application.DisplayAlerts = false;

que evita que aparezcan avisos durante el tiempo en el que tienes la instancia de la aplicación abierta.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.