private static void Compare(string sourcePath, string targetPath, string resultPath)
        {
            // Create to streams of documents
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   sourceStream = assembly.GetManifestResourceStream(sourcePath);
            Stream   targetStream = assembly.GetManifestResourceStream(targetPath);
            // Opening two documents
            IComparisonDocument sourcePresentation = new ComparisonDocument(sourceStream);

            Console.WriteLine("Document with source path: " + sourcePath + " was loaded.");
            IComparisonDocument targetPresentation = new ComparisonDocument(targetStream);

            Console.WriteLine("Document with source path: " + targetPath + " was loaded.");

            // Creating settings for comparison of documents
            WordsComparisonSettings comparisonSettings = new WordsComparisonSettings();

            // Comparing documents
            IWordsCompareResult compareResult = sourcePresentation.CompareWith(targetPresentation, comparisonSettings);

            Console.WriteLine("Documents was compared.");

            // Saving result of comparison to new document
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" + resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }
Exemplo n.º 2
0
        public static void CompareTwoCreatingParagraphs()
        {
            // Creating Paragraphs
            IComparisonParagraph sourceParagraph = new ComparisonParagraph();

            sourceParagraph.AddRun("This is source Paragraph.");
            Console.WriteLine("New Paragraph was created.");

            IComparisonParagraph targetParagraph = new ComparisonParagraph();

            targetParagraph.AddRun("This is target Paragraph.");
            Console.WriteLine("New Paragraph was created.");

            // Creating settings for comparison of Paragraphs
            WordsComparisonSettings settings = new WordsComparisonSettings();
            // Comparing Paragraphs
            IWordsCompareResult compareResult = sourceParagraph.CompareWith(targetParagraph, settings);

            Console.WriteLine("Paragraphs was compared.");

            // Saving result of comparison to new document
            string resultPath          = @"./../../Components/testresult/CompareTwoCreatingParagraphs/result.docx";
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" +
                              resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }
        //ExEnd:CompareWordDcumentsFromPathToFileWithSettings

        //ExStart:CompareMultipleTargetWordDcumentsFromPathToFileWithSettings
        /// <summary>
        /// Compare Two target  word processing documents using method MultiCompareWith from file path with saving results into a file with document settings
        /// </summary>
        public static void ComparetwoTargetWordDcumentsFromPathToFileWithSettings()
        {
            // Create list of targets documents
            List <IComparisonDocument> ListOfTargetDocuments = new List <IComparisonDocument>();

            // Open documents
            ComparisonDocument source  = new ComparisonDocument(Path.Combine(Common.sourcePath, Common.sourceFile));
            ComparisonDocument target1 = new ComparisonDocument(Path.Combine(Common.targetPath, "target.docx"));
            ComparisonDocument target2 = new ComparisonDocument(Path.Combine(Common.targetPath, "target2.docx"));

            // Add target documents in list
            ListOfTargetDocuments.Add(target1);
            ListOfTargetDocuments.Add(target2);

            // Call method MultiCompareWith
            IWordsCompareResult result = source.MultiCompareWith(ListOfTargetDocuments, new WordsComparisonSettings {
                StyleChangeDetection = true, ShowDeletedContent = true, IsMultipleComparison = true, GenerateSummaryPage = true
            });

            // Call GetDocument() method
            IComparisonDocument resultDocument = result.GetDocument();

            // Call Save() method
            resultDocument.Save(Path.Combine(Common.resultPath, Common.resultFile), ComparisonSaveFormat.Docx);
        }
Exemplo n.º 4
0
        public static void CompareTwoCreatingCells()
        {
            // Creating Cells
            IComparisonCell      sourceCell = new ComparisonCell();
            IComparisonParagraph paragraph  = sourceCell.AddParagraph();

            paragraph.AddRun("This is Cell of source table.");
            Console.WriteLine("New Column was created.");

            IComparisonCell targetCell = new ComparisonCell();

            paragraph = targetCell.AddParagraph();
            paragraph.AddRun("This is Cell of target table.");
            Console.WriteLine("New Column was created.");

            // Creating settings for comparison of Cells
            WordsComparisonSettings settings = new WordsComparisonSettings();
            // Comparing Cells
            IWordsCompareResult compareResult = sourceCell.CompareWith(targetCell, settings);

            Console.WriteLine("Cells was compared.");

            // Saving result of comparison to new document
            string resultPath          = @"./../../Components/testresult/CompareTwoCreatingCells/result.docx";
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" +
                              resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }
Exemplo n.º 5
0
 public PreviewModel(IComparisonDocument document)
 {
     ComparisonDocument = document;
     FileName = ComparisonDocument.FileName;
     asm = System.Reflection.Assembly.LoadFrom("Workshare.Utilities.dll");
     _lcfm = Activator.CreateInstance(asm.GetType("Workshare.Utilities.LocalCopyOfFileManager"));
     PreviewImages = new List<Bitmap>();
     LoadModel();
 }
Exemplo n.º 6
0
        //ExStart:CompareWordDcumentsFromStreamToFile
        /// <summary>
        /// Compare two word processing documents from streams with saving results into a file
        /// </summary>
        public static string CompareWordDcumentsFromStreamToFile(Stream sourceStream, Stream targetStream, string resultFile)
        {
            IComparisonDocument     sourcePresentation = new ComparisonDocument(sourceStream);
            IComparisonDocument     targetPresentation = new ComparisonDocument(targetStream);
            WordsComparisonSettings comparisonSettings = new WordsComparisonSettings();
            IWordsCompareResult     compareResult      = sourcePresentation.CompareWith(targetPresentation, comparisonSettings);
            // Saving result of comparison to new document
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultFile, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();

            return(resultFile);
        }
Exemplo n.º 7
0
        public static void CompareColumnFromDocumentWithCreatingColumn()
        {
            string sourcePath =
                @"GroupDocs.Comparison.Samples.Words.Components.data.CompareColumnFromDocumentWithCreatingColumn.source.docx";

            // Create to stream of document
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   sourceStream = assembly.GetManifestResourceStream(sourcePath);

            // Opening source document
            IComparisonDocument sourceDocument = new ComparisonDocument(sourceStream);

            Console.WriteLine("Document with source path: " + sourcePath + " was loaded.");

            // Getting first Column from source document
            IComparisonColumn sourceColumn = (sourceDocument.Sections[0].Body.GetChildNodes(ComparisonNodeType.Table, false)[0] as IComparisonTable).Columns[0];

            // Creating Column
            IComparisonColumn    targetColumn = new ComparisonColumn(100, new double[] { 20, 20, 20 });
            IComparisonParagraph paragraph    = targetColumn.Cells[0].AddParagraph();

            paragraph.AddRun("This is cell.");
            paragraph = targetColumn.Cells[1].AddParagraph();
            paragraph.AddRun("This is Cell of target table.");
            paragraph = targetColumn.Cells[2].AddParagraph();
            paragraph.AddRun("This is Cell.");
            Console.WriteLine("New Column was created.");

            // Creating settings for comparison of Columns
            WordsComparisonSettings settings = new WordsComparisonSettings();
            // Comparing Columns
            IWordsCompareResult compareResult = sourceColumn.CompareWith(targetColumn, settings);

            Console.WriteLine("Columns was compared.");

            // Saving result of comparison to new document
            string resultPath          = @"./../../Components/testresult/CompareColumnFromDocumentWithCreatingColumn/result.docx";
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" +
                              resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }
Exemplo n.º 8
0
        public static void CompareColumnsFromDifferentDocuments()
        {
            string sourcePath =
                @"GroupDocs.Comparison.Samples.Words.Components.data.CompareColumnsFromDifferentDocuments.source.docx";
            string targetPath =
                @"GroupDocs.Comparison.Samples.Words.Components.data.CompareColumnsFromDifferentDocuments.target.docx";

            // Create to streams of documents
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   sourceStream = assembly.GetManifestResourceStream(sourcePath);
            Stream   targetStream = assembly.GetManifestResourceStream(targetPath);

            // Opening two documents
            IComparisonDocument sourceDocument = new ComparisonDocument(sourceStream);

            Console.WriteLine("Document with source path: " + sourcePath + " was loaded.");
            IComparisonDocument targetDocument = new ComparisonDocument(targetStream);

            Console.WriteLine("Document with source path: " + targetPath + " was loaded.");

            // Getting first Column from source document
            IComparisonColumn sourceColumn = (sourceDocument.Sections[0].Body.GetChildNodes(ComparisonNodeType.Table, false)[0] as IComparisonTable).Columns[0];
            // Getting first Column from target document
            IComparisonColumn targetColumn = (targetDocument.Sections[0].Body.GetChildNodes(ComparisonNodeType.Table, false)[0] as IComparisonTable).Columns[0];

            // Creating settings for comparison of Columns
            WordsComparisonSettings settings = new WordsComparisonSettings();
            // Comparing Columns
            IWordsCompareResult compareResult = sourceColumn.CompareWith(targetColumn, settings);

            Console.WriteLine("Columns was compared.");

            // Saving result of comparison to new document
            string resultPath          = @"./../../Components/testresult/CompareColumnsFromDifferentDocuments/result.docx";
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" +
                              resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }
Exemplo n.º 9
0
        public static void CompareParagraphFromDocumentWithCreatingParagraph()
        {
            string sourcePath =
                @"GroupDocs.Comparison.Samples.Words.Components.data.CompareParagraphFromDocumentWithCreatingParagraph.source.docx";

            // Create to stream of document
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   sourceStream = assembly.GetManifestResourceStream(sourcePath);

            // Opening source document
            IComparisonDocument sourceDocument = new ComparisonDocument(sourceStream);

            Console.WriteLine("Document with source path: " + sourcePath + " was loaded.");

            // Getting first Paragraph from source document
            IComparisonParagraph sourceParagraph = sourceDocument.Sections[0].Body.GetChildNodes(ComparisonNodeType.Paragraph, false)[0] as IComparisonParagraph;

            // Creating Paragraph
            IComparisonParagraph targetParagraph = new ComparisonParagraph();

            targetParagraph.AddRun("This paragraph was created.");
            Console.WriteLine("New Paragraph was created.");

            // Creating settings for comparison of Paragraphs
            WordsComparisonSettings settings = new WordsComparisonSettings();
            // Comparing Paragraphs
            IWordsCompareResult compareResult = sourceParagraph.CompareWith(targetParagraph, settings);

            Console.WriteLine("Paragraphs was compared.");

            // Saving result of comparison to new document
            string resultPath          = @"./../../Components/testresult/CompareParagraphFromDocumentWithCreatingParagraph/result.docx";
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" +
                              resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }
Exemplo n.º 10
0
        public static void CompareTwoCreatingTables()
        {
            // Creating Tables
            IComparisonTable     sourceTable = new ComparisonTable(new double[] { 100, 100 }, new double[] { 20, 20 });
            IComparisonParagraph paragraph   = sourceTable.Rows[0].Cells[0].AddParagraph();

            paragraph.AddRun("This is cell.");
            paragraph = sourceTable.Rows[0].Cells[1].AddParagraph();
            paragraph.AddRun("This is Cell of source table.");
            paragraph = sourceTable.Rows[1].Cells[0].AddParagraph();
            paragraph.AddRun("This is Cel of tble.");
            Console.WriteLine("New Table was created.");

            IComparisonTable targetTable = new ComparisonTable(new double[] { 100, 100 }, new double[] { 20, 20 });

            paragraph = targetTable.Rows[0].Cells[0].AddParagraph();
            paragraph.AddRun("This is cell.");
            paragraph = targetTable.Rows[0].Cells[1].AddParagraph();
            paragraph.AddRun("This is Cell of target table.");
            paragraph = targetTable.Rows[1].Cells[0].AddParagraph();
            paragraph.AddRun("This is Cell of table.");
            Console.WriteLine("New Table was created.");

            // Creating settings for comparison of Tables
            WordsComparisonSettings settings = new WordsComparisonSettings();
            // Comparing Tables
            IWordsCompareResult compareResult = sourceTable.CompareWith(targetTable, settings);

            Console.WriteLine("Tables was compared.");

            // Saving result of comparison to new document
            string resultPath          = @"./../../Components/testresult/CompareTwoCreatingTables/result.docx";
            IComparisonDocument result = compareResult.GetDocument();
            Stream resultStream        = new FileStream(resultPath, FileMode.Create);

            result.Save(resultStream, ComparisonSaveFormat.Docx);
            resultStream.Close();
            Console.WriteLine("Result of comparison was saved to document with the following source path" +
                              resultPath + ".");
            Console.WriteLine("===============================================");
            Console.WriteLine("");
        }