Example #1
0
        public void btnSyncField_Click(IRibbonControl control)
        {
            var doc             = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);
            var proptectionType = -1;

            try
            {
                proptectionType = doc.TurnOffProtection(string.Empty);
                var contentcontrol = Globals.ThisAddIn.Application.Selection.Range.ParentContentControl;
                if (contentcontrol == null)
                {
                    return;
                }
                var matchingControls =
                    Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTag(contentcontrol.Tag);
                foreach (WordOM.ContentControl mc in matchingControls)
                {
                    mc.Range.Text = contentcontrol.Range.Text;
                }
            }
            catch (Exception e)
            {
                var logger = new EventViewerLogger();
                logger.Log(e.ToString(), Type.Error);

#if DEBUG
                MessageBox.Show(e.ToString(), @"sorry");
#endif
            }
            finally
            {
                doc.TurnOnProtection(proptectionType, string.Empty);
            }
        }
        private IBaseTemplate LoadTemplateData()
        {
            var document = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);

            var template = new FactFinder();

            //read content controls and set template values.
            foreach (PropertyInfo pInfo in template.GetType().GetProperties())
            {
                if (pInfo == null)
                {
                    break;
                }

                if (!String.Equals(pInfo.PropertyType.Name, "string", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                string value = document.ReadContentControlValue(pInfo.Name);
                pInfo.SetValue(template, value, null);
            }

            //read cover page and logo property values and set template values
            template.CoverPageTitle = document.GetPropertyValue(Constants.WordDocumentProperties.CoverPageTitle);
            template.LogoTitle      = document.GetPropertyValue(Constants.WordDocumentProperties.LogoTitle);
            return(template);
        }
Example #3
0
        public void ExcelApplicationConstructorTest()
        {
            ExcelApplication_Accessor target   = new ExcelApplication_Accessor(application);
            OfficeDocument            document = target.Open(this.demoDoc);

            Assert.AreEqual(document.FilePath.FullName.ToUpperInvariant(), demoDoc.FullName.ToUpperInvariant());
        }
        public void ReloadOnSaveTest()
        {
            // Arrange
            void CheckIntegrity(OfficeDocumentViewModel innerModel)
            {
                Assert.AreEqual(2, innerModel.Children.Count);

                for (var i = 0; i < 2; ++i)
                {
                    var innerPart = (OfficePartViewModel)innerModel.Children[i];

                    if (innerPart.Part?.PartType == XmlPart.RibbonX12)
                    {
                        Assert.AreEqual(1, innerPart.Children.Count);
                        Assert.AreEqual("redo", ((IconViewModel)innerPart.Children[0]).Name);
                    }
                    else
                    {
                        Assert.AreEqual(2, innerPart.Children.Count);
                        Assert.AreEqual("changedId", ((IconViewModel)innerPart.Children[0]).Name);
                        Assert.AreEqual("redo", ((IconViewModel)innerPart.Children[1]).Name);
                    }
                }
            }

            using (var doc = new OfficeDocument(this.sourceFile))
                using (var viewModel = new OfficeDocumentViewModel(doc))
                {
                    viewModel.InsertPart(XmlPart.RibbonX12);
                    viewModel.InsertPart(XmlPart.RibbonX14);

                    var part = (OfficePartViewModel)viewModel.Children[0];
                    part.InsertIcon(this.undoIcon);
                    part.InsertIcon(this.redoIcon);
                    part.RemoveIcon("undo");
                    part = (OfficePartViewModel)viewModel.Children[1];
                    part.InsertIcon(this.redoIcon);
                    var icon = (IconViewModel)part.Children[0];
                    icon.Name = "changedId";
                    part.InsertIcon(this.redoIcon);

                    // Act / assert
                    CheckIntegrity(viewModel);

                    viewModel.Save(false, this.destFile);
                }

            using (var doc = new OfficeDocument(this.destFile))
                using (var viewModel = new OfficeDocumentViewModel(doc))
                {
                    CheckIntegrity(viewModel);
                    viewModel.Save(true, this.destFile);
                }

            using (var doc = new OfficeDocument(this.destFile))
                using (var viewModel = new OfficeDocumentViewModel(doc))
                {
                    CheckIntegrity(viewModel);
                }
        }
Example #5
0
        /// <summary>
        /// Reloads the associated Office document, but keeping the OfficeParts currently shown in the GUI. This
        /// ensures that, if the files have been modified externally, the program is still looking at their latest
        /// version. Otherwise, we might accidentally lose those external changes when saving
        /// </summary>
        public void Reload()
        {
            // Store the file name (otherwise, it will have been erased after calling Dispose)
            var fileName = this.document.Name;

            // Dispose current document (not needed as references to its parts are stored in their View models anyway)
            this.document.Dispose();

            // Then, reload it
            this.document = new OfficeDocument(fileName);

            // Delete all its original parts
            foreach (var type in Enum.GetValues(typeof(XmlPart)).OfType <XmlPart>())
            {
                this.document.RemoveCustomPart(type);
            }

            // Instead, use the parts currently shown in the editor
            foreach (var part in this.Children.OfType <OfficePartViewModel>())
            {
                if (part.Part == null)
                {
                    continue;
                }

                this.document.SaveCustomPart(part.Part.PartType, part.OriginalContents, true);

                // Re-map the Part. This ensures that the PackagePart stored internally in OfficePart points to
                // the right location, in case it is needed
                part.Reload();
            }
        }
        public InsuranceRenewalReportWizard(OfficeDocument document, Helpers.Enums.FormLoadType loadType)
        {
            InitializeComponent();

            tbcWizardScreens.SelectedIndexChanged += new EventHandler(tbcWizardScreens_SelectedIndexChanged);
            _checked.CheckStateChanged            += new EventHandler <TreePathEventArgs>(_checked_CheckStateChanged);

            _orderPolicy.ChangesApplied += new EventHandler(_textbox_ValueChanged);

            txtClientName.Validating          += txtClientName_Validating;
            txtClientCommonName.Validating    += txtClientCommonName_Validating;
            rdoSegment2.Validating            += rdoSegment_Validating;
            rdoSegment3.Validating            += rdoSegment_Validating;
            rdoSegment4.Validating            += rdoSegment_Validating;
            rdoSegment5.Validating            += rdoSegment_Validating;
            rdoWholesale.Validating           += rdoRetailWholesale_Validating;
            rdoWholesaleWithRetail.Validating += rdoRetailWholesale_Validating;
            rdoRetailFSG.Validating           += rdoRetailWholesale_Validating;
            rdoFeeOnly.Validating             += rdoFee_Validating;
            rdoCombination.Validating         += rdoFee_Validating;
            rdoCombination.Validating         += rdoFee_Validating;
            rdoUFIYes.Validating += rdoUFI_Validating;
            rdoUFINo.Validating  += rdoUFI_Validating;

            //send marketing template to the presenter

            _presenter         = new InsuranceRenewealReportPresenter(document, this);
            base.BasePresenter = _presenter;
            _loadType          = loadType;

            tvaPolicies.Resize += new EventHandler(tvaPolicies_Resize);

            _name.DrawText += new EventHandler <DrawEventArgs>(_name_DrawText);
        }
Example #7
0
        public void btnConvertToPlacementSlip_Click(IRibbonControl control)
        {
            var docTitle = ((DocumentProperties)(Globals.ThisAddIn.Application.ActiveDocument.BuiltInDocumentProperties))[WordOM.WdBuiltInProperty.wdPropertyTitle].Value;

            if (Constants.TemplateNames.PlacementSlip.Equals(docTitle.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                MessageBox.Show(@"Document has already been converted into a Placement Slip", "Document is a Placement Slip", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ribbon.Invalidate();
                return;
            }

            var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);

            WordOM.Document d = Globals.ThisAddIn.Application.ActiveDocument;
            doc.PopulateControl(Constants.WordContentControls.DocumentTitle, Constants.TemplateNames.PlacementSlip);
            doc.MoveCursorToStartOfControl(Constants.WordContentControls.Instructions);
            doc.DeleteControl(Constants.WordContentControls.Instructions);
            doc.DeleteCharacter(1);
            doc.InsertFile(Settings.Default.PlacementSlipConditionsFragement);

            ((DocumentProperties)(Globals.ThisAddIn.Application.ActiveDocument.BuiltInDocumentProperties))[WordOM.WdBuiltInProperty.wdPropertyTitle].Value = Constants.TemplateNames.PlacementSlip;
            doc.UpdateOrCreatePropertyValue(Constants.WordDocumentProperties.BuiltInTitle, Constants.TemplateNames.PlacementSlip);
            ribbon.Invalidate();

            var s = doc.GetBookmarkStartRange("QuotationDetailsStart");
            var e = doc.GetBookmarkEndRange("QuotationDetailsEnd");

            doc.DeleteRange(s, e);
            if (doc.MoveCursorToStartOfBookmark("QuotationDetailsEnd"))
            {
                doc.DeletePage();
                doc.DeleteCharacter(1);
            }
        }
Example #8
0
        public HelpWizard(string templateName)
        {
            InitializeComponent();


            var officeDoc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);

            _presenter = new HelpContentPresenter(officeDoc, this);

            base.BasePresenter = _presenter;


//            var find = Globals.ThisAddIn.Application.Selection.Find;

//            var r = Globals.ThisAddIn.Application.Application.Selection.Move();


//            //error handling needed.
//// ReSharper disable UseIndexedProperty
//            find.set_Style(Globals.ThisAddIn.Application.ActiveDocument.Styles[BusinessLogic.Helpers.Constants.WordStyles.Heading1]);
//// ReSharper restore UseIndexedProperty
//            find.Text = String.Empty;
//            find.Forward = false;
//            find.MatchWildcards = true;
//            find.Execute();

//            BusinessLogic.Helpers.Constants.WordStyles.Heading1
//            var heading = Globals.ThisAddIn.Application.Selection.Text;

            var heading = _presenter.FindHeadingTextForCurrentDocument();

            webHelpWindow.DocumentText = GetHelpContentFromSharePoint(heading, Settings.Default.SharePointContextUrl, Settings.Default.HelpContentListName, templateName);

            //    Globals.ThisAddIn.Application.Application.Selection.GoTo(WdGoToItem.wdGoToTable)
        }
Example #9
0
        public void btnConvertToManual_Click(IRibbonControl control)
        {
            var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);
            int p   = doc.TurnOffProtection(string.Empty);

            doc.PopulateControl(Constants.WordContentControls.DocumentTitle, "Insurance Manual");
            doc.TurnOnProtection(p, string.Empty);
        }
