Standardising casing of parameter names

This commit is contained in:
MikeyBronowski
2020-06-20 23:03:27 +02:00
parent 9841ef9436
commit 11d591aad6
15 changed files with 127 additions and 127 deletions

View File

@@ -87,7 +87,7 @@
if ($Reverse) { if ($Reverse) {
if ($rule.type -match 'IconSet$' ) {$rule.reverse = $true} if ($rule.type -match 'IconSet$' ) {$rule.reverse = $true}
elseif ($rule.type -match 'ColorScale$') {$temp =$rule.LowValue.Color ; $rule.LowValue.Color = $rule.HighValue.Color; $rule.HighValue.Color = $temp} elseif ($rule.type -match 'ColorScale$') {$temp =$rule.LowValue.Color ; $rule.LowValue.Color = $rule.HighValue.Color; $rule.HighValue.Color = $temp}
else {Write-Warning -Message "-Reverse was ignored because $ruletype does not support it."} else {Write-Warning -Message "-Reverse was ignored because $RuleType does not support it."}
} }
#endregion #endregion
#region set the rule conditions #region set the rule conditions

View File

@@ -11,7 +11,7 @@ function Add-ExcelName {
$ws = $Range.Worksheet $ws = $Range.Worksheet
if (-not $RangeName) { if (-not $RangeName) {
$RangeName = $ws.Cells[$Range.Start.Address].Value $RangeName = $ws.Cells[$Range.Start.Address].Value
$Range = ($Range.Worksheet.cells[($range.start.row +1), $range.start.Column , $range.end.row, $range.end.column]) $Range = ($Range.Worksheet.cells[($Range.start.row +1), $Range.start.Column , $Range.end.row, $Range.end.column])
} }
if ($RangeName -match '\W') { if ($RangeName -match '\W') {
Write-Warning -Message "Range name '$RangeName' contains illegal characters, they will be replaced with '_'." Write-Warning -Message "Range name '$RangeName' contains illegal characters, they will be replaced with '_'."

View File

@@ -96,8 +96,8 @@
$pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.Cells[$SourceRange], $pivotTableName) $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.Cells[$SourceRange], $pivotTableName)
} }
else {Write-warning "Could not create a PivotTable with the Source Range provided."; return} else {Write-warning "Could not create a PivotTable with the Source Range provided."; return}
foreach ($Row in $PivotRows) { foreach ($row in $PivotRows) {
try {$null = $pivotTable.RowFields.Add($pivotTable.Fields[$Row]) } try {$null = $pivotTable.RowFields.Add($pivotTable.Fields[$row]) }
catch {Write-Warning -message "Could not add '$row' to Rows in PivotTable $pivotTableName." } catch {Write-Warning -message "Could not add '$row' to Rows in PivotTable $pivotTableName." }
} }
foreach ($Column in $PivotColumns) { foreach ($Column in $PivotColumns) {

View File

@@ -7,7 +7,7 @@
$Referencefile , $Referencefile ,
[parameter(Mandatory=$true,Position=1)] [parameter(Mandatory=$true,Position=1)]
$Differencefile , $Differencefile ,
$WorkSheetName = "Sheet1", $WorksheetName = "Sheet1",
$Property = "*" , $Property = "*" ,
$ExcludeProperty , $ExcludeProperty ,
[Parameter(ParameterSetName='B', Mandatory)] [Parameter(ParameterSetName='B', Mandatory)]
@@ -32,19 +32,19 @@
catch { Write-Warning -Message "Could not Resolve the filenames." ; return } catch { Write-Warning -Message "Could not Resolve the filenames." ; return }
#If we have one file , we must have two different worksheet names. If we have two files we can have a single string or two strings. #If we have one file , we must have two different worksheet names. If we have two files we can have a single string or two strings.
if ($onefile -and ( ($WorkSheetName.count -ne 2) -or $WorkSheetName[0] -eq $WorkSheetName[1] ) ) { if ($onefile -and ( ($WorksheetName.count -ne 2) -or $WorksheetName[0] -eq $WorksheetName[1] ) ) {
Write-Warning -Message "If both the Reference and difference file are the same then worksheet name must provide 2 different names" Write-Warning -Message "If both the Reference and difference file are the same then worksheet name must provide 2 different names"
return return
} }
if ($WorkSheetName.count -eq 2) {$worksheet1 = $WorkSheetName[0] ; $workSheet2 = $WorkSheetName[1]} if ($WorksheetName.count -eq 2) {$worksheet1 = $WorksheetName[0] ; $worksheet2 = $WorksheetName[1]}
elseif ($WorkSheetName -is [string]) {$worksheet1 = $workSheet2 = $WorkSheetName} elseif ($WorksheetName -is [string]) {$worksheet1 = $worksheet2 = $WorksheetName}
else {Write-Warning -Message "You must provide either a single worksheet name or two names." ; return } else {Write-Warning -Message "You must provide either a single worksheet name or two names." ; return }
$params= @{ ErrorAction = [System.Management.Automation.ActionPreference]::Stop } $params= @{ ErrorAction = [System.Management.Automation.ActionPreference]::Stop }
foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}}
try { try {
$sheet1 = Import-Excel -Path $Referencefile -WorksheetName $WorkSheet1 @params $sheet1 = Import-Excel -Path $Referencefile -WorksheetName $worksheet1 @params
$sheet2 = Import-Excel -Path $Differencefile -WorksheetName $WorkSheet2 @Params $sheet2 = Import-Excel -Path $Differencefile -WorksheetName $worksheet2 @Params
} }
catch {Write-Warning -Message "Could not read the worksheet from $Referencefile and/or $Differencefile." ; return } catch {Write-Warning -Message "Could not read the worksheet from $Referencefile and/or $Differencefile." ; return }
@@ -57,7 +57,7 @@
$propList = @() $propList = @()
foreach ($p in $Property) {$propList += ($headings.where({$_ -like $p}) )} foreach ($p in $Property) {$propList += ($headings.where({$_ -like $p}) )}
foreach ($p in $ExcludeProperty) {$propList = $propList.where({$_ -notlike $p}) } foreach ($p in $ExcludeProperty) {$propList = $propList.where({$_ -notlike $p}) }
if (($headings -contains $key) -and ($propList -notcontains $Key)) {$propList += $Key} if (($headings -contains $Key) -and ($propList -notcontains $Key)) {$propList += $Key}
$propList = $propList | Select-Object -Unique $propList = $propList | Select-Object -Unique
if ($propList.Count -eq 0) {Write-Warning -Message "No Columns are selected with -Property = '$Property' and -excludeProperty = '$ExcludeProperty'." ; return} if ($propList.Count -eq 0) {Write-Warning -Message "No Columns are selected with -Property = '$Property' and -excludeProperty = '$ExcludeProperty'." ; return}
@@ -106,7 +106,7 @@
} }
} }
#if font color was specified, set it on changed properties where the same key appears in both sheets. #if font color was specified, set it on changed properties where the same key appears in both sheets.
if ($diff -and $FontColor -and (($propList -contains $Key) -or ($key -is [hashtable])) ) { if ($diff -and $FontColor -and (($propList -contains $Key) -or ($Key -is [hashtable])) ) {
$updates = $diff.where({$_.SideIndicator -ne "=="}) | Group-object -Property $Key | Where-Object {$_.count -eq 2} $updates = $diff.where({$_.SideIndicator -ne "=="}) | Group-object -Property $Key | Where-Object {$_.count -eq 2}
if ($updates) { if ($updates) {
$XL1 = Open-ExcelPackage -path $Referencefile $XL1 = Open-ExcelPackage -path $Referencefile
@@ -135,28 +135,28 @@
elseif ($diff -and $FontColor) {Write-Warning -Message "To match rows to set changed cells, you must specify -Key and it must match one of the included properties." } elseif ($diff -and $FontColor) {Write-Warning -Message "To match rows to set changed cells, you must specify -Key and it must match one of the included properties." }
#if nothing was found write a message which will not be redirected #if nothing was found write a message which will not be redirected
if (-not $diff) {Write-Host "Comparison of $Referencefile::$worksheet1 and $Differencefile::$WorkSheet2 returned no results." } if (-not $diff) {Write-Host "Comparison of $Referencefile::$worksheet1 and $Differencefile::$worksheet2 returned no results." }
if ($Show) { if ($Show) {
Start-Process -FilePath $Referencefile Start-Process -FilePath $Referencefile
if (-not $oneFile) { Start-Process -FilePath $Differencefile } if (-not $oneFile) { Start-Process -FilePath $Differencefile }
if ($GridView) { Write-Warning -Message "-GridView is ignored when -Show is specified" } if ($GridView) { Write-Warning -Message "-GridView is ignored when -Show is specified" }
} }
elseif ($GridView -and $propList -contains $key) { elseif ($GridView -and $propList -contains $Key) {
if ($IncludeEqual -and -not $ExcludeDifferent) { if ($IncludeEqual -and -not $ExcludeDifferent) {
$GroupedRows = $diff | Group-Object -Property $key $GroupedRows = $diff | Group-Object -Property $Key
} }
else { #to get the right now numbers on the grid we need to have all the rows. else { #to get the right now numbers on the grid we need to have all the rows.
$GroupedRows = Compare-Object -ReferenceObject $Sheet1 -DifferenceObject $Sheet2 -Property $propList -PassThru -IncludeEqual | $GroupedRows = Compare-Object -ReferenceObject $Sheet1 -DifferenceObject $Sheet2 -Property $propList -PassThru -IncludeEqual |
Group-Object -Property $key Group-Object -Property $Key
} }
#Additions, deletions and unchanged rows will give a group of 1; changes will give a group of 2 . #Additions, deletions and unchanged rows will give a group of 1; changes will give a group of 2 .
#If one sheet has extra rows we can get a single "==" result from compare, but with the row from the reference sheet #If one sheet has extra rows we can get a single "==" result from compare, but with the row from the reference sheet
#but the row in the other sheet might so we will look up the row number from the key field build a hash table for that #but the row in the other sheet might so we will look up the row number from the key field build a hash table for that
$Sheet2 | ForEach-Object -Begin {$Rowhash = @{} } -Process {$Rowhash[$_.$key] = $_._row } $Sheet2 | ForEach-Object -Begin {$rowHash = @{} } -Process {$rowHash[$_.$Key] = $_._row }
$ExpandedDiff = ForEach ($g in $GroupedRows) { $ExpandedDiff = ForEach ($g in $GroupedRows) {
#we're going to create a custom object from a hash table. We want the fields to be ordered #we're going to create a custom object from a hash table. We want the fields to be ordered
@@ -168,11 +168,11 @@
#if we have already set the side, this is the second record, so set side to indicate "changed" #if we have already set the side, this is the second record, so set side to indicate "changed"
if ($hash.Side) {$hash.side = "<>"} else {$hash["Side"] = $result.sideindicator} if ($hash.Side) {$hash.side = "<>"} else {$hash["Side"] = $result.sideindicator}
#if result is "in reference" and we don't have a matching "in difference" (meaning a change) the lookup will be blank. Which we want. #if result is "in reference" and we don't have a matching "in difference" (meaning a change) the lookup will be blank. Which we want.
$hash[">Row"] = $Rowhash[$g.Name] $hash[">Row"] = $rowHash[$g.Name]
#position the key as the next field (only appears once) #position the key as the next field (only appears once)
$Hash[$key] = $g.Name $Hash[$Key] = $g.Name
#For all the other fields we care about create <=FieldName and/or =>FieldName #For all the other fields we care about create <=FieldName and/or =>FieldName
foreach ($p in $propList.Where({$_ -ne $key})) { foreach ($p in $propList.Where({$_ -ne $Key})) {
if ($result.SideIndicator -eq "==") {$hash[("=>$P")] = $hash[("<=$P")] =$result.$P} if ($result.SideIndicator -eq "==") {$hash[("=>$P")] = $hash[("<=$P")] =$result.$P}
else {$hash[($result.SideIndicator+$P)] =$result.$P} else {$hash[($result.SideIndicator+$P)] =$result.$P}
} }
@@ -191,7 +191,7 @@
if ( $ExcludeDifferent) {$ExpandedDiff = $ExpandedDiff.where({$_.side -eq "=="}) | Sort-Object -Property "<row" ,">row" } if ( $ExcludeDifferent) {$ExpandedDiff = $ExpandedDiff.where({$_.side -eq "=="}) | Sort-Object -Property "<row" ,">row" }
elseif ( $IncludeEqual) {$ExpandedDiff = $ExpandedDiff | Sort-Object -Property "<row" ,">row" } elseif ( $IncludeEqual) {$ExpandedDiff = $ExpandedDiff | Sort-Object -Property "<row" ,">row" }
else {$ExpandedDiff = $ExpandedDiff.where({$_.side -ne "=="}) | Sort-Object -Property "<row" ,">row" } else {$ExpandedDiff = $ExpandedDiff.where({$_.side -ne "=="}) | Sort-Object -Property "<row" ,">row" }
$ExpandedDiff | Update-FirstObjectProperties | Out-GridView -Title "Comparing $Referencefile::$worksheet1 (<=) with $Differencefile::$WorkSheet2 (=>)" $ExpandedDiff | Update-FirstObjectProperties | Out-GridView -Title "Comparing $Referencefile::$worksheet1 (<=) with $Differencefile::$worksheet2 (=>)"
} }
elseif ($GridView ) {Write-Warning -Message "To use -GridView you must specify -Key and it must match one of the included properties." } elseif ($GridView ) {Write-Warning -Message "To use -GridView you must specify -Key and it must match one of the included properties." }
elseif (-not $PassThru) {return ($diff | Select-Object -Property (@(@{n="_Side";e={$_.SideIndicator}},"_File" ,"_Sheet","_Row") + $propList))} elseif (-not $PassThru) {return ($diff | Select-Object -Property (@(@{n="_Side";e={$_.SideIndicator}},"_File" ,"_Sheet","_Row") + $propList))}

View File

@@ -3,56 +3,56 @@
param ( param (
[parameter(Mandatory=$true)] [parameter(Mandatory=$true)]
$Path, $Path,
$workSheetname = "Sheet1" , $WorksheetName = "Sheet1" ,
[parameter(Mandatory=$true)] [parameter(Mandatory=$true)]
$range, $Range,
$destination = "$pwd\temp.png", $Destination = "$pwd\temp.png",
[switch]$show [switch]$Show
) )
$extension = $destination -replace '^.*\.(\w+)$' ,'$1' $extension = $Destination -replace '^.*\.(\w+)$' ,'$1'
if ($extension -in @('JPEG','BMP','PNG')) { if ($extension -in @('JPEG','BMP','PNG')) {
$Format = [system.Drawing.Imaging.ImageFormat]$extension $Format = [system.Drawing.Imaging.ImageFormat]$extension
} #if we don't recognise the extension OR if it is JPG with an E, use JPEG format } #if we don't recognise the extension OR if it is JPG with an E, use JPEG format
else { $Format = [system.Drawing.Imaging.ImageFormat]::Jpeg} else { $Format = [system.Drawing.Imaging.ImageFormat]::Jpeg}
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Starting Excel" Write-Progress -Activity "Exporting $Range of $WorksheetName in $Path" -Status "Starting Excel"
$xlApp = New-Object -ComObject "Excel.Application" $xlApp = New-Object -ComObject "Excel.Application"
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Opening Workbook and copying data" Write-Progress -Activity "Exporting $Range of $WorksheetName in $Path" -Status "Opening Workbook and copying data"
$xlWbk = $xlApp.Workbooks.Open($Path) $xlWbk = $xlApp.Workbooks.Open($Path)
$xlWbk.Worksheets($workSheetname).Select() $xlWbk.Worksheets($WorksheetName).Select()
$null = $xlWbk.ActiveSheet.Range($range).Select() $null = $xlWbk.ActiveSheet.Range($Range).Select()
$null = $xlApp.Selection.Copy() $null = $xlApp.Selection.Copy()
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Saving copied data" Write-Progress -Activity "Exporting $Range of $WorksheetName in $Path" -Status "Saving copied data"
# Get-Clipboard came in with PS5. Older versions can use [System.Windows.Clipboard] but it is ugly. # Get-Clipboard came in with PS5. Older versions can use [System.Windows.Clipboard] but it is ugly.
$image = Get-Clipboard -Format Image $image = Get-Clipboard -Format Image
$image.Save($destination, $Format) $image.Save($Destination, $Format)
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Closing Excel" Write-Progress -Activity "Exporting $Range of $WorksheetName in $Path" -Status "Closing Excel"
$null = $xlWbk.ActiveSheet.Range("a1").Select() $null = $xlWbk.ActiveSheet.Range("a1").Select()
$null = $xlApp.Selection.Copy() $null = $xlApp.Selection.Copy()
$xlApp.Quit() $xlApp.Quit()
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Completed Write-Progress -Activity "Exporting $Range of $WorksheetName in $Path" -Completed
if ($show) {Start-Process -FilePath $destination} if ($Show) {Start-Process -FilePath $Destination}
else {Get-Item -Path $destination} else {Get-Item -Path $Destination}
} }
<# <#
del demo*.xlsx del demo*.xlsx
$workSheetname = 'Processes' $worksheetName = 'Processes'
$Path = "$pwd\demo.xlsx" $Path = "$pwd\demo.xlsx"
$myData = Get-Process | Select-Object -Property Name,WS,CPU,Description,company,startTime $myData = Get-Process | Select-Object -Property Name,WS,CPU,Description,company,startTime
$excelPackage = $myData | Export-Excel -KillExcel -Path $Path -WorkSheetname $workSheetname -ClearSheet -AutoSize -AutoFilter -BoldTopRow -FreezeTopRow -PassThru $excelPackage = $myData | Export-Excel -KillExcel -Path $Path -WorkSheetname $worksheetName -ClearSheet -AutoSize -AutoFilter -BoldTopRow -FreezeTopRow -PassThru
$workSheet = $excelPackage.Workbook.Worksheets[$workSheetname] $worksheet = $excelPackage.Workbook.Worksheets[$worksheetName]
$range = $workSheet.Dimension.Address $range = $worksheet.Dimension.Address
Set-ExcelRange -Worksheet $workSheet -Range "b:b" -NumberFormat "#,###" -AutoFit Set-ExcelRange -Worksheet $worksheet -Range "b:b" -NumberFormat "#,###" -AutoFit
Set-ExcelRange -Worksheet $workSheet -Range "C:C" -NumberFormat "#,##0.00" -AutoFit Set-ExcelRange -Worksheet $worksheet -Range "C:C" -NumberFormat "#,##0.00" -AutoFit
Set-ExcelRange -Worksheet $workSheet -Range "F:F" -NumberFormat "dd MMMM HH:mm:ss" -AutoFit Set-ExcelRange -Worksheet $worksheet -Range "F:F" -NumberFormat "dd MMMM HH:mm:ss" -AutoFit
Add-ConditionalFormatting -Worksheet $workSheet -Range "c2:c1000" -DataBarColor Blue Add-ConditionalFormatting -Worksheet $worksheet -Range "c2:c1000" -DataBarColor Blue
Add-ConditionalFormatting -Worksheet $workSheet -Range "b2:B1000" -RuleType GreaterThan -ConditionValue '104857600' -ForeGroundColor "Red" -Bold Add-ConditionalFormatting -Worksheet $worksheet -Range "b2:B1000" -RuleType GreaterThan -ConditionValue '104857600' -ForeGroundColor "Red" -Bold
Export-Excel -ExcelPackage $excelPackage -WorkSheetname $workSheetname Export-Excel -ExcelPackage $excelPackage -WorksheetName $worksheetName
Convert-ExcelRangeToImage -Path $Path -workSheetname $workSheetname -range $range -destination "$pwd\temp.png" -show Convert-ExcelRangeToImage -Path $Path -WorksheetName $worksheetName -range $range -destination "$pwd\temp.png" -show
#> #>
#Convert-ExcelRangeToImage -Path $Path -workSheetname $workSheetname -range $range -destination "$pwd\temp.png" -show #Convert-ExcelRangeToImage -Path $Path -WorksheetName $worksheetName -range $range -destination "$pwd\temp.png" -show

View File

@@ -7,7 +7,7 @@ function ConvertFrom-ExcelData {
$Path, $Path,
[ScriptBlock]$scriptBlock, [ScriptBlock]$scriptBlock,
[Alias("Sheet")] [Alias("Sheet")]
$WorkSheetname = 1, $WorksheetName = 1,
[int]$HeaderRow = 1, [int]$HeaderRow = 1,
[string[]]$Header, [string[]]$Header,
[switch]$NoHeader, [switch]$NoHeader,

View File

@@ -8,7 +8,7 @@ function ConvertFrom-ExcelToSQLInsert {
[ValidateScript( { Test-Path $_ -PathType Leaf })] [ValidateScript( { Test-Path $_ -PathType Leaf })]
$Path, $Path,
[Alias("Sheet")] [Alias("Sheet")]
$WorkSheetname = 1, $WorksheetName = 1,
[Alias('HeaderRow', 'TopRow')] [Alias('HeaderRow', 'TopRow')]
[ValidateRange(1, 9999)] [ValidateRange(1, 9999)]
[Int]$StartRow, [Int]$StartRow,

View File

@@ -52,7 +52,7 @@
else { else {
$SourceObject = (Resolve-Path $SourceObject).ProviderPath $SourceObject = (Resolve-Path $SourceObject).ProviderPath
try { try {
Write-Verbose "Opening worksheet '$Worksheetname' in Excel workbook '$SourceObject'." Write-Verbose "Opening worksheet '$WorksheetName' in Excel workbook '$SourceObject'."
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $SourceObject, 'Open', 'Read' , 'ReadWrite' $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $SourceObject, 'Open', 'Read' , 'ReadWrite'
$package1 = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream $package1 = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
$sourceWs = $Package1.Workbook.Worksheets[$SourceWorkSheet] $sourceWs = $Package1.Workbook.Worksheets[$SourceWorkSheet]

View File

@@ -132,7 +132,7 @@
$WorksheetName = $ws.Name $WorksheetName = $ws.Name
} }
} }
catch {throw "Could not get worksheet $worksheetname"} catch {throw "Could not get worksheet $WorksheetName"}
try { try {
if ($Append -and $ws.Dimension) { if ($Append -and $ws.Dimension) {
#if there is a title or anything else above the header row, append needs to be combined wih a suitable startrow parameter #if there is a title or anything else above the header row, append needs to be combined wih a suitable startrow parameter
@@ -176,23 +176,23 @@
} }
elseif ($Title) { elseif ($Title) {
#Can only add a title if not appending! #Can only add a title if not appending!
$Row = $StartRow $row = $StartRow
$ws.Cells[$Row, $StartColumn].Value = $Title $ws.Cells[$row, $StartColumn].Value = $Title
$ws.Cells[$Row, $StartColumn].Style.Font.Size = $TitleSize $ws.Cells[$row, $StartColumn].Style.Font.Size = $TitleSize
if ($PSBoundParameters.ContainsKey("TitleBold")) { if ($PSBoundParameters.ContainsKey("TitleBold")) {
#Set title to Bold face font if -TitleBold was specified. #Set title to Bold face font if -TitleBold was specified.
#Otherwise the default will be unbolded. #Otherwise the default will be unbolded.
$ws.Cells[$Row, $StartColumn].Style.Font.Bold = [boolean]$TitleBold $ws.Cells[$row, $StartColumn].Style.Font.Bold = [boolean]$TitleBold
} }
if ($TitleBackgroundColor ) { if ($TitleBackgroundColor ) {
if ($TitleBackgroundColor -is [string]) {$TitleBackgroundColor = [System.Drawing.Color]::$TitleBackgroundColor } if ($TitleBackgroundColor -is [string]) {$TitleBackgroundColor = [System.Drawing.Color]::$TitleBackgroundColor }
$ws.Cells[$Row, $StartColumn].Style.Fill.PatternType = $TitleFillPattern $ws.Cells[$row, $StartColumn].Style.Fill.PatternType = $TitleFillPattern
$ws.Cells[$Row, $StartColumn].Style.Fill.BackgroundColor.SetColor($TitleBackgroundColor) $ws.Cells[$row, $StartColumn].Style.Fill.BackgroundColor.SetColor($TitleBackgroundColor)
} }
$Row ++ ; $startRow ++ $row ++ ; $startRow ++
} }
else { $Row = $StartRow } else { $row = $StartRow }
$ColumnIndex = $StartColumn $ColumnIndex = $StartColumn
$Numberformat = Expand-NumberFormat -NumberFormat $Numberformat $Numberformat = Expand-NumberFormat -NumberFormat $Numberformat
if ((-not $ws.Dimension) -and ($Numberformat -ne $ws.Cells.Style.Numberformat.Format)) { if ((-not $ws.Dimension) -and ($Numberformat -ne $ws.Cells.Style.Numberformat.Format)) {
@@ -278,20 +278,20 @@
foreach ($exclusion in $ExcludeProperty) {$script:Header = $script:Header -notlike $exclusion} foreach ($exclusion in $ExcludeProperty) {$script:Header = $script:Header -notlike $exclusion}
if ($NoHeader) { if ($NoHeader) {
# Don't push the headers to the spreadsheet # Don't push the headers to the spreadsheet
$Row -= 1 $row -= 1
} }
else { else {
$ColumnIndex = $StartColumn $ColumnIndex = $StartColumn
foreach ($Name in $script:Header) { foreach ($Name in $script:Header) {
$ws.Cells[$Row, $ColumnIndex].Value = $Name $ws.Cells[$row, $ColumnIndex].Value = $Name
Write-Verbose "Cell '$Row`:$ColumnIndex' add header '$Name'" Write-Verbose "Cell '$row`:$ColumnIndex' add header '$Name'"
$ColumnIndex += 1 $ColumnIndex += 1
} }
} }
} }
#endregion #endregion
#region Add non header values #region Add non header values
$Row += 1 $row += 1
$ColumnIndex = $StartColumn $ColumnIndex = $StartColumn
<# <#
For each item in the header OR for the Data item if this is a simple Type or data table : For each item in the header OR for the Data item if this is a simple Type or data table :
@@ -305,39 +305,39 @@
else {$v = $TargetData.$Name} else {$v = $TargetData.$Name}
try { try {
if ($v -is [DateTime]) { if ($v -is [DateTime]) {
$ws.Cells[$Row, $ColumnIndex].Value = $v $ws.Cells[$row, $ColumnIndex].Value = $v
$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = 'm/d/yy h:mm' # This is not a custom format, but a preset recognized as date and localized. $ws.Cells[$row, $ColumnIndex].Style.Numberformat.Format = 'm/d/yy h:mm' # This is not a custom format, but a preset recognized as date and localized.
} }
elseif ($v -is [TimeSpan]) { elseif ($v -is [TimeSpan]) {
$ws.Cells[$Row, $ColumnIndex].Value = $v $ws.Cells[$row, $ColumnIndex].Value = $v
$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = '[h]:mm:ss' $ws.Cells[$row, $ColumnIndex].Style.Numberformat.Format = '[h]:mm:ss'
} }
elseif ($v -is [System.ValueType]) { elseif ($v -is [System.ValueType]) {
$ws.Cells[$Row, $ColumnIndex].Value = $v $ws.Cells[$row, $ColumnIndex].Value = $v
if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } if ($setNumformat) {$ws.Cells[$row, $ColumnIndex].Style.Numberformat.Format = $Numberformat }
} }
elseif ($v -is [uri] ) { elseif ($v -is [uri] ) {
$ws.Cells[$Row, $ColumnIndex].HyperLink = $v $ws.Cells[$row, $ColumnIndex].HyperLink = $v
$ws.Cells[$Row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) $ws.Cells[$row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue)
$ws.Cells[$Row, $ColumnIndex].Style.Font.UnderLine = $true $ws.Cells[$row, $ColumnIndex].Style.Font.UnderLine = $true
} }
elseif ($v -isnot [String] ) { #Other objects or null. elseif ($v -isnot [String] ) { #Other objects or null.
if ($null -ne $v) { $ws.Cells[$Row, $ColumnIndex].Value = $v.toString()} if ($null -ne $v) { $ws.Cells[$row, $ColumnIndex].Value = $v.toString()}
} }
elseif ($v[0] -eq '=') { elseif ($v[0] -eq '=') {
$ws.Cells[$Row, $ColumnIndex].Formula = ($v -replace '^=','') $ws.Cells[$row, $ColumnIndex].Formula = ($v -replace '^=','')
if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } if ($setNumformat) {$ws.Cells[$row, $ColumnIndex].Style.Numberformat.Format = $Numberformat }
} }
elseif ( [System.Uri]::IsWellFormedUriString($v , [System.UriKind]::Absolute) ) { elseif ( [System.Uri]::IsWellFormedUriString($v , [System.UriKind]::Absolute) ) {
if ($v -match "^xl://internal/") { if ($v -match "^xl://internal/") {
$referenceAddress = $v -replace "^xl://internal/" , "" $referenceAddress = $v -replace "^xl://internal/" , ""
$display = $referenceAddress -replace "!A1$" , "" $display = $referenceAddress -replace "!A1$" , ""
$h = New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList $referenceAddress , $display $h = New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList $referenceAddress , $display
$ws.Cells[$Row, $ColumnIndex].HyperLink = $h $ws.Cells[$row, $ColumnIndex].HyperLink = $h
} }
else {$ws.Cells[$Row, $ColumnIndex].HyperLink = $v } #$ws.Cells[$Row, $ColumnIndex].Value = $v.AbsoluteUri else {$ws.Cells[$row, $ColumnIndex].HyperLink = $v } #$ws.Cells[$row, $ColumnIndex].Value = $v.AbsoluteUri
$ws.Cells[$Row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) $ws.Cells[$row, $ColumnIndex].Style.Font.Color.SetColor([System.Drawing.Color]::Blue)
$ws.Cells[$Row, $ColumnIndex].Style.Font.UnderLine = $true $ws.Cells[$row, $ColumnIndex].Style.Font.UnderLine = $true
} }
else { else {
$number = $null $number = $null
@@ -346,15 +346,15 @@
$NoNumberConversion -notcontains $Name -and $NoNumberConversion -notcontains $Name -and
[Double]::TryParse($v, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) [Double]::TryParse($v, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number)
) { ) {
$ws.Cells[$Row, $ColumnIndex].Value = $number $ws.Cells[$row, $ColumnIndex].Value = $number
if ($setNumformat) {$ws.Cells[$Row, $ColumnIndex].Style.Numberformat.Format = $Numberformat } if ($setNumformat) {$ws.Cells[$row, $ColumnIndex].Style.Numberformat.Format = $Numberformat }
} }
else { else {
$ws.Cells[$Row, $ColumnIndex].Value = $v $ws.Cells[$row, $ColumnIndex].Value = $v
} }
} }
} }
catch {Write-Warning -Message "Could not insert the '$Name' property at Row $Row, Column $ColumnIndex"} catch {Write-Warning -Message "Could not insert the '$Name' property at Row $row, Column $ColumnIndex"}
$ColumnIndex += 1 $ColumnIndex += 1
} }
$ColumnIndex -= 1 # column index will be the last column whether isDataTypeValueType was true or false $ColumnIndex -= 1 # column index will be the last column whether isDataTypeValueType was true or false
@@ -371,7 +371,7 @@
$endAddress = $ws.Dimension.End.Address $endAddress = $ws.Dimension.End.Address
} }
else { else {
$LastRow = $Row $LastRow = $row
$LastCol = $ColumnIndex $LastCol = $ColumnIndex
$endAddress = [OfficeOpenXml.ExcelAddress]::GetAddress($LastRow , $LastCol) $endAddress = [OfficeOpenXml.ExcelAddress]::GetAddress($LastRow , $LastCol)
} }

