Exemplo n.º 1
0
 public UndoerRedoer(Document document)
 {
     if (document == null)
     {
         throw new ArgumentNullException(nameof(document));
     }
     _document = document;
 }
Exemplo n.º 2
0
 private void SetupDocument()
 {
     if (Globals.ThisAddIn.Application.Documents.Count > 0)
     {
         nativeDocument = Globals.ThisAddIn.Application.ActiveDocument;
         Populate();
         Microsoft.Office.Tools.Word.Document vstoDoc = (Microsoft.Office.Tools.Word.Document)Globals.Factory.GetVstoObject(nativeDocument);
         vstoDoc.SelectionChange += new Microsoft.Office.Tools.Word.SelectionEventHandler(ThisDocument_SelectionChange);
     }
 }
        private void Search()
        {
            string textToSearch = txtLookupText.Text;

            if (!string.IsNullOrEmpty(textToSearch))
            {
                try
                {
                    Microsoft.Office.Tools.Word.Document document = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
                    if (document != null)
                    {
                        //TODO
                        //Draw shapes on other pages on scroll
                        IntPtr      handle      = new IntPtr(document.ActiveWindow.Hwnd);
                        ScrollEvent scrollEvent = new ScrollEvent();
                        scrollEvent.AssignHandle(handle);

                        document.BeforeSave  += Document_BeforeSave;
                        document.BeforeClose += Document_BeforeClose;

                        DeleteShapes();

                        Range currentlyVisibleRange = GetCurrentlyVisibleRange();

                        foreach (Range word in document.Words)
                        {
                            if (word.Text.Trim().ToLower() == textToSearch.Trim().ToLower())
                            {
                                if (Intersects(currentlyVisibleRange, word))
                                {
                                    float leftPosition = (float)word.Information[WdInformation.wdHorizontalPositionRelativeToPage];
                                    float topPosition  = (float)word.Information[WdInformation.wdVerticalPositionRelativeToPage];

                                    document.ActiveWindow.GetPoint(out int left, out int top, out int width, out int height, word);
                                    var wordWidth  = width - (width * 28 / 100);
                                    var wordHeight = word.Font.Size + (word.Font.Size * 28 / 100);
                                    DrawIt(word, leftPosition, topPosition, wordWidth, wordHeight);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
 private void DeleteShapes()
 {
     Microsoft.Office.Tools.Word.Document document = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
     if (document != null)
     {
         var shapes       = document.Shapes;
         var shapesCount  = shapes.Count;
         int deletedCount = 0;
         for (var i = 1; i <= shapesCount; i++)
         {
             var shape = shapes[i - deletedCount];
             if (shape.Name == SHAPE_NAME)
             {
                 shape.Delete();
                 deletedCount++;
             }
         }
     }
 }
        ////////////////////////////////////////
            //        MS-Word Processing
            ////////////////////////////////////////

            //Word.ApplicationClass wordApp = new Word.ApplicationClass();

        private void Func1()
        {
            Microsoft.Office.Interop.Word.ApplicationClass oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
            Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();

            object fileName = (object)@"D:\Documents and Settings\Haim\Desktop\Kan-Naim\test.doc";
            //object fileName = (object)@"D:\Documents and Settings\Haim\Desktop\Kan-Naim\ArticleEditor.doc";
            object oMissing = System.Reflection.Missing.Value;

            oWordApp.Visible = true;
            oWordDoc = oWordApp.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            oWordDoc.ActiveWindow.Selection.WholeStory();
            oWordDoc.ActiveWindow.Selection.Copy();

            IDataObject data = Clipboard.GetDataObject();

            if (data != null) richTextBox1.Text = data.GetData(DataFormats.Text).ToString();

            object oTrue = true;
            object oFalse = false;

            Object oTemplatePath = (object)@"D:\Documents and Settings\Haim\Desktop\Kan-Naim\ArticleTemplate.dotx";
            oWordDoc = oWordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oTrue);

            Microsoft.Office.Tools.Word.RichTextContentControl richTextContentControl1;
            Microsoft.Office.Tools.Word.Document oWordTools = new Microsoft.Office.Tools.Word.Document();
            //oWordTools.Application.ActiveDocument.ContentControls = oWordApp;
            oWordTools.Paragraphs[1].Range.InsertParagraphBefore();
            oWordTools.Paragraphs[1].Range.Select();
            richTextContentControl1 = oWordTools.Controls.AddRichTextContentControl("richTextControl1");
            richTextContentControl1.PlaceholderText = "Enter your first name";

            //oWordDoc.ContentControls.get_Item(

        }
Exemplo n.º 6
0
        private void GetBetterImg()
        {
            Range rangeAll = Globals.ThisAddIn.Application.ActiveDocument.Range();

            //range.SetRange(0,0);

            //while(range.End<rangeAll.End)
            //{
            //    range.Start = range.Start + 100;
            //    range.End = range.End + 100;
            //    Globals.ThisAddIn.Application.ActiveWindow.ScrollIntoView(range);
            //}



            object filename = @"D:\BaoProject\高分宝三期\2014届高三数学理科模拟试题(定稿).doc";  //文件保存路径
            Object Nothing  = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    WordDoc = WordApp.Documents.Add(ref filename, ref Nothing, ref Nothing, ref Nothing);


            Range range = WordDoc.Range(0, 500);



            range.Copy();



            rangeAll.Paste();

            rangeAll = Globals.ThisAddIn.Application.ActiveDocument.Range();

            rangeAll.SetRange(rangeAll.End, rangeAll.End);
            rangeAll.Select();

            System.Windows.Point pointend = CaretPos();

            rangeAll.SetRange(0, 0);
            rangeAll.Select();

            Microsoft.Office.Tools.Word.Document document = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
            Microsoft.Office.Tools.Word.DropDownListContentControl dropdown = document.Controls.AddDropDownListContentControl(rangeAll, "MyContentControl");
            dropdown.PlaceholderText = "My DropdownList Test";
            dropdown.DropDownListEntries.Add("Test01", "01", 1);
            dropdown.DropDownListEntries.Add("Test02", "02", 2);
            dropdown.DropDownListEntries.Add("Test03", "03", 3);

            rangeAll.SetRange(dropdown.Range.End + 1, dropdown.Range.End + 1);

            System.Drawing.Point o = new System.Drawing.Point(dropdown.Application.Left, dropdown.Application.Top);

            System.Drawing.Point o1 = this.PointToScreen(o);


            rangeAll.SetRange(0, 0);
            rangeAll.Select();

            System.Drawing.Point currentPos = GetPositionForShowing(Globals.ThisAddIn.Application.Selection);
            //Globals.ThisAddIn._FloatingPanel = new FloatingPanel(bookmark);



            rangeAll.Text = rangeAll.Text + "\n" + dropdown.Application.Top + "::::" + dropdown.Application.Left + "\n" + o1.X + "::::::" + o1.Y + "\n" + currentPos.X + "::::::" + currentPos.Y;


            Bitmap image = new Bitmap(currentPos.X, currentPos.Y);

            Graphics g = Graphics.FromImage(image);

            System.Drawing.Point FrmP = new System.Drawing.Point(currentPos.X, currentPos.Y);
            //ScreenP返回相对屏幕的坐标
            System.Drawing.Point ScreenP = this.PointToScreen(FrmP);

            g.CopyFromScreen(0, 0, 0, 0, image.Size);

            image.Save(@"C:\Users\Word\Desktop\3523433.png", System.Drawing.Imaging.ImageFormat.Png);

            int i = 0;
            //Image imgTemp = Metafile.FromStream(new MemoryStream(range.EnhMetaFileBits));

            //imgTemp.Save(@"C:\Users\Word\Desktop\1233.png", System.Drawing.Imaging.ImageFormat.Png);
        }