Repository navigation
Expand file tree
/
Copy pathDiffWord.ps1
More file actions
74 lines (68 loc) · 2.85 KB
/
Copy pathDiffWord.ps1
File metadata and controls
74 lines (68 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$ErrorActionPreference = "Stop"
$Title = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
## 本体 #######################################################################
function local:DiffWord([System.IO.FileInfo] $LHS, [System.IO.FileInfo] $RHS) {
try {
$AppDOC = New-Object -ComObject Word.Application
$AppDOC.Visible = $true
$AppDOC.DisplayAlerts = 0 # wdAlertsNone
if ($LHS.LastWriteTime -le $RHS.LastWriteTime) {
$DocLHS = $AppDOC.Documents.Open($LHS.FullName, $false, $true)
$DocRHS = $AppDOC.Documents.Open($RHS.FullName, $false, $true)
} else {
$DocLHS = $AppDOC.Documents.Open($RHS.FullName, $false, $true)
$DocRHS = $AppDOC.Documents.Open($LHS.FullName, $false, $true)
}
$null = $AppDOC.CompareDocuments(
$DocLHS, # OriginalDocument
$DocRHS, # RevisedDocument
2, # Destination wdCompareDestinationNew=2
1, # Granularity wdGranularityWordLevel=1
$False, # CompareFormatting
$False, # CompareCaseChanges
$False, # CompareWhitespace
$True, # CompareTables
$False, # CompareHeaders
$False, # CompareFootnotes
$True, # CompareTextboxes
$True, # CompareFields
$False, # CompareComments
$False # CompareMoves
)
} finally {
if($null -ne $DocRHS){
$null = $DocRHS.Close(0)
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($DocRHS)
}
if($null -ne $DocLHS){
$null = $DocLHS.Close(0)
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($DocLHS)
}
# 差分表示が目的であるため閉じない
# if($null -ne $AppDOC){
# $AppDOC.Quit(); $AppDOC = $null
# $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($AppDOC)
# }
}
}
###############################################################################
# $args = @("$($ENV:USERPROFILE)\Desktop\新しいフォルダー\aaa.docx", "$($ENV:USERPROFILE)\Desktop\新しいフォルダー\bbb.docx")
try {
$null = Write-Host "---$Title---"
# 引数確認
if ($args.Count -ne 2) {
exit
}
# 処理実行
$exist = $true
$exist = $exist -and (Test-Path -LiteralPath $args[0])
$exist = $exist -and (Test-Path -LiteralPath $args[1])
if ($exist) {
DiffWord (Get-Item -LiteralPath $args[0]) (Get-Item -LiteralPath $args[1])
}
} catch {
$null = Write-Host "---例外発生---"
$null = Write-Host $_.Exception.Message
$null = Write-Host $_.ScriptStackTrace
$null = Write-Host "--------------"
}