Ejemplo n.º 1
0
        internal static void Run()
        {
            NetOffice.Settings.Default.EnableAutomaticQuit = true;

            string fileName = @"C:\Sebastian\NetOffice\Tests\Concept Tests\DynamicsCSharp\Document.docm";

            using (Word.Application application = new NetOffice.WordApi.ApplicationClass())
            {
                using (var doc = application.Documents.Open(fileName))
                {
                    if (doc.HasVBProject)
                    {
                        var project = doc.VBProject;
                        foreach (var component in project.VBComponents)
                        {
                            if (component.Type == NetOffice.VBIDEApi.Enums.vbext_ComponentType.vbext_ct_MSForm)
                            {
                                Console.WriteLine(" - " + component.Name);
                                var exportPath = Path.Combine(Path.GetDirectoryName(fileName), component.Name + ".frm");
                                component.Export(exportPath);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Word.Application application = null;
            try
            {
                application = new Word.ApplicationClass();
                application.DisplayAlerts = WdAlertLevel.wdAlertsNone;

                object   basic     = application.WordBasic;
                object[] argValues = { 1 };
                basic.GetType().InvokeMember("DisableAutoMacros", BindingFlags.InvokeMethod, null, basic, argValues, null, null, null);
                Console.WriteLine("Fine");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            Word.Application application = new Word.ApplicationClass();
            application.Visible       = true;
            application.DisplayAlerts = NetOffice.WordApi.Enums.WdAlertLevel.wdAlertsNone;
            Word.Document document = application.Documents.Add();
            application.Selection.TypeText("Hello World");
            int left   = 0;
            int top    = 0;
            int width  = 0;
            int height = 0;

            application.ActiveWindow.GetPoint(out left, out top, out width, out height, application.Selection.Range);

            MessageBox.Show(string.Format("GetPoint returns Left:{0} Top:{1} Width:{2} Height:{3}", left, top, width, height));
            document.Saved = true;

            try
            {
                application.Quit();
                application.Dispose();
            }
            catch
            {
                // may closed by user
            }
        }
Ejemplo n.º 4
0
        private static void TestWord()
        {
            Console.WriteLine("Test Word Application Utils");

            Word.Application application = new Word.ApplicationClass();
            application.DisplayAlerts = Word.Enums.WdAlertLevel.wdAlertsNone;
            application.Documents.Add();

            Word.Tools.Contribution.CommonUtils utils = new Word.Tools.Contribution.CommonUtils(application);
            int hwnd = utils.Application.TryGetMainWindowHandle(application.Documents[1]);

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

            if (0 == hwnd)
            {
                throw new Exception("Cant resolve word hwnd");
            }
        }