在“比较文档”中打开Microsoft Word模式从命令提示符 [英] Open Microsoft Word in "compare document" mode from command prompt
问题描述
我正在开发一个web项目,其中客户端需要一个功能,首先上传一些MS Word文档&那么他可以比较任何两个上传的文档。
我想出的想法是首先使用WEBDAV&然后使用具有并排比较选项的命令行打开这两个文档。以这种方式,他将能够比较&修改两个文档。
问题是,我找不到任何命令,可以从命令提示符处以比较模式打开两个文档。
这可能是一种方法(对于Visual Studio 2010)
我混合了以下两个链接
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;
使用Word = Microsoft.Office.Interop.Word;
// using Office = Microsoft.Office.Core;
// using Microsoft.Office.Tools.Word;
命名空间ConsoleApplication1
{
类程序
{
static void Main(string [] args)
{
Word。应用程序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);
对象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:
- 使用命令行中的字符串替换1.docx和2.docx
- 也许是一些异常处理
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.
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.
This may be an approach (for Visual Studio 2010)
I mixed together the two following links
http://msdn.microsoft.com/en-us/library/vstudio/ee342218%28v=vs.100%29.aspx
to a C# Console Project to which I added added the Reference: .NET --> Microsoft.Office.Interop.Word Version 14.0.0.0
here the source:
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:
- Replace 1.docx and 2.docx with strings from command line
- maybe some Exception handling
这篇关于在“比较文档”中打开Microsoft Word模式从命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!