Đây có thể là một cách tiếp cận (cho Visual Studio 2010)
tôi pha trộn với nhau hai liên kết sau
http://social.msdn.microsoft.com/Forums/en-US/b7f4b480-ca1c-49a1-a2ea-b1d1cf5ad56b/how-do-you-compare-two-word-documents-in-c
http://msdn.microsoft.com/en-us/library/vstudio/ee342218%28v=vs.100%29.aspx
đến một điều khiển dự án C# mà tôi thêm vào thêm Tài liệu tham khảo: .NET -> Microsoft.Office.Interop.Word Phiên bản 14.0.0.0
đây nguồn:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
//using Office = Microsoft.Office.Core;
//using Microsoft.Office.Tools.Word;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Word.Application wordApp = new Word.Application();
wordApp.Visible = false;
object wordTrue = (object)true;
object wordFalse = (object)false;
object fileToOpen = @"C:\Temp\1.docx";
object missing = Type.Missing;
Word.Document doc1 = wordApp.Documents.Open(ref fileToOpen,
ref missing, ref wordFalse, ref wordFalse, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref wordTrue, ref missing,
ref missing, ref missing, ref missing);
object fileToOpen1 = @"C:\Temp\2.docx";
Word.Document doc2 = wordApp.Documents.Open(ref fileToOpen1,
ref missing, ref wordFalse, ref wordFalse, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
Word.Document doc = wordApp.CompareDocuments(doc1, doc2, Word.WdCompareDestination.wdCompareDestinationNew, Word.WdGranularity.wdGranularityWordLevel,
true, true, true, true, true, true, true, true, true, true, "", true);
doc1.Close(ref missing,ref missing,ref missing);
doc2.Close(ref missing,ref missing,ref missing);
wordApp.Visible = true;
}
}
}
TODO:
- Thay 1.docx và 2.docx với chuỗi từ dòng lệnh
- có thể một số ngoại lệ xử lý
Có, có vẻ là một cách nhưng làm cách nào tôi có thể tự động chuyển từ trong chế độ so sánh? – araaku
Sử dụng chức năng này: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.windows.comparesidebysidewith.aspx – ZippyV