Example #10
0
 public SelectSitePublish(String title, String description, OfficeDocument document, WebSiteInfo webSiteInfo)
     : base(webSiteInfo)
 {
     this.m_title       = title;
     this.m_description = description;
     this.ValidateStep += new System.ComponentModel.CancelEventHandler(SelectSitePublish_ValidateStep);
     this.document      = document;
 }
Example #11
0
 public SelectSitePublish(OfficeDocument document, WebSiteInfo webSiteInfo)
     : base(webSiteInfo)
 {
     this.document          = document;
     type                   = document.DocumentType;
     this.ValidateStep     += new System.ComponentModel.CancelEventHandler(SelectSitePublish_ValidateStep);
     selectWebPage.AddNode += new WBOffice4.Controls.NodeEvent(selectWebPage_onAddNode);
 }
Example #12
0
 public FormPublishcontentToPage(OfficeDocument document, String title, String description, WebSiteInfo site)
 {
     InitializeComponent();
     this.document    = document;
     this.title       = title;
     this.description = description;
     this.site        = site;
 }
Example #13
0
 public SelectSiteCreatePage(String title, String description, OfficeDocument document)
     : base()
 {
     this.title         = title;
     this.description   = description;
     this.document      = document;
     this.ValidateStep += new System.ComponentModel.CancelEventHandler(SelectSite_ValidateStep);
 }
        public void DocumentShouldBeOpened()
        {
            // Arrange / act
            var doc = new OfficeDocument(this.sourceFile);

            // Assert
            Assert.IsNotNull(doc.UnderlyingPackage, "Package was not opened");
        }