View File

@@ -115,7 +115,7 @@
try { try {
#Select worksheet #Select worksheet
if (-not $WorksheetName) { $Worksheet = $ExcelPackage.Workbook.Worksheets[1] } if (-not $WorksheetName) { $Worksheet = $ExcelPackage.Workbook.Worksheets[1] }
elseif (-not ($Worksheet = $ExcelPackage.Workbook.Worksheets[$WorkSheetName])) { elseif (-not ($Worksheet = $ExcelPackage.Workbook.Worksheets[$WorksheetName])) {
throw "Worksheet '$WorksheetName' not found, the workbook only contains the worksheets '$($ExcelPackage.Workbook.Worksheets)'. If you only wish to select the first worksheet, please remove the '-WorksheetName' parameter." ; return throw "Worksheet '$WorksheetName' not found, the workbook only contains the worksheets '$($ExcelPackage.Workbook.Worksheets)'. If you only wish to select the first worksheet, please remove the '-WorksheetName' parameter." ; return
} }
@@ -142,12 +142,12 @@
} }
else { else {
$Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." } $Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." }
if ($NoHeader) { $Rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } } if ($NoHeader) { $rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } }
elseif ($HeaderName) { $Rows = $StartRow..$EndRow } elseif ($HeaderName) { $rows = $StartRow..$EndRow }
else { else {
$Rows = (1 + $StartRow)..$EndRow $rows = (1 + $StartRow)..$EndRow
if ($StartRow -eq 1 -and $EndRow -eq 1) { if ($StartRow -eq 1 -and $EndRow -eq 1) {
$Rows = 0 $rows = 0
} }
} }
@@ -162,7 +162,7 @@
throw "Duplicate column headers found on row '$StartRow' in columns '$($Duplicates.Group.Column)'. Column headers must be unique, if this is not a requirement please use the '-NoHeader' or '-HeaderName' parameter."; return throw "Duplicate column headers found on row '$StartRow' in columns '$($Duplicates.Group.Column)'. Column headers must be unique, if this is not a requirement please use the '-NoHeader' or '-HeaderName' parameter."; return
} }
#endregion #endregion
if (-not $Rows) { if (-not $rows) {
Write-Warning "Worksheet '$WorksheetName' in workbook '$Path' contains no data in the rows after top row '$StartRow'" Write-Warning "Worksheet '$WorksheetName' in workbook '$Path' contains no data in the rows after top row '$StartRow'"
} }
else { else {
@@ -186,7 +186,7 @@
$TextColRegEx = New-Object -TypeName regex -ArgumentList $TextColExpression , 9 $TextColRegEx = New-Object -TypeName regex -ArgumentList $TextColExpression , 9
} }
else {$TextColRegEx = $null} else {$TextColRegEx = $null}
foreach ($R in $Rows) { foreach ($R in $rows) {
#Disabled write-verbose for speed #Disabled write-verbose for speed
# Write-Verbose "Import row '$R'" # Write-Verbose "Import row '$R'"
$NewRow = [Ordered]@{ } $NewRow = [Ordered]@{ }
@@ -213,7 +213,7 @@
#endregion #endregion
} }
} }
catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$Worksheetname': $_"; return } catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$WorksheetName': $_"; return }
finally { finally {
if ($Path) { $stream.close(); $ExcelPackage.Dispose() } if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
} }

