关于SVN的word比较脚本

【2008-6月 bbs】

前面曾贴出TortoiseSVN可以调用word进行doc文件比较的图。

今天扫视了下 TortoiseSVN\Diff-Scripts目录,发现了奥秘:

diff-doc.js文件!

其内容如下:

 

QUOTE:

var objArgs,num,sBaseDoc,sNewDoc,objScript,word,destination;
// Microsoft Office versions for Microsoft Windows OS
var vOffice2000 = 9;
var vOffice2002 = 10;
var vOffice2003 = 11;
var vOffice2007 = 12;

// WdCompareTarget
var wdCompareTargetSelected = 0;
var wdCompareTargetCurrent = 1;
var wdCompareTargetNew = 2;
// WdViewType
var wdMasterView = 5;
var wdNormalView = 1;
var wdOutlineView = 2;
// WdSaveOptions
var wdDoNotSaveChanges = 0;
var wdPromptToSaveChanges = -2;
var wdSaveChanges = -1;

objArgs = WScript.Arguments;
num = objArgs.length;
if (num < 2)
{
   WScript.Echo("Usage: [CScript | WScript] diff-doc.js base.doc new.doc");
   WScript.Quit(1);
}

sBaseDoc = objArgs(0);
sNewDoc = objArgs(1);

objScript = new ActiveXObject("Scripting.FileSystemObject" );
if ( ! objScript.FileExists(sBaseDoc))
{
    WScript.Echo("File " + sBaseDoc + " does not exist.  Cannot compare the documents.");
    WScript.Quit(1);
}
if ( ! objScript.FileExists(sNewDoc))
{
    WScript.Echo("File " + sNewDoc + " does not exist.  Cannot compare the documents.");
    WScript.Quit(1);
}

objScript = null;

try
{
   word = WScript.CreateObject("Word.Application") ;
}
catch(e)
{
   WScript.Echo("You must have Microsoft Word installed to perform this operation.");
   WScript.Quit(1);
}

word.visible = true;

// Open the new document
destination = word.Documents.Open(sNewDoc) ;

// If the Type property returns either wdOutlineView or wdMasterView and the Count property returns zero, the current document is an outline.
if (((destination.ActiveWindow.View.Type == wdOutlineView) || (destination.ActiveWindow.View.Type == wdMasterView)) && (destination.Subdocuments.Count == 0))
{
    // Change the Type property of the current document to normal
    destination.ActiveWindow.View.Type = wdNormalView;
}

// Compare to the base document
if (Number(word.Version) <= vOffice2000)
{
    // Compare for Office 2000 and earlier
    destination.Compare(sBaseDoc);
}
else
{
    // Compare for Office XP (2002) and later
    destination.Compare(sBaseDoc, "Comparison", wdCompareTargetNew, true, true);
}

   
// Show the comparison result
if (Number(word.Version) < vOffice2007)
{
    word.ActiveDocument.Windows(1).Visible = 1;
}
   
// Mark the comparison document as saved to prevent the annoying
// "Save as" dialog from appearing.
word.ActiveDocument.Saved = 1;
   
// Close the first document
if (Number(word.Version) >= vOffice2002)
{
    destination.Close(wdDoNotSaveChanges);
}

这段代码揭示了用脚本控制word的冰山一角。

 收藏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值