Example #1
0
        private void DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
        {
            if (Utils.ActiveDocumentLinkedToDocumentMap())
            {
                var path = Utils.DocumentMapperFilelocation();

                Utils.SaveDocumentMap(DocumentMapping.Current, path);
            }
        }
Example #2
0
        public void OpenLink(Office.IRibbonControl control)
        {
            Inspector currentInspector = Globals.ThisAddIn.Application.ActiveInspector();

            if (currentInspector == null)
            {
                Explorer  currentExplorer  = Globals.ThisAddIn.Application.ActiveExplorer();
                Selection currentSelection = currentExplorer.Selection;
                object    o     = currentSelection[1];
                MailItem  oMail = (MailItem)o;
                currentInspector = oMail.GetInspector;
            }
            Microsoft.Office.Interop.Word.Document document =
                (Microsoft.Office.Interop.Word.Document)currentInspector.WordEditor;
            string address = document.Application.Selection.Hyperlinks[1].Address;
            int    numId   = GetButtonID(control.Id);
            string path    = searchBrowsersTask.Result.Browsers.Where(browser => browser.BrowserID == numId).Single().CommandPath;

            Process.Start(path, address);
        }
Example #3
0
        private void Create(Microsoft.Office.Interop.Outlook.MailItem mailItem)
        {
            String messageClass;

            DevExpress.XtraRichEdit.RichEditControl    rtfControl = new DevExpress.XtraRichEdit.RichEditControl();
            TIS.DL.Internal.Task.TaskObject            taskObj;
            Microsoft.Office.Interop.Outlook.Inspector inspector;
            try
            {
                messageClass = mailItem.MessageClass;


                if (messageClass == "IPM.Note")
                {
                    taskObj = new TIS.DL.Internal.Task.TaskObject();
                    ProcessEmailAddresses(taskObj, mailItem);
                    //Get Reporter
                    Microsoft.Office.Interop.Outlook.NameSpace outNamespace;
                    outNamespace = Application.GetNamespace("MAPI");
                    Microsoft.Office.Interop.Outlook.Recipient reporter = outNamespace.CurrentUser;
                    ProcessEmailAddressReporter(taskObj, reporter.Address);

                    taskObj.CreationDate = PROF_IT.Common.Convert.DateFunctions.DateToStrDate(System.DateTime.Now);
                    //RTF BODY
                    inspector = mailItem.GetInspector;
                    inspector.Activate();
                    Microsoft.Office.Interop.Word.Document document = (Microsoft.Office.Interop.Word.Document)inspector.WordEditor;
                    document.Select();
                    document.Application.Selection.Copy();
                    rtfControl.Paste();
                    taskObj.Description = rtfControl.RtfText;

                    //Subject
                    taskObj.Tag = mailItem.Subject;
                    switch (mailItem.Importance)
                    {
                    case Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh:
                        taskObj.Priority = TIS.Framework.Common.Enumeration.Task.Priority.High;
                        break;

                    case Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow:
                        taskObj.Priority = TIS.Framework.Common.Enumeration.Task.Priority.Low;
                        break;

                    case Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal:
                        taskObj.Priority = TIS.Framework.Common.Enumeration.Task.Priority.Medium;
                        break;
                    }
                    taskObj.Effort = TIS.Framework.Common.Enumeration.Task.Effort.Low;
                    taskObj.Status = TIS.Framework.Common.Enumeration.Task.Status.Open;

                    Task task = new Task(PROF_IT.Common.Enumerations.TypeForm.PropertyForm, taskObj);
                    task.ShowDialog();

                    //Close document, inspector
                    if (inspector != null)
                    {
                        inspector.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
                    }
                    document  = null;
                    inspector = null;
                    mailItem  = null;
                }
                else
                {
                    MessageBox.Show("Kan geen task creëren omdat het geselecteerde item geen e-mail is!");
                }
            }
            catch (System.Exception exception1)
            {
                System.Exception innerException = exception1;
                throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException);
            }
            finally
            {
                rtfControl.Dispose();
            }
        }
