I am reading an Excel file in the following way and it works for me, but I always get this dialog that tells me if I want to save changes.
What can I do so that it does not appear?
C# code:
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;
}
Dialog I need to remove:
The problem is probably solved with a simple
which prevents warnings from appearing during the time you have the application instance open.