public void Run() { // NetOffice Core supports so-called managed C# dynamic // with proxy management services. No need for additional NetOffice Api assemblies. // NetOffice want convert a proxy to COMDynamicObject each time if its failed to resolve // a corresponding wrapper type. // Note: Reference to Microsoft.CSharp is required. dynamic application = new COMDynamicObject("Excel.Application"); application.DisplayAlerts = false; var book = application.Workbooks.Add(); foreach (var sheet in book.Sheets) { Console.WriteLine(sheet); } // quit and dispose all open proxies application.Quit(); application.Dispose(); // -- no proxies open anymore -- HostApplication.ShowFinishDialog(); }
internal void Run() { dynamic application = new COMDynamicObject("Excel.Application"); application.DisplayAlerts = false; var book = application.Workbooks.Add(); Excel.Workbook convertedBook = book as Excel.Workbook; Console.WriteLine("book converted {0}", null != convertedBook); foreach (var sheet in book.Sheets) { Console.WriteLine(sheet); } application.Quit(); application.Dispose(); }
internal void Test() { try { Type wordType = System.Type.GetTypeFromProgID("Word.Application", true); object interopProxy = Activator.CreateInstance(wordType); COMDynamicObject.TryConvertFailResult = true; dynamic application = new COMDynamicObject(interopProxy); application.Visible = true; application.DisplayAlerts = 0; var document = application.Documents.Add(); application.Selection.TypeText("Hello World"); int left = 0; int top = 0; int width = 0; int height = 0; dynamic window = application.ActiveWindow; dynamic range = application.Selection.Range; window.GetPoint(out left, out top, out width, out height, range); MessageBox.Show(string.Format("GetPoint returns Left:{0} Top:{1} Width:{2} Height:{3}", left, top, width, height)); document.Saved = true; application.Quit(); application.Dispose(); } catch (Exception exception) { Console.WriteLine(exception); } Console.WriteLine("Press any key."); Console.ReadKey(); }