View File

@@ -7,7 +7,7 @@
[Parameter(Mandatory = $true, ParameterSetName = "PackageDefault")] [Parameter(Mandatory = $true, ParameterSetName = "PackageDefault")]
[Parameter(Mandatory = $true, ParameterSetName = "PackageTable")] [Parameter(Mandatory = $true, ParameterSetName = "PackageTable")]
[OfficeOpenXml.ExcelPackage]$ExcelPackage, [OfficeOpenXml.ExcelPackage]$ExcelPackage,
$WorkSheetName = 'Combined', $WorksheetName = 'Combined',
[switch]$Clearsheet, [switch]$Clearsheet,
[switch]$NoHeader, [switch]$NoHeader,
[string]$FromLabel = "From" , [string]$FromLabel = "From" ,
@@ -55,10 +55,10 @@
) )
#region get target worksheet, select it and move it to the end. #region get target worksheet, select it and move it to the end.
if ($Path -and -not $ExcelPackage) {$ExcelPackage = Open-ExcelPackage -path $Path } if ($Path -and -not $ExcelPackage) {$ExcelPackage = Open-ExcelPackage -path $Path }
$destinationSheet = Add-Worksheet -ExcelPackage $ExcelPackage -WorkSheetname $WorkSheetName -ClearSheet:$Clearsheet $destinationSheet = Add-Worksheet -ExcelPackage $ExcelPackage -WorkSheetname $WorksheetName -ClearSheet:$Clearsheet
foreach ($w in $ExcelPackage.Workbook.Worksheets) {$w.view.TabSelected = $false} foreach ($w in $ExcelPackage.Workbook.Worksheets) {$w.view.TabSelected = $false}
$destinationSheet.View.TabSelected = $true $destinationSheet.View.TabSelected = $true
$ExcelPackage.Workbook.Worksheets.MoveToEnd($WorkSheetName) $ExcelPackage.Workbook.Worksheets.MoveToEnd($WorksheetName)
#row to insert at will be 1 on a blank sheet and lastrow + 1 on populated one #row to insert at will be 1 on a blank sheet and lastrow + 1 on populated one
$row = (1 + $destinationSheet.Dimension.End.Row ) $row = (1 + $destinationSheet.Dimension.End.Row )
#endregion #endregion
@@ -123,7 +123,7 @@
'Title', 'TitleFillPattern', 'TitleBackgroundColor', 'TitleBold', 'TitleSize' | ForEach-Object {$null = $params.Remove($_)} 'Title', 'TitleFillPattern', 'TitleBackgroundColor', 'TitleBold', 'TitleSize' | ForEach-Object {$null = $params.Remove($_)}
if ($params.Keys.Count) { if ($params.Keys.Count) {
if ($Title) { $params.StartRow = 2} if ($Title) { $params.StartRow = 2}
$params.WorkSheetName = $WorkSheetName $params.WorkSheetName = $WorksheetName
$params.ExcelPackage = $ExcelPackage $params.ExcelPackage = $ExcelPackage
Export-Excel @Params Export-Excel @Params
} }

