Beispiel #1
0
        public void RunExample()
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = new Outlook.Application(true);

            // SendAndReceive is supported from Outlook 2007 or higher
            // we check at runtime the feature is available
            if (outlookApplication.Session.EntityIsAvailable("SendAndReceive"))
            {
                // one simple call
                outlookApplication.Session.SendAndReceive(false);
            }
            else
            {
                HostApplication.ShowErrorDialog("This version of MS-Outlook doesnt support SendAndReceive.", null);
            }

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();

            HostApplication.ShowFinishDialog("Done!", null);
        }
Beispiel #2
0
        public void Run()
        {
            // Replace Excel.Workbook with MyWorkbook
            NetOffice.Core.Default.ObjectActivator.CreateInstance += delegate(Core sender, NetOffice.CoreServices.OnCreateInstanceEventArgs args)
            {
                if (args.RequestedFrom.ContractType == typeof(Excel.Workbook))
                {
                    args.Replace = new MyWorkbook();
                }
            };

            Excel.Application application = new Excel.ApplicationClass();
            application.DisplayAlerts = false;

            // add and cast book to MyWorkbook
            MyWorkbook book = application.Workbooks.Add() as MyWorkbook;

            if (book.Has3Sheets)
            {
                Console.WriteLine("Book has 3 sheets.");
            }

            application.Quit();
            application.Dispose();

            HostApplication.ShowFinishDialog();
        }
Beispiel #3
0
        public void RunExample()
        {
            // start outlook by trying to access running application first
            // if its failed to resolve a running instance, we create a new one here
            Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <Outlook.Application>();

            // create a new TaskItem.
            Outlook.TaskItem newTask = outlookApplication.CreateItem(OlItemType.olTaskItem) as Outlook.TaskItem;

            // Configure the task at hand and save it.
            newTask.Subject    = "Don't forget to check for NoScript updates";
            newTask.Body       = "check updates here: https://addons.mozilla.org/de/firefox/addon/noscript";
            newTask.DueDate    = DateTime.Now;
            newTask.Importance = OlImportance.olImportanceHigh;
            newTask.Save();

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();

            HostApplication.ShowFinishDialog("Done!", null);
        }
Beispiel #4
0
        public void Run()
        {
            // NetOffice instances implements the IClonable interface
            // and deal with underlying proxies as well

            Excel.Application application = new Excel.ApplicationClass();
            application.DisplayAlerts = false;
            Excel.Workbook book = application.Workbooks.Add();

            // clone the book
            Excel.Workbook cloneBook = book.Clone() as Excel.Workbook;

            // dispose the origin book keep the underlying proxy alive
            // until the clone is disposed
            book.Dispose();

            // alive and works even the origin book is disposed
            foreach (Excel.Worksheet sheet in cloneBook.Sheets)
            {
                Console.WriteLine(sheet);
            }

            application.Quit();
            application.Dispose();

            HostApplication.ShowFinishDialog();
        }
Beispiel #5
0
        public void Run()
        {
            /*
             *  NetOffice provides features to compare 2 proxies directly on server.
             *
             *  2 proxies may different instances but pointing to the same instance on the com server(the office application)
             *
             *  This is a showstopper to demonstrate a deep comparison.
             *
             *  -------------------------------------------------------
             *  Former NetOffice versions spend operator overloads here.
             *  This is impossible in NetOffice 2.0 and above because
             *  NetOffice 2.0 use interfaces instead of classes.
             *
             */

            using (var application = COMObject.Create <Excel.Application>())
            {
                application.DisplayAlerts = false;
                Excel.Workbook book = application.Workbooks.Add();

                bool isEqual = false;

                // determine active workbook is the same as book1 on the server
                isEqual = application.ActiveWorkbook.EqualsOnServer(book);

                // another static version to do the same
                isEqual = COMObject.EqualsOnServer(application.ActiveWorkbook, book);

                application.Quit();
            }

            HostApplication.ShowFinishDialog();
        }
