示例#1
0
        /*
         *
         * http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx
         * 9.1 Embedding Pictures in Document Header:
         *
         * //EMBEDDING LOGOS IN THE DOCUMENT
         * //SETTING FOCUES ON THE PAGE HEADER TO EMBED THE WATERMARK
         * oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;
         *
         * //THE LOGO IS ASSIGNED TO A SHAPE OBJECT SO THAT WE CAN USE ALL THE
         * //SHAPE FORMATTING OPTIONS PRESENT FOR THE SHAPE OBJECT
         * Word.Shape logoCustom = null;
         *
         * //THE PATH OF THE LOGO FILE TO BE EMBEDDED IN THE HEADER
         * String logoPath = "C:\\Document and Settings\\MyLogo.jpg";
         * logoCustom = oWord.Selection.HeaderFooter.Shapes.AddPicture(logoPath,
         * ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
         *
         * logoCustom.Select(ref oMissing);
         * logoCustom.Name = "CustomLogo";
         * logoCustom.Left = (float)Word.WdShapePosition.wdShapeLeft;
         *
         * //SETTING FOCUES BACK TO DOCUMENT
         * oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
         *
         */


        public static void CompareDocuments(object fromFileName, string toFileName)
        {
            if (!File.Exists((string)fromFileName))
            {
                MessageBox.Show("File not found. " + fromFileName);
                return;
            }


            Word.Application vkWordApp =
                new Word.Application();

            object vkReadOnly = false;
            object vkVisible  = true;
            object vkFalse    = false;
            object vkTrue     = true;
            object vkDynamic  = 2;


            object vkMissing = System.Reflection.Missing.Value;

            // Let's make the word application visible
            vkWordApp.Visible = true;
            vkWordApp.Activate();

            // Let's open the document
            Word.Document vkMyDoc = vkWordApp.Documents.Open(
                ref fromFileName, ref vkMissing, ref vkReadOnly,
                ref vkMissing, ref vkMissing, ref vkMissing,
                ref vkMissing, ref vkMissing, ref vkMissing,
                ref vkMissing, ref vkMissing, ref vkVisible);

            vkMyDoc.Compare(toFileName);

            vkMyDoc.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc);

            vkWordApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vkWordApp);

            return;
        }