在命令提示符下以"比较文档"模式打开Microsoft Word

ara*_*aku 15 command-line ms-word

我正在开发一个Web项目,其中客户端需要首先上传一些MS Word文档的功能,然后他可以比较任何两个上传的文档.

我想出的想法是首先使用WEBDAV使文档可用,然后使用命令行打开两个文档并使用"并排比较"选项.通过这种方式,他将能够比较和修改两个文档.

问题是,我无法找到任何可以从命令提示符运行的命令,以在比较模式下打开两个文档.

此外,如果您知道任何其他方式来实现此功能,请与我分享.

gre*_*nix 6

这可能是一种方法(对于Visual Studio 2010)

我将以下两个链接混合在一起

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

到我添加的C#控制台项目添加了参考:.NET - > Microsoft.Office.Interop.Word版本14.0.0.0

来源:

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;
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

去做:

  • 用命令行中的字符串替换1.docx和2.docx
  • 也许是一些异常处理


jtp*_*yda 5

有一个项目可以使用 PowerShell 脚本 ExtDiff:https : //github.com/ForNeVeR/ExtDiff


Zip*_*pyV 2

我查看了命令行开关列表,但没有看到任何相关内容。

您可以在 .net 中创建一个控制台应用程序,用于打开 Word、加载两个文档并将 Word 切换到比较文档视图模式。您无需直接从命令行启动 Word,而是启动应用程序。