Beispiel #6
0
        public void RunExample()
        {
            // start excel and turn off msg boxes
            Excel.Application excelApplication = new Excel.Application();
            excelApplication.DisplayAlerts = false;

            // create a utils instance, not need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(excelApplication);

            // add a new workbook
            //Excel.Workbook workBook = excelApplication.Workbooks.Add();
            Excel.Workbook  workBook  = excelApplication.Workbooks.Open(@"C:\Users\Gilbert Perlaza\Dropbox\HPC\MttoApp\Docs\FORMATO EWO EN BLANCO UNIFICADO OT.XLSX");
            Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1];

            workSheet.Cells[1, 1].Value = "NetOffice Excel Example 04";

            // create a star
            Excel.Shape starShape = workSheet.Shapes.AddShape(MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20);

            // create a simple textbox
            Excel.Shape textBox = workSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50);
            Excel.Shape rb      = workSheet.Shapes.AddFormControl(Excel.Enums.XlFormControl.xlOptionButton, 100, 100, 100, 100);

            var sh = workSheet.Shapes;

            foreach (var item in sh)
            {
                if (item.Name.Equals("Option Button 1"))
                {
                    item.ControlFormat.Value = 1;
                }
            }
            rb.TextFrame.Characters().Text = "Hola prueba";
            rb.ControlFormat.Value = 0;
            textBox.TextFrame.Characters().Text = "text";
            textBox.TextFrame.Characters().Font.Size = 14;

            // create a wordart
            Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12,
                                                                    MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250);

            // create text effect
            Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14,
                                                                     MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350);

            // save the book
            string workbookFile = utils.File.Combine(HostApplication.RootDirectory, "Example04", DocumentFormat.Normal);

            workBook.SaveAs(workbookFile);

            // close excel and dispose reference
            excelApplication.Quit();
            excelApplication.Dispose();

            // show end dialog
            HostApplication.ShowFinishDialog(null, workbookFile);
        }
Beispiel #7
0
        public void Run()
        {
            // In some situations you want use NetOffice with an already running application.
            // this tutorial shows how its possible.

            // 1)
            //
            // GetActiveInstance take the first instance in memory
            Excel.Application application = ProxyService.GetActiveInstance <Excel.Application>();
            if (null != application)
            {
                application.Dispose();
            }

            // 2)
            //
            // GetActiveInstances takes all instances in memory
            var applications = ProxyService.GetActiveInstances <Excel.Application>();

            applications.Dispose();

            // 3)
            //
            // Use special ctor to try access a running application first
            // and if its failed create a new application
            application = new Excel.ApplicationClass(new Core(), true);
            // quit only if its a new application
            if (!application.FromProxyService)
            {
                application.Quit();
            }
            application.Dispose();

            // 4)
            //
            // Creates instance from interop proxy
            Type   interopType = Type.GetTypeFromProgID("Excel.Application");
            object proxy       = Activator.CreateInstance(interopType);

            application = COMObject.Create <Excel.Application>(proxy);
            application.Quit();
            application.Dispose();


            HostApplication.ShowFinishDialog();
        }
Beispiel #8
0
        public void Run()
        {
            // In some situations you want use NetOffice with a already running application.
            // this examples show you how its possible.

            // GetActiveInstance take the first instance in memory
            Excel.Application excelApplication = Excel.Application.GetActiveInstance();

            // another method is GetActiveInstances:
            //
            // GetActiveInstances takes all instances in memory. dont forget to dispose the instances.
            //
            // Excel.Application[] excelApplications = Excel.Application.GetActiveInstances();

            excelApplication.Quit();
            excelApplication.Dispose();

            HostApplication.ShowFinishDialog();
        }
