Opening and Navigating Excel with C# - Removing dialogs






3.50/5 (3 votes)
Remove dialogs
Introduction
Take a look at the article below first. The only thing I'm adding here is how to remove dialogs... since I couldn't find that anywhere online.
Code
Error: The problem is that every time I run it, a message box comes up saying: "'example.xls' is being modified by johndoe. Open as read-only?"
Solution:
Before opening the Excel file, run this code:
excelApp.DisplayAlerts = false;
So, the entire code would look like this:
Microsoft.Office.Interop.Excel.Workbook workbook;
Microsoft.Office.Interop.Excel.ApplicationClass excelApp =
new Microsoft.Office.Interop.Excel.ApplicationClass();
excelApp.DisplayAlerts = false;
workbook = excelApp.Workbooks.Open(
filename,
ExcelLib.XlUpdateLinks.xlUpdateLinksAlways,
ReadOnly, 5, Type.Missing, Type.Missing, true,
ExcelLib.XlPlatform.xlWindows, Type.Missing,
true, false, Type.Missing, false, false,
ExcelLib.XlCorruptLoad.xlNormalLoad
);
And that's all I wanted to add. (Note, the linked article isn't allowing me to post, otherwise I'd have thrown a message up there on it.)