Example #15
0
        public void btnConvertToPlacementSlip_Click(IRibbonControl control)
        {
            var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);

            WordOM.Document d = Globals.ThisAddIn.Application.ActiveDocument;
            doc.PopulateControl(Constants.WordContentControls.DocumentTitle, "Placement Slip");
            doc.MoveCursorToStartOfControl(Constants.WordContentControls.Instructions);
            doc.DeleteControl(Constants.WordContentControls.Instructions);
            doc.InsertFile(Settings.Default.PlacementSlipConditionsFragement);
        }
        //private bool isPrePrintedStationary;

        public GenericLetterWizard(OfficeDocument document)
        {
            InitializeComponent();
            tbcWizardScreens.SelectedIndexChanged += tbcWizardScreens_SelectedIndexChanged;

            _wizardPresenter         = new GenericLetterWizardPresenter(document, this);
            base.BaseWizardPresenter = _wizardPresenter;

            txtClientName.Validating += ClientNameValidating;
        }
Example #17
0
        protected override OfficeDocument Open(System.IO.FileInfo file)
        {
            OfficeDocument officeDocument = null;
            object         filedocxtoOpen = file.FullName;
            object         missing        = Type.Missing;

            Word.Document doc = application.Documents.Open(ref filedocxtoOpen, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            officeDocument = new Word2007OfficeDocument(doc);
            return(officeDocument);
        }
        //private bool isPrePrintedStationary;

        public GenericLetterWizard(OfficeDocument document)
        {
            InitializeComponent();
            tbcWizardScreens.SelectedIndexChanged += new EventHandler(tbcWizardScreens_SelectedIndexChanged);

            _presenter         = new GenericLetterPresenter(document, this);
            base.BasePresenter = _presenter;

            txtClientName.Validating += new CancelEventHandler(ClientNameValidating);
        }
Example #19
0
        public SummaryOfDiscussionWizard(OfficeDocument document)
        {
            InitializeComponent();

            tbcWizardScreens.SelectedIndexChanged += new EventHandler(tbcWizardScreens_SelectedIndexChanged);

            //send marketing template to the presenter

            _presenter    = new SummaryOfDiscussionPresenter(document, this);
            BasePresenter = _presenter;
        }
Example #20
0
 public TitleAndDescription(OfficeDocument document, bool showType)
 {
     InitializeComponent();
     this.document = document;
     this.showType = showType;
     if (!showType)
     {
         this.ComboBoxType.Visible = false;
         this.labelType.Visible    = false;
     }
 }
Example #21
0
        protected override OfficeDocument Open(System.IO.FileInfo file, String contentid, String rep)
        {
            object         missing        = Type.Missing;
            object         format         = Word.WdSaveFormat.wdFormatDocument;
            OfficeDocument officeDocument = null;
            object         filedocxtoOpen = file.FullName;

            if (file.Exists)
            {
                try
                {
                    Word.Document doc = application.Documents.Open(ref filedocxtoOpen, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    officeDocument = new Word2010OfficeDocument(doc);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.StackTrace);
                    String   path  = file.FullName.Replace(".doc", ".html");
                    FileInfo fHTML = new FileInfo(path);
                    if (fHTML.Exists)
                    {
                        filedocxtoOpen = path;
                        Word.Document doc = application.Documents.Open(ref filedocxtoOpen, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                        filedocxtoOpen = file.FullName;
                        doc.SaveAs(ref filedocxtoOpen, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                        doc.ActiveWindow.View.Type = Word.WdViewType.wdPrintView;
                        officeDocument             = new Word2010OfficeDocument(doc);
                    }
                }
            }
            else
            {
                String   path  = file.FullName.Replace(".doc", ".html");
                FileInfo fHTML = new FileInfo(path);
                if (fHTML.Exists)
                {
                    filedocxtoOpen = path;
                    Word.Document doc = application.Documents.Open(ref filedocxtoOpen, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    filedocxtoOpen = file.FullName;
                    doc.SaveAs(ref filedocxtoOpen, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    doc.ActiveWindow.View.Type = Word.WdViewType.wdPrintView;
                    officeDocument             = new Word2010OfficeDocument(doc);
                }
            }
            if (officeDocument != null)
            {
                officeDocument.SaveContentProperties(contentid, rep);
                if (MenuListener != null)
                {
                    MenuListener.DocumentPublished();
                }
            }
            return(officeDocument);
        }
        public void DocumentShouldBeSaved()
        {
            // Arrange
            var doc = new OfficeDocument(this.sourceFile);

            // Act
            doc.Save(this.destFile);

            // Assert
            Assert.IsTrue(File.Exists(this.destFile), "File was not saved");
        }
        public void PartShouldBeCreated()
        {
            // Arrange
            var doc = new OfficeDocument(this.sourceFile);

            // Act
            var part = doc.CreateCustomPart(XmlParts.RibbonX12);

            // Assert
            Assert.IsNotNull(part, "Part was not inserted");
        }
        public ThemesOnlyWizard(OfficeDocument document)
        {
            InitializeComponent();

            tbcWizardScreens.SelectedIndexChanged += tbcWizardScreens_SelectedIndexChanged;

            _wizardPresenter    = new BaseWizardPresenter(document, this);
            BaseWizardPresenter = _wizardPresenter;

            //ShouldUpdateTemplate(Settings.Default.TemplateLibraryName, "Multi Page Document.docx");
        }
Example #25
0
        public void btnSyncTable_Click(Microsoft.Office.Core.IRibbonControl control)
        {
            var doc             = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);
            var proptectionType = -1;

            try
            {
                //proptectionType = doc.TurnOffProtection(String.Empty);

                var tables = Globals.ThisAddIn.Application.Selection.Tables;
                if (tables == null || tables.Count == 0)
                {
                    MessageBox.Show(@"Please ensure your cursor is within a table", @"No Table Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var table = tables[1];


                var contentcontrols = table.Range.ContentControls;
                if (contentcontrols == null)
                {
                    return;
                }

                foreach (WordOM.ContentControl contentControl in contentcontrols)
                {
                    if (String.IsNullOrEmpty(contentControl.Tag))
                    {
                        continue;
                    }

                    var matchingControls =
                        Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTag(contentControl.Tag);
                    foreach (WordOM.ContentControl mc in matchingControls)
                    {
                        mc.Range.Text = contentControl.Range.Text;
                    }
                }
            }
            catch (Exception e)
            {
                var logger = new EventViewerLogger();
                logger.Log(e.ToString(), BusinessLogic.Interfaces.Logging.Type.Error);

#if DEBUG
                MessageBox.Show(e.ToString(), @"sorry");
#endif
            }
            finally
            {
                //   doc.TurnOnProtection(proptectionType, String.Empty);
            }
        }
        public PreRenewalQuestionareWizard(OfficeDocument document, Helpers.Enums.FormLoadType loadType)
        {
            InitializeComponent();
            tbcWizardScreens.SelectedIndexChanged += new EventHandler(tbcWizardScreens_SelectedIndexChanged);
            _presenter         = new PreRenewalQuestionarePresenter(document, this);
            base.BasePresenter = _presenter;
            _loadType          = loadType;

            _checked.CheckStateChanged += new EventHandler <TreePathEventArgs>(_checked_CheckStateChanged);

            _name.DrawText += new EventHandler <DrawEventArgs>(OnDrawPolicyNode);
        }
        public GenericLetterWizard(OfficeDocument document)
        {
            InitializeComponent();
            tbcWizardScreens.SelectedIndexChanged += tbcWizardScreens_SelectedIndexChanged;

            _wizardPresenter    = new GenericLetterWizardPresenter(document, this);
            BaseWizardPresenter = _wizardPresenter;

            txtClientName.Validating += ClientNameValidating;

            //ShouldUpdateTemplate(Settings.Default.TemplateLibraryName, "Generic Letter.docx");
        }
        public void PartShouldBeInserted()
        {
            // Arrange
            var doc       = new OfficeDocument(this.sourceFile);
            var viewModel = new OfficeDocumentViewModel(doc);

            // Act
            viewModel.InsertPart(XmlParts.RibbonX12);

            // Assert
            Assert.AreEqual(1, viewModel.Children.Count);
        }
        public void SaveTest()
        {
            var doc       = new OfficeDocument(this.sourceFile);
            var viewModel = new OfficeDocumentViewModel(doc);

            viewModel.InsertPart(XmlParts.RibbonX12);
            Assert.AreEqual(1, viewModel.Children.Count);

            Assert.IsFalse(File.Exists(this.destFile), "File was not deleted before test");
            doc.Save(this.destFile);
            Assert.IsTrue(File.Exists(this.destFile), "File was not saved");
        }
Example #30
0
        private void ThisAddIn_DocumentOpen(Document doc)
        {
            try
            {
                var logger = new EventViewerLogger();
                logger.Log(string.Format("DocumentOpen event"), Type.Information);

                if (doc == null)
                {
                    logger.Log(string.Format("DocumentOpen event - doc is null, returning"), Type.Information);
                    return;
                }

                doc.ActiveWindow.View.ShadeEditableRanges = 0;
                Ribbon.ribbon.Invalidate();


                var document   = new OfficeDocument(doc);
                var documentId = document.GetPropertyValue(Constants.WordDocumentProperties.DocumentId);
                logger.Log(string.Format("DocumentOpen event - documentId = {0}", documentId), Type.Information);

                // disabled update check Nov 2017 DSZ
                //var fragmentsUsedPropertyValue = document.GetPropertyValue(Constants.WordDocumentProperties.UsedDateOfFragements);
                //var logoPropertyValue = document.GetPropertyValue(Constants.WordDocumentProperties.UsedDateOfLogo);
                //var themePropertyValue = document.GetPropertyValue(Constants.WordDocumentProperties.UsedDateOfTheme);
                //var mainTemplatePropertyValue =
                //    document.GetPropertyValue(Constants.WordDocumentProperties.BuiltInTitle) + ";" +
                //    document.GetPropertyValue(Constants.WordDocumentProperties.DocumentGeneratedDate);

                //var spList = ListFactory.Create("TemplateUpdateTracking");
                //var item = spList.GetListItemByTitle(documentId);
                //var shouldHide = "false";
                //var hideChosedDate = "";
                //if (item != null)
                //{
                //    shouldHide = item.GetFieldValue("Hide");
                //    hideChosedDate = item.GetFieldValue("Modified");
                //}

                //var task =
                //    Task.Factory.StartNew(
                //        () =>
                //            ExecuteUpdateChecker(shouldHide, fragmentsUsedPropertyValue, themePropertyValue,
                //                logoPropertyValue, mainTemplatePropertyValue, documentId, hideChosedDate));

                //System.Threading.Tasks.Task.Factory.StartNew(() => ThisAddIn.CheckStartupTasks(document), CancellationToken.None, TaskCreationOptions.None, uiScheduler);
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
        }