Beispiel #9
0
        public void Run()
        {
            // this example shows you another dispose method: DisposeChildInstances
            // this means all child proxies from an instance

            // start application
            Excel.Application application = new Excel.Application();
            application.DisplayAlerts = false;

            Excel.Workbook  book  = application.Workbooks.Add();
            Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets.Add();

            /*
             * we have 5 created proxies now in proxy table as follows
             *
             * Application
             *   + Workbooks
             *     + Workbook
             *        + Worksheets
             *            + Worksheet
             */


            // we dispose the child instances from book
            book.DisposeChildInstances();

            /*
             * we have 3 created proxies now, the childs from book are disposed
             *
             * Application
             *   + Workbooks
             *     + Workbook
             */

            application.Quit();
            application.Dispose();

            // the Dispose() call for application release the instance and created childs Workbooks and Workbook

            HostApplication.ShowFinishDialog();
        }
Beispiel #10
0
        public void Run()
        {
            // this example demonstrate the global helper module(static class)
            // the module is a vba compatibility workarround and contains static methods and properties from the coresponding Application class.

            // start excel and add a new workbook
            Excel.Application application = new Excel.Application();
            application.Visible       = false;
            application.DisplayAlerts = false;
            application.Workbooks.Add();

            // GlobalModule contains the well known globals and is located in NetOffice.ExcelApi.GlobalHelperModules
            // In VB.NET you can do now: ActiveCell.Value = "ActiveCellValue" and this is helpful to bring code from VBA to NetOffice
            GlobalModule.ActiveCell.Value = "ActiveCellValue";

            // quit and dispose excel
            application.Quit();
            application.Dispose();

            HostApplication.ShowFinishDialog();
        }
Beispiel #11
0
        public void Run()
        {
            // Enable and trigger trace alert
            NetOffice.Settings.Default.PerformanceTrace.Enabled = true;
            NetOffice.Settings.Default.PerformanceTrace.Alert  += delegate(NetOffice.PerformanceTrace sender, NetOffice.PerformanceTrace.PerformanceAlertEventArgs args)
            {
                Console.WriteLine("{0} {1}:{2} in {3} Milliseconds ({4} Ticks)", args.CallType, args.EntityName, args.MethodName, args.TimeElapsedMS, args.Ticks);
            };

            // Criteria 1
            // Enable performance trace in excel generaly. set interval limit to 100ms to see all actions there need >= 100 milliseconds
            NetOffice.Settings.Default.PerformanceTrace["NetOffice.ExcelApi"].Enabled    = true;
            NetOffice.Settings.Default.PerformanceTrace["NetOffice.ExcelApi"].IntervalMS = 100;

            // Criteria 2
            // Enable additional performance trace for all members of WorkSheet in excel. set interval limit to 20ms to see all actions there need >=20 milliseconds
            NetOffice.Settings.Default.PerformanceTrace["NetOffice.ExcelApi", "Worksheet"].Enabled    = true;
            NetOffice.Settings.Default.PerformanceTrace["NetOffice.ExcelApi", "Worksheet"].IntervalMS = 20;

            // Criteria 3
            // Enable additional performance trace for WorkSheet Range property in excel. set interval limit to 0ms to see all calls anywhere
            NetOffice.Settings.Default.PerformanceTrace["NetOffice.ExcelApi", "Worksheet", "Range"].Enabled    = true;
            NetOffice.Settings.Default.PerformanceTrace["NetOffice.ExcelApi", "Worksheet", "Range"].IntervalMS = 0;

            // do some stuff
            Excel.Application application = new NetOffice.ExcelApi.Application();
            application.DisplayAlerts = false;
            Excel.Workbook  book  = application.Workbooks.Add();
            Excel.Worksheet sheet = book.Sheets.Add() as Excel.Worksheet;
            for (int i = 1; i <= 5; i++)
            {
                Excel.Range range = sheet.Range("A" + i.ToString());
                range.Value       = "Test123";
                range[1, 1].Value = "Test234";
            }
            application.Quit();
            application.Dispose();

            HostApplication.ShowFinishDialog();
        }
Beispiel #12
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // create a utils instance, no need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a label
            PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
            label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

            // add a line
            slide.Shapes.AddLine(10, 80, 700, 80);

            // add a wordart
            slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                       MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

            // add a star
            slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

            // save the document
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example02", DocumentFormat.Normal);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show end dialog
            HostApplication.ShowFinishDialog(null, documentFile);
        }