我尝试通过代码打开两个文档,使用户可以比较版本(法律黑线) - 文档的编辑将在可见文档中完成。
那是我的代码片段:
objectoMissing = System.Reflection.Missing.Value;
//Start Word and create a new document.
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oWord.DefaultLegalBlackline.....
答案 0 :(得分:1)
请参阅下面的课程作为示例解决方案:
using WordR = Microsoft.Office.Interop.Word;
namespace WordTest
{
class TestComparison
{
private void openWordForComparison(object filenameMaster, object filenameModified)
{
WordR.Application app = null;
WordR.Document docMaster = null;
WordR.Document docModified = null;
WordR.Document docComparison = null;
object missing = System.Reflection.Missing.Value;
//create a readonly variable of object type and assign it to false.
object readonlyobj = false;
//create a word application object for processing the word file.
app = new WordR.Application();
// Open frist document
docMaster = app.Documents.Open(
ref filenameMaster, ref missing, ref readonlyobj, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
// Open second document
docModified = app.Documents.Open(
ref filenameModified, ref missing, ref readonlyobj, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
// open a new document for comparison of documents
docComparison = app.CompareDocuments(docMaster, docModified);
// close first and second document to display comparison only
docMaster.Close(ref missing, ref missing, ref missing);
docModified.Close(ref missing, ref missing, ref missing);
app.Visible = true;
}
}
}
答案 1 :(得分:0)
我找到了一个解决方案:
oDoc1 = oWord.Documents.Open(@"Word1.docx", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
oDoc2 = oWord.Documents.Open(@"Word2.docx", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
oDoc = oWord.CompareDocuments(oDoc1, oDoc2, Microsoft.Office.Interop.Word.WdCompareDestination.wdCompareDestinationOriginal, Microsoft.Office.Interop.Word.WdGranularity.wdGranularityCharLevel, true, false, true, true, false, false, false, false, false, false, "", false);
oDoc2.Close(oMissing,oMissing,oMissing);
是否有解决方案没有首先打开两个文档然后关闭第二个没有打开的文档,因为它不需要。