Hi I tried it again and still get the same result (excel opens for a second and closes)
private void button1_Click(object sender, EventArgs e)
{
Excel.Application spreadsheet = new Excel.Application();
spreadsheet.Visible = false;
Excel.Workbook excelWorkbook = spreadsheet.Workbooks.Open(location workbook);
excelWorkbook.Close();
spreadsheet.Quit();
}
how to stop excel from appearing when opening in c# using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel; i open the excel file using Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(location/filename);
when i use this the file opens and i would like for that not to happen and for the program to read the excel file in the background. I tried
lApp.Visible = false;
xlApp.DisplayAlerts = false;
before the Open statement but it still appears.
3 answers
Sort by: Most helpful
-
Richard collier 1 Reputation point
2022-06-15T13:29:33.413+00:00 -
Karen Payne MVP 35,036 Reputation points
2022-06-15T19:17:44.757+00:00 Usually one needs to make more of an effort for what they want out of Excel via automation rather than Open XML.
I invite you to examine the following code which I've used the pattern shown and never had your issue plus the code ensure (unless there is a runtime exception) all objects are released used.
-
Richard collier 1 Reputation point
2022-06-20T14:34:13.867+00:00 Sorry for the delay i believe my issue was not adding the visible=false till after i had the range done