OSDN Git Service

Share resource file between TortoiseGitBlame and TortoiseProc
[tortoisegit/TortoiseGitJp.git] / contrib / other / diff-scripts / diff-xlsx.vbs
1 '\r
2 ' TortoiseSVN Diff script for Excel files\r
3 '\r
4 ' Copyright (C) 2004-2008 the TortoiseSVN team\r
5 ' This file is distributed under the same license as TortoiseSVN\r
6 '\r
7 ' Last commit by:\r
8 ' $Author: luebbe $\r
9 ' $Date: 2008-06-13 21:52:53 +0800 (Fri, 13 Jun 2008) $\r
10 ' $Rev: 13247 $\r
11 '\r
12 ' Authors:\r
13 ' Michael Joras <michael@joras.net>, 2008\r
14 ' Suraj Barkale, 2006\r
15 '\r
16 \r
17 dim objExcelApp, objArgs, objScript, objBaseDoc, objNewDoc, objWorkSheet, i\r
18 \r
19 Set objArgs = WScript.Arguments\r
20 num = objArgs.Count\r
21 if num < 2 then\r
22    MsgBox "Usage: [CScript | WScript] compare.vbs base.doc new.doc", vbExclamation, "Invalid arguments"\r
23    WScript.Quit 1\r
24 end if\r
25 \r
26 sBaseDoc = objArgs(0)\r
27 sNewDoc = objArgs(1)\r
28 \r
29 Set objScript = CreateObject("Scripting.FileSystemObject")\r
30 If objScript.FileExists(sBaseDoc) = False Then\r
31     MsgBox "File " + sBaseDoc +" does not exist.  Cannot compare the documents.", vbExclamation, "File not found"\r
32     Wscript.Quit 1\r
33 End If\r
34 If objScript.FileExists(sNewDoc) = False Then\r
35     MsgBox "File " + sNewDoc +" does not exist.  Cannot compare the documents.", vbExclamation, "File not found"\r
36     Wscript.Quit 1\r
37 End If\r
38 \r
39 Set objScript = Nothing\r
40 \r
41 On Error Resume Next\r
42 Set objExcelApp = Wscript.CreateObject("Excel.Application")\r
43 If Err.Number <> 0 Then\r
44    Wscript.Echo "You must have Excel installed to perform this operation."\r
45    Wscript.Quit 1\r
46 End If\r
47 \r
48 'Open base excel sheet\r
49 objExcelApp.Workbooks.Open sBaseDoc\r
50 'Open new excel sheet\r
51 objExcelApp.Workbooks.Open sNewDoc\r
52 'Show Excel window\r
53 objExcelApp.Visible = True\r
54 'Create a compare side by side view\r
55 objExcelApp.Windows.CompareSideBySideWith(objExcelApp.Windows(2).Caption)\r
56 If Err.Number <> 0 Then\r
57         objExcelApp.Application.WindowState = xlMaximized\r
58         objExcelApp.Windows.Arrange(-4128)\r
59 End If\r
60 \r
61 'Mark differences in sNewDoc red\r
62 i = 1\r
63 \r
64 For Each objWorkSheet In objExcelApp.Workbooks(2).Worksheets\r
65 \r
66                 objworksheet.Cells.FormatConditions.Delete\r
67 \r
68                 objExcelApp.Workbooks(1).Sheets(i).Copy ,objExcelApp.Workbooks(2).Sheets(objExcelApp.Workbooks(2).Sheets.Count)\r
69 \r
70                 objExcelApp.Workbooks(2).Sheets(objExcelApp.Workbooks(2).Sheets.Count).Name = "Dummy_for_Comparison" & i\r
71 \r
72                 objworksheet.Activate\r
73                 'To create a local formula the cell A1 is used\r
74                 original_content = objworksheet.Cells(1,1).Formula\r
75                 String sFormula\r
76                 'objworksheet.Cells(1,1).Formula = "=INDIRECT(""" & objExcelApp.Workbooks(2).Sheets(i).name & " (2)"& "!""&ADDRESS(ROW(),COLUMN()))"\r
77                 objworksheet.Cells(1,1).Formula = "=INDIRECT(""Dummy_for_Comparison" & i & "!""&ADDRESS(ROW(),COLUMN()))" \r
78                 sFormula = objworksheet.Cells(1,1).FormulaLocal\r
79 \r
80                 objworksheet.Cells(1,1).Formula = original_content\r
81                 'with the local formula the conditional formatting is used to mark the cells that are different\r
82                 const xlCellValue = 1\r
83                 const xlNotEqual = 4\r
84                 objworksheet.Cells.FormatConditions.Add xlCellValue, xlNotEqual, sFormula\r
85                 objworksheet.Cells.FormatConditions(1).Interior.ColorIndex = 3\r
86 \r
87         i = i + 1 \r
88 next\r