在“比较文档"中打开 Microsoft Word命令提示符模式 [英] Open Microsoft Word in "compare document" mode from command prompt

查看:29
本文介绍了在“比较文档"中打开 Microsoft Word命令提示符模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on a web project where client needs a functionality to first upload some MS Word document & then he can compare any two of the uploaded documents.

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

The idea I came up with is to first make the documents available using WEBDAV & then open both documents using command line with "Compare side by side" option. In this way he will be able to compare & modify two documents.

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

The problem is, I am not able to find any command which can be run from command prompt to open two documents in compare mode.

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

Also, if you know any other way to achieve this functionality then please share it with me.

推荐答案

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

This may be an approach (for Visual Studio 2010)

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

I mixed together the two following links

http://social.msdn.microsoft.com/Forums/en-US/b7f4b480-ca1c-49a1-a2ea-b1d1cf5ad56b/how-do-you-compare-two-word-文档中的 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

to a C# Console Project to which I added added the Reference: .NET --> Microsoft.Office.Interop.Word Version 14.0.0.0

来源:

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:Temp1.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:Temp2.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;
        }

    }
}

待办事项:

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

这篇关于在“比较文档"中打开 Microsoft Word命令提示符模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