Example #4
0
        public void QuoteCommandClick(IRibbonControl e)
        {
            var app = Globals.ThisAddIn.Application;

            if (app == null)
            {
                return;
            }

            var inspector = app.ActiveInspector();
            var explorer  = app.ActiveExplorer();

            if (inspector == null)
            {
                return;
            }

            if (inspector.CurrentItem != null)
            {
                MailItem mailItem = inspector.CurrentItem;
                if (mailItem.BodyFormat == OlBodyFormat.olFormatHTML)
                {
                    if (inspector.EditorType == OlEditorType.olEditorHTML)
                    {
                        var editor = inspector.HTMLEditor;
                    }
                    else if (inspector.EditorType == OlEditorType.olEditorWord)
                    {
                        Microsoft.Office.Interop.Outlook.Selection oSel = explorer.Selection;

                        List <string> rawQuotes = new List <string>();

                        string author = "Кто-то";

                        for (int i = 1; i <= oSel.Count; i++)
                        {
                            var       oItem          = oSel[i];
                            MailItem  oMail          = (MailItem)oItem;
                            Inspector localInspector = oMail.GetInspector;
                            Microsoft.Office.Interop.Word.Document document =
                                (Microsoft.Office.Interop.Word.Document)inspector.WordEditor;
                            string quoteText = document.Application.Selection.Text;

                            List <ParserDescriptor> parserDescriptors = new List <ParserDescriptor>();
                            parserDescriptors.Add(new ParserDescriptor("From", "Sent"));
                            parserDescriptors.Add(new ParserDescriptor("От", "Отправлено:"));

                            foreach (var pd in parserDescriptors)
                            {
                                Object findText = pd.SearchKey;
                                Object missing  = Type.Missing;

                                var range = document.Range(document.Content.Start, document.Application.Selection.Range.Start);
                                if (range.Find.Execute(
                                        ref findText, ref missing, ref missing, true, ref missing,
                                        ref missing, false, ref missing, ref missing, ref missing,
                                        ref missing, ref missing, ref missing, ref missing, ref missing))
                                {
                                    pd.Result = document.Range(range.Start, range.End);
                                }
                            }

                            var optimalParser = parserDescriptors.OrderByDescending(pd => pd.Result == null ? 0 : pd.Result.Start).FirstOrDefault();
                            if (optimalParser != null)
                            {
                                string parsedAuthor = optimalParser.ParseSender(document);
                                if (!String.IsNullOrWhiteSpace(parsedAuthor))
                                {
                                    author = parsedAuthor;
                                }
                            }

                            rawQuotes.Add(quoteText);
                        }

                        string styledQuote = "";

                        foreach (var rawQuote in rawQuotes)
                        {
                            styledQuote += Properties.Resources.QuoteTemplate
                                           .Replace("[%QUOTE_ID%]", Guid.NewGuid().ToString().Replace("-", ""))
                                           .Replace("[%QUOTE_AUTHOR%]", author)
                                           .Replace("[%QUOTE_TEXT%]", rawQuote);
                        }

                        mailItem.HTMLBody = QuoteInsert(styledQuote, mailItem.HTMLBody);
                    }
                }
            }
        }
        private void CreateDocument(String cellResult)
        {
            try
            {
                //Create an instance for word app
                Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();

                //Set animation status for word application
                winword.ShowAnimation = false;

                //Set status for word application is to be visible or not.
                winword.Visible = false;

                //Create a missing variable for missing value
                object missing = System.Reflection.Missing.Value;

                //Create a new document
                Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                //Add header into the document

                /*foreach (Microsoft.Office.Interop.Word.Section section in document.Sections)
                 * {
                 *  //Get the header range and add the header details.
                 *  Microsoft.Office.Interop.Word.Range headerRange = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                 *  headerRange.Fields.Add(headerRange, Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage);
                 *  headerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                 *  headerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBlue;
                 *  headerRange.Font.Size = 10;
                 *  headerRange.Text = "Header text goes here";
                 * }
                 *
                 * //Add the footers into the document
                 * foreach (Microsoft.Office.Interop.Word.Section wordSection in document.Sections)
                 * {
                 *  //Get the footer range and add the footer details.
                 *  Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                 *  footerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
                 *  footerRange.Font.Size = 10;
                 *  footerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                 *  footerRange.Text = "Footer text goes here";
                 * }*/

                //adding text to document
                document.Content.SetRange(0, 0);
                document.Content.Text = cellResult;

                //Save the document
                object filename = @"E:\temp1.docx";
                document.SaveAs2(ref filename);
                document.Close(ref missing, ref missing, ref missing);
                document = null;
                winword.Quit(ref missing, ref missing, ref missing);
                winword = null;
                MessageBox.Show("Document created successfully !");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #6
0
 private void OnDocumentOpen(Microsoft.Office.Interop.Word.Document Doc)
 {
     InitializeDocumentMapper();
 }