View File

@@ -84,7 +84,7 @@
#All the 'difference' columns in the sheet are labeled with the file they came from, 'reference' columns need their #All the 'difference' columns in the sheet are labeled with the file they came from, 'reference' columns need their
#headers prefixed with the ref file name, $colnames is the basis of a regular expression to identify what should have $refPrefix appended #headers prefixed with the ref file name, $colnames is the basis of a regular expression to identify what should have $refPrefix appended
$colNames = @("^_Row$") $colNames = @("^_Row$")
if ($key -ne "*") if ($Key -ne "*")
{$colnames += "^$Key$"} {$colnames += "^$Key$"}
if ($filesToProcess.Count -ge 2) { if ($filesToProcess.Count -ge 2) {
$refPrefix = (Split-Path -Path $filestoProcess[0] -Leaf) -replace "\.xlsx$"," " $refPrefix = (Split-Path -Path $filestoProcess[0] -Leaf) -replace "\.xlsx$"," "

View File

@@ -122,8 +122,8 @@
foreach ($p in $Property) { $propList += ($headings.where({$_ -like $p}) )} foreach ($p in $Property) { $propList += ($headings.where({$_ -like $p}) )}
foreach ($p in $ExcludeProperty) { $propList = $propList.where({$_ -notlike $p}) } foreach ($p in $ExcludeProperty) { $propList = $propList.where({$_ -notlike $p}) }
if (($propList -notcontains $Key) -and if (($propList -notcontains $Key) -and
('*' -ne $Key)) { $propList += $Key} #If $key isn't one of the headings we will have bailed by now ('*' -ne $Key)) { $propList += $Key} #If $Key isn't one of the headings we will have bailed by now
$propList = $propList | Select-Object -Unique #so, prolist must contain at least $key if nothing else $propList = $propList | Select-Object -Unique #so, prolist must contain at least $Key if nothing else
#If key is "*" we treat it differently , and we will create a script property which concatenates all the Properties in $Proplist #If key is "*" we treat it differently , and we will create a script property which concatenates all the Properties in $Proplist
$ConCatblock = [scriptblock]::Create( ($proplist | ForEach-Object {'$this."' + $_ + '"'}) -join " + ") $ConCatblock = [scriptblock]::Create( ($proplist | ForEach-Object {'$this."' + $_ + '"'}) -join " + ")
@@ -131,12 +131,12 @@
#Build the list of the properties to output, in order. #Build the list of the properties to output, in order.
$diffpart = @() $diffpart = @()
$refpart = @() $refpart = @()
foreach ($p in $proplist.Where({$key -ne $_}) ) {$refPart += $p ; $diffPart += "$DiffPrefix $p" } foreach ($p in $proplist.Where({$Key -ne $_}) ) {$refPart += $p ; $diffPart += "$DiffPrefix $p" }
$lastRefColNo = $proplist.count $lastRefColNo = $proplist.count
$FirstDiffColNo = $lastRefColNo + 1 $FirstDiffColNo = $lastRefColNo + 1
if ($key -ne '*') { if ($Key -ne '*') {
$outputProps = @($key) + $refpart + $diffpart $outputProps = @($Key) + $refpart + $diffpart
#If we are using a single column as the key, don't duplicate it, so the last difference column will be A if there is one property, C if there are two, E if there are 3 #If we are using a single column as the key, don't duplicate it, so the last difference column will be A if there is one property, C if there are two, E if there are 3
$lastDiffColNo = (2 * $proplist.count) - 1 $lastDiffColNo = (2 * $proplist.count) - 1
} }
@@ -151,7 +151,7 @@
#the row in the other sheet might be different so we will look up the row number from the key field - build a hash table for that here #the row in the other sheet might be different so we will look up the row number from the key field - build a hash table for that here
#If we have "*" as the key ad the script property to concatenate the [selected] properties. #If we have "*" as the key ad the script property to concatenate the [selected] properties.
$Rowhash = @{} $rowHash = @{}
$rowNo = $firstDataRow $rowNo = $firstDataRow
foreach ($row in $ReferenceObject) { foreach ($row in $ReferenceObject) {
if ($null -eq $row._row) {Add-Member -InputObject $row -MemberType NoteProperty -Value ($rowNo ++) -Name "_Row" } if ($null -eq $row._row) {Add-Member -InputObject $row -MemberType NoteProperty -Value ($rowNo ++) -Name "_Row" }
@@ -163,23 +163,23 @@
Add-Member -InputObject $row -MemberType NoteProperty -Value $rowNo -Name "$DiffPrefix Row" -Force Add-Member -InputObject $row -MemberType NoteProperty -Value $rowNo -Name "$DiffPrefix Row" -Force
if ($Key -eq '*' ) { if ($Key -eq '*' ) {
Add-Member -InputObject $row -MemberType ScriptProperty -Value $ConCatblock -Name "_All" Add-Member -InputObject $row -MemberType ScriptProperty -Value $ConCatblock -Name "_All"
$Rowhash[$row._All] = $rowNo $rowHash[$row._All] = $rowNo
} }
else {$Rowhash[$row.$key] = $rowNo } else {$rowHash[$row.$Key] = $rowNo }
$rowNo ++ $rowNo ++
} }
if ($DifferenceObject.count -gt $Rowhash.Keys.Count) { if ($DifferenceObject.count -gt $rowHash.Keys.Count) {
Write-Warning -Message "Difference object has $($DifferenceObject.Count) rows; but only $($Rowhash.keys.count) unique keys" Write-Warning -Message "Difference object has $($DifferenceObject.Count) rows; but only $($rowHash.keys.count) unique keys"
} }
if ($Key -eq '*') {$key = "_ALL"} if ($Key -eq '*') {$Key = "_ALL"}
#endregion #endregion
#We need to know all the properties we've met on the objects we've diffed #We need to know all the properties we've met on the objects we've diffed
$eDiffProps = [ordered]@{} $eDiffProps = [ordered]@{}
#When we do a compare object changes will result in two rows so we group them and join them together. #When we do a compare object changes will result in two rows so we group them and join them together.
$expandedDiff = Compare-Object -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject -Property $propList -PassThru -IncludeEqual | $expandedDiff = Compare-Object -ReferenceObject $ReferenceObject -DifferenceObject $DifferenceObject -Property $propList -PassThru -IncludeEqual |
Group-Object -Property $key | ForEach-Object { Group-Object -Property $Key | ForEach-Object {
#The value of the key column is the name of the Group. #The value of the key column is the name of the Group.
$keyval = $_.name $keyVal = $_.name
#we're going to create a custom object from a hash table. #we're going to create a custom object from a hash table.
$hash = [ordered]@{} $hash = [ordered]@{}
foreach ($result in $_.Group) { foreach ($result in $_.Group) {
@@ -187,7 +187,7 @@
elseif (-not $hash["$DiffPrefix Row"]) {$hash["_Row"] = "" } elseif (-not $hash["$DiffPrefix Row"]) {$hash["_Row"] = "" }
#if we have already set the side, this must be the second record, so set side to indicate "changed"; if we got two "Same" indicators we may have a classh of keys #if we have already set the side, this must be the second record, so set side to indicate "changed"; if we got two "Same" indicators we may have a classh of keys
if ($hash.Side) { if ($hash.Side) {
if ($hash.Side -eq $result.SideIndicator) {Write-Warning -Message "'$keyval' may be a duplicate."} if ($hash.Side -eq $result.SideIndicator) {Write-Warning -Message "'$keyVal' may be a duplicate."}
$hash.Side = "<>" $hash.Side = "<>"
} }
else {$hash["Side"] = $result.SideIndicator} else {$hash["Side"] = $result.SideIndicator}
@@ -204,10 +204,10 @@
'<=' { $hash["$DiffPrefix is"] = 'Removed'} '<=' { $hash["$DiffPrefix is"] = 'Removed'}
} }
#find the number of the row in the the "difference" object which has this key. If it is the object is only in the reference this will be blank. #find the number of the row in the the "difference" object which has this key. If it is the object is only in the reference this will be blank.
$hash["$DiffPrefix Row"] = $Rowhash[$keyval] $hash["$DiffPrefix Row"] = $rowHash[$keyVal]
$hash[$key] = $keyval $hash[$Key] = $keyVal
#Create FieldName and/or =>FieldName columns #Create FieldName and/or =>FieldName columns
foreach ($p in $result.psobject.Properties.name.where({$_ -ne $key -and $_ -ne "SideIndicator" -and $_ -ne "$DiffPrefix Row" })) { foreach ($p in $result.psobject.Properties.name.where({$_ -ne $Key -and $_ -ne "SideIndicator" -and $_ -ne "$DiffPrefix Row" })) {
if ($result.SideIndicator -eq "==" -and $p -in $propList) if ($result.SideIndicator -eq "==" -and $p -in $propList)
{$hash[("$p")] = $hash[("$DiffPrefix $p")] = $result.$P} {$hash[("$p")] = $hash[("$DiffPrefix $p")] = $result.$P}
elseif ($result.SideIndicator -eq "==" -or $result.SideIndicator -eq "<=") elseif ($result.SideIndicator -eq "==" -or $result.SideIndicator -eq "<=")

View File

@@ -8,7 +8,7 @@
[Parameter(ParameterSetName="Package",Mandatory=$true)] [Parameter(ParameterSetName="Package",Mandatory=$true)]
[OfficeOpenXml.ExcelPackage]$ExcelPackage, [OfficeOpenXml.ExcelPackage]$ExcelPackage,
[Parameter(ParameterSetName="Package")] [Parameter(ParameterSetName="Package")]
[String]$Worksheetname = "Sheet1", [String]$WorksheetName = "Sheet1",
[Parameter(ParameterSetName="sheet",Mandatory=$true)] [Parameter(ParameterSetName="sheet",Mandatory=$true)]
[OfficeOpenXml.ExcelWorksheet]$Worksheet, [OfficeOpenXml.ExcelWorksheet]$Worksheet,
[Parameter(ValueFromPipeline=$true)] [Parameter(ValueFromPipeline=$true)]
@@ -52,10 +52,10 @@
begin { begin {
#if we were passed a package object and a worksheet name , get the worksheet. #if we were passed a package object and a worksheet name , get the worksheet.
if ($ExcelPackage) { if ($ExcelPackage) {
if ($ExcelPackage.Workbook.Worksheets.Name -notcontains $Worksheetname) { if ($ExcelPackage.Workbook.Worksheets.Name -notcontains $WorksheetName) {
throw "The Workbook does not contain a sheet named '$Worksheetname'" throw "The Workbook does not contain a sheet named '$WorksheetName'"
} }
else {$Worksheet = $ExcelPackage.Workbook.Worksheets[$Worksheetname] } else {$Worksheet = $ExcelPackage.Workbook.Worksheets[$WorksheetName] }
} }
#In a script block to build a formula, we may want any of corners or the column name, #In a script block to build a formula, we may want any of corners or the column name,
@@ -66,7 +66,7 @@
$endRow = $Worksheet.Dimension.End.Row $endRow = $Worksheet.Dimension.End.Row
} }
process { process {
if ($null -eq $workSheet.Dimension) {Write-Warning "Can't format an empty worksheet."; return} if ($null -eq $Worksheet.Dimension) {Write-Warning "Can't format an empty worksheet."; return}
if ($Column -eq 0 ) {$Column = $endColumn + 1 } if ($Column -eq 0 ) {$Column = $endColumn + 1 }
$columnName = (New-Object 'OfficeOpenXml.ExcelCellAddress' @(1, $column)).Address -replace "1","" $columnName = (New-Object 'OfficeOpenXml.ExcelCellAddress' @(1, $column)).Address -replace "1",""
Write-Verbose -Message "Updating Column $columnName" Write-Verbose -Message "Updating Column $columnName"
@@ -120,7 +120,7 @@
Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params
} }
#endregion #endregion
if ($PSBoundParameters.ContainsKey('Hide')) {$workSheet.Column($Column).Hidden = [bool]$Hide} if ($PSBoundParameters.ContainsKey('Hide')) {$Worksheet.Column($Column).Hidden = [bool]$Hide}
#return the new data if -passthru was specified. #return the new data if -passthru was specified.
if ($PassThru) { $Worksheet.Column($Column)} if ($PassThru) { $Worksheet.Column($Column)}
elseif ($ReturnRange) { $theRange} elseif ($ReturnRange) { $theRange}

View File

@@ -8,7 +8,7 @@
[Parameter(ParameterSetName="Package",Mandatory=$true)] [Parameter(ParameterSetName="Package",Mandatory=$true)]
[OfficeOpenXml.ExcelPackage]$ExcelPackage, [OfficeOpenXml.ExcelPackage]$ExcelPackage,
[Parameter(ParameterSetName="Package")] [Parameter(ParameterSetName="Package")]
$Worksheetname = "Sheet1", $WorksheetName = "Sheet1",
[Parameter(ParameterSetName="Sheet",Mandatory=$true)] [Parameter(ParameterSetName="Sheet",Mandatory=$true)]
[OfficeOpenXml.Excelworksheet] $Worksheet, [OfficeOpenXml.Excelworksheet] $Worksheet,
[Parameter(ValueFromPipeline = $true)] [Parameter(ValueFromPipeline = $true)]
@@ -53,10 +53,10 @@
begin { begin {
#if we were passed a package object and a worksheet name , get the worksheet. #if we were passed a package object and a worksheet name , get the worksheet.
if ($ExcelPackage) { if ($ExcelPackage) {
if ($ExcelPackage.Workbook.Worksheets.Name -notcontains $Worksheetname) { if ($ExcelPackage.Workbook.Worksheets.Name -notcontains $WorksheetName) {
throw "The Workbook does not contain a sheet named '$Worksheetname'" throw "The Workbook does not contain a sheet named '$WorksheetName'"
} }
else {$Worksheet = $ExcelPackage.Workbook.Worksheets[$Worksheetname] } else {$Worksheet = $ExcelPackage.Workbook.Worksheets[$WorksheetName] }
} }
#In a script block to build a formula, we may want any of corners or the columnname, #In a script block to build a formula, we may want any of corners or the columnname,
#if row and start column aren't specified assume first unused row, and first column #if row and start column aren't specified assume first unused row, and first column
@@ -66,7 +66,7 @@
$endRow = $Worksheet.Dimension.End.Row $endRow = $Worksheet.Dimension.End.Row
} }
process { process {
if ($null -eq $workSheet.Dimension) {Write-Warning "Can't format an empty worksheet."; return} if ($null -eq $Worksheet.Dimension) {Write-Warning "Can't format an empty worksheet."; return}
if ($Row -eq 0 ) {$Row = $endRow + 1 } if ($Row -eq 0 ) {$Row = $endRow + 1 }
Write-Verbose -Message "Updating Row $Row" Write-Verbose -Message "Updating Row $Row"
#Add a row label #Add a row label
@@ -117,7 +117,7 @@
Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params
} }
#endregion #endregion
if ($PSBoundParameters.ContainsKey('Hide')) {$workSheet.Row($Row).Hidden = [bool]$Hide} if ($PSBoundParameters.ContainsKey('Hide')) {$Worksheet.Row($Row).Hidden = [bool]$Hide}
#return the new data if -passthru was specified. #return the new data if -passthru was specified.
if ($passThru) {$Worksheet.Row($Row)} if ($passThru) {$Worksheet.Row($Row)}
elseif ($ReturnRange) {$theRange} elseif ($ReturnRange) {$theRange}