DiffExcel.ps1


<#PSScriptInfo
 
.VERSION 1.3.1
 
.GUID c623da06-d9d6-4890-8171-627b0023c972
 
.AUTHOR zhangkq2000@hotmail.com
 
.COMPANYNAME ExcelBDD.com
 
.COPYRIGHT Copyright (c) 2023 by ExcelBDD Team, licensed under Apache 2.0 License.
 
.TAGS Excel Diff Compare
 
.LICENSEURI https://www.apache.org/licenses/LICENSE-2.0.html
 
.PROJECTURI https://dev.azure.com/simplopen/ExcelBDD/_wiki/wikis/ExcelBDD.wiki/39/ExcelBDD-Homepage
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
now supports the following features:
compare two excel files, support git diff after the responding configuration
 
#>


<#
  .SYNOPSIS
  Compare two excel files
  .DESCRIPTION
  Compare two excel files. and support git diff, for example: git diff theChangedExcelFile.
  The git diff config is needed, which is described in the below online version link.
  It provides great supports to ExcelBDD to check changes in excel file.
 
  .INPUTS
  The two files
 
  .OUTPUTS
  None.
 
  .EXAMPLE
  DiffExcel oldfile.xlsx newfile.xlsx
 
  .EXAMPLE
  DiffExcel oldfile.xlsx newfile.xlsx -Open
  #Because -Open is set, then the new file will open in Excel if any change is found.
 
  .EXAMPLE
  git diff theExcelfile.xlsx
  #if git diff config is setup,the above command will invoke DiffExcel automatically to find latest changes after last commit
  
 
  .EXAMPLE
  git diff head~2 theExcelfile.xlsx
 
  .LINK
  Online version: https://dev.azure.com/simplopen/ExcelBDD/_wiki/wikis/ExcelBDD.wiki/57/DiffExcel-Guideline
 
  .LINK
  ExcelBDD website: https://dev.azure.com/simplopen/ExcelBDD/
#>
 
[CmdletBinding()]
param (
    [Parameter()]
    [String]
    # Specifies the old file path and name.
    $OldFile,
    [Parameter()]
    [String]
    # Specifies the new file path and name.
    $NewFile,
    [Switch]
    # if Open switch is set, the new Excel file will open if any change is found.
    $Open
)

$script:StartPath = (Resolve-Path "$PSScriptRoot").Path
Write-Host $StartPath
$modulePath = Join-Path $PSScriptRoot "DiffExcel.psm1"
Import-Module $modulePath
Write-Host "==== DiffExcel ==="
Write-Host " V1.3" 
Write-Host "Author: Zhang Keqiang Mike"
Write-Host "Email: zhangkq2000@hotmail.com"

if ((-not $OldFile) -or (-not $NewFile)) {
    Write-Host "lack of file."
    return
}
if ($NewFile.IndexOf(":") -lt 0) {
    $NewFile = Join-Path $(Get-Location) $NewFile
}
if ($OldFile.IndexOf(":") -lt 0) {
    $OldFile = Join-Path $(Get-Location) $OldFile
}
Write-Host "New File: $NewFile"
Write-Host "Old File: $OldFile"
if($Open){
    Write-Host "The new file will open if any change is found."
}


Compare-Excel $OldFile $NewFile -Open:$Open | Out-Null