LoginSignup
6
9

More than 3 years have passed since last update.

WinMerge で MS Office ファイルを比較するプラグイン(スクリプトレット移植版)

Last updated at Posted at 2020-04-07

プラグイン紹介

WinMerge で Excel、Word、PowerPoint のファイルを比較するためのプラグインを作成しました。
WinMerge にも「CompareMSExcelFiles.sct」「CompareMSWordFiles.sct」「CompareMSPowerPointFiles.sct」が付属していますが、今回作成したものは、ファイルの読み取りに hishida 様の xdoc2txt.exe を使用しています。

S.Kohno 様の xdocdiff WinMerge Plugin、来栖光明 様の xdocdiffPlugin64 を元に、スクリプトレットに移植してみました。
元は出力されるテキストが Shift_JIS だったのを、UTF-8 で出力されるように修正しています。

ライセンスは WinMerge と同じくGPL2です。

diff.png

不具合に対処してみた経緯(2020/08/31)

問題の内容:

  • ネットワーク上のExcelファイルを比較すると、「ファイルに書き込みできません」というエラーが出たり出なかったりする。
  • 問題の位置でメッセージボックスを出すと、エラーが出なくなる。

対処:

  • Excelの内容を吐き出す先のファイルとして、空のファイルを生成しておいてから先に進むようにした。

ファイルの書き込み・読み出しのタイミングによってエラーが起きるようなので、Sleep を入れられればよかったのですが、スクリプトレットで WScript オブジェクトが使用できず、Sleep する方法が不明でした。
今のところエラーメッセージなしで動作しているので、これで様子を見ようと思います。

使い方

  1. xdoc2txt.exe は、WinMerge本体(WinMergeU.exe)と同じフォルダに配置してください。
  2. 下記のソースを、xdocdiffU.sct の名前でローカルに保存します。
  3. WinMerge をインストールしたフォルダの MergePlugins フォルダに xdocdiffU.sct を配置してください。
  4. WinMerge のメニューから「プラグイン」-「プラグインの設定」を実行すると、xdocdiffU.sct が列挙されているはずです。
  5. amb_xdocdiffplugin.dll(xdocdiffPlugin64 の本体)をすでにご利用の方は、amb_xdocdiffplugin.dllのチェックを外してください。
  6. xdocdiffU.sct の設定オプションはありません。

plugin.png

ソース

xdocdiffU.sct
<scriptlet>
<implements type="Automation" id="dispatcher">
    <property name="PluginEvent">
        <get/>
    </property>
    <property name="PluginDescription">
        <get/>
    </property>
    <property name="PluginFileFilters">
        <get/>
    </property>
    <property name="PluginIsAutomatic">
        <get/>
    </property>
    <method name="UnpackFile"/>
    <method name="PackFile"/>
    <method name="ShowSettingsDialog"/>
</implements>

<script language="VBS">

'/////////////////////////////////////////////////////////////////////////////
'    This is a plugin for WinMerge.
'    Copyright (C) 2020 stonee
'
'    Original:
'      xdocdiff WinMerge Plugin http://freemind.s57.xrea.com/xdocdiffPlugin/
'      xdocdiffPlugin64 http://crus.mydns.jp/xdocdiffPlugin64/
'
'    This program is free software; you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation; either version 2 of the License, or
'    (at your option) any later version.
'
'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.
'
'    You should have received a copy of the GNU General Public License
'    along with this program; if not, write to the Free Software
'    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
'
Option Explicit

Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim wsh: Set wsh = CreateObject("WScript.Shell")

Function get_PluginEvent()
    get_PluginEvent = "FILE_PACK_UNPACK"
End Function

Function get_PluginDescription()
    get_PluginDescription = "Display the text content of MS Word, Excel, PowerPoint and pdf files. (via xdoc2txt)"
End Function

Function get_PluginFileFilters()
    get_PluginFileFilters = "\.sxw;\.sxc;\.sxi;\.sxd;\.odt;\.ods;\.odp;\.odg;\.docx;\.docm;\.xlsx;\.xlsm;\.pptx;\.pptm;\.doc;\.xls;\.ppt;\.rtf;\.jaw;\.jtw;\.jbw;\.juw;\.jfw;\.jvw;\.jtd;\.jtt;\.oas;\.oa2;\.oa3;\.bun;\.wj2;\.wj3;\.wk3;\.wk4;\.123;\.wri;\.pdf;\.mht;\.eml$"
End Function

Function get_PluginIsAutomatic()
    get_PluginIsAutomatic = True
End Function

Function UnpackFile(fileSrc, fileDst, pbChanged, pSubcode)
    Dim objFile: Set objFile = fso.CreateTextFile(fileDst)
    objFile.WriteLine ""
    objFile.Close
    Set objFile = Nothing

    Dim cmd: cmd = "cmd /c xdoc2txt.exe -i -8 """ & fileSrc & """ > """ & fileDst & """"
    wsh.run cmd, 0, True

    pbChanged = True
    pSubcode = 0
    UnpackFile = True
End Function

Function PackFile(fileSrc, fileDst, pbChanged, pSubcode)
    PackFile = False
End Function

Function ShowSettingsDialog()
    MsgBox "No options."
End Function

</script>

</scriptlet>

6
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
9