fixes to casing, and some basic functions changed to advanced

This commit is contained in:
jhoneill
2019-11-25 23:40:51 +00:00
parent feb493e397
commit 5e87c3f6a7
43 changed files with 118 additions and 133 deletions

View File

@@ -6,7 +6,7 @@
} }
function ListFonts { function ListFonts {
[cmdletbinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", "")]
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
if (-not $script:FontFamilies) { if (-not $script:FontFamilies) {
@@ -77,7 +77,7 @@ function WorksheetArgumentCompleter {
} }
} }
If (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { if (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) {
Register-ArgumentCompleter -CommandName Export-Excel -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Export-Excel -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion
Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion
Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName DataBarColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName DataBarColor -ScriptBlock $Function:ColorCompletion

View File

@@ -1,15 +1,14 @@
 
Function Test-SingleFunction { function Test-SingleFunction {
param ( param (
[parameter(ValueFromPipeline=$true)] [parameter(ValueFromPipeline=$true)]
$path ) $path )
begin { begin {
Push-Location "C:\Users\mcp\Documents\GitHub\ImportExcel" $psd = Get-Content -Raw "$PSScriptRoot\..\ImportExcel.psd1"
$exportedFunctions = (Import-LocalizedData -FileName "ImportExcel.psd1").functionsToExport $exportedFunctions = (Invoke-Command ([scriptblock]::Create($psd))).functionsToExport
Pop-Location
$reg = [Regex]::new(@" $reg = [Regex]::new(@"
function\s*[-\w]+\s*{ # The function name and opening '{' function\s*[-\w]+\s*{ # The function name and opening '{'
(?: (?:
[^{}]+ # Match all non-braces [^{}]+ # Match all non-braces
| |
(?<open> { ) # Match '{', and capture into 'open' (?<open> { ) # Match '{', and capture into 'open'
@@ -18,27 +17,38 @@ Function Test-SingleFunction {
)* )*
(?(open)(?!)) # Fails if 'open' stack isn't empty (?(open)(?!)) # Fails if 'open' stack isn't empty
} # Functions closing '}' } # Functions closing '}'
"@, 33) # 33 = ignore case and white space. "@, 57) # 41 = compile ignore case and white space.
$reg2 = [Regex]::new(@"
^function\s*[-\w]+\s*{ # The function name and opening '{'
}# (
\#.*?[\r\n]+ # single line comment
| # or
\s*<\#.*?\#> # <#comment block#>
| # or
\s*\[.*?\] # [attribute tags]
)*
"@, 57)
# 43 = compile, multi-line, ignore case and white space.
}
process { process {
$item = Get-item $Path $item = Get-item $Path
$name = $item.Name -replace "\.\w+$","" $name = $item.Name -replace "\.\w+$",""
Write-Verbose $name Write-Verbose $name
$file = Get-Content $item -Raw $file = Get-Content $item -Raw
$m = $reg.Matches($file) $m = $reg.Matches($file)
#based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis
#based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis
if ($m.Count -eq 0) {return "Could not find $name function in $($item.name)"} if ($m.Count -eq 0) {return "Could not find $name function in $($item.name)"}
elseif ($m.Count -ge 2) {return "Multiple functions in $($item.name)"} elseif ($m.Count -ge 2) {return "Multiple functions in $($item.name)"}
elseif ($exportedFunctions -cnotcontains $name) {return "$name not exported (or in the wrong case)"} elseif ($exportedFunctions -cnotcontains $name) {return "$name not exported (or in the wrong case)"}
elseif ($m[0] -cnotmatch "^\w+\s+$name") {return "function $name in wrong case"} elseif ($m[0] -cnotmatch "^\w+\s+$name") {return "function $name in wrong case"}
elseif ($m[0] -inotmatch "^function\s*$name\s*{(\s*<\#.*?\#>|\s*\[.*?\])*\s*param") {return "No param block in $name"} $m2 = [regex]::Match($m[0],"param",[System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
elseif ($m[0] -inotmatch "\[cmdletbinding\(" -and if (-not $m2.Success) {return "No param block in $name"}
# elseif ($m[0] -inotmatch "(?s)^function\s*$name\s*{(\s*<\#.*?\#>|\s*\[.*?\])*\s*param")
# elseif ($reg2.IsMatch($m[0].Value)) {return "function $name has comment-based help"}
elseif ($m[0] -inotmatch "\[CmdletBinding\(" -and
$m[0] -inotmatch "\[parameter\(" ) {return "$name has is not an advanced function"} $m[0] -inotmatch "\[parameter\(" ) {return "$name has is not an advanced function"}
elseif (-not (& $Name -?).synopsis) {return "$name has no help"} elseif (-not (& $Name -?).synopsis) {return "$name has no help"}
else {return "$name OK"} else {Write-Verbose "$name OK"}
} }
} }

View File

@@ -10,7 +10,7 @@
Preset2 will set AutoFilter and add the Title "Daily Report". Preset2 will set AutoFilter and add the Title "Daily Report".
(see comments and code below). (see comments and code below).
#> #>
Function Out-Excel { function Out-Excel {
[CmdletBinding(DefaultParameterSetName = 'Default')] [CmdletBinding(DefaultParameterSetName = 'Default')]
param( param(
[switch] [switch]

View File

@@ -1,5 +1,5 @@
#requires -modules "Get-IndexedItem" #requires -modules "Get-IndexedItem"
[cmdletbinding()] [CmdletBinding()]
Param() Param()
Remove-Item ~\documents\music.xlsx -ErrorAction SilentlyContinue Remove-Item ~\documents\music.xlsx -ErrorAction SilentlyContinue
[System.Diagnostics.Stopwatch]$stopwatch = [System.Diagnostics.Stopwatch]::StartNew() [System.Diagnostics.Stopwatch]$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

View File

@@ -10,7 +10,7 @@
Exports the charts to PNG files in MyDocuments , and returns file objects representing the newly created files Exports the charts to PNG files in MyDocuments , and returns file objects representing the newly created files
#> #>
Param ( param(
#Path to the Excel file whose chars we will export. #Path to the Excel file whose chars we will export.
$Path = "C:\Users\public\Documents\stats.xlsx", $Path = "C:\Users\public\Documents\stats.xlsx",
#If specified, output file objects representing the image files #If specified, output file objects representing the image files

View File

@@ -1,5 +1,5 @@
Function Add-ConditionalFormatting { function Add-ConditionalFormatting {
Param ( param (
[Parameter(Mandatory = $true, Position = 0)] [Parameter(Mandatory = $true, Position = 0)]
[Alias("Range")] [Alias("Range")]
$Address , $Address ,
@@ -50,7 +50,7 @@
) )
#Allow conditional formatting to work like Set-ExcelRange (with single ADDRESS parameter), split it to get worksheet and range of cells. #Allow conditional formatting to work like Set-ExcelRange (with single ADDRESS parameter), split it to get worksheet and range of cells.
If ($Address -is [OfficeOpenXml.Table.ExcelTable]) { if ($Address -is [OfficeOpenXml.Table.ExcelTable]) {
$Worksheet = $Address.Address.Worksheet $Worksheet = $Address.Address.Worksheet
$Address = $Address.Address.Address $Address = $Address.Address.Address
} }

View File

@@ -1,6 +1,6 @@
function Add-ExcelChart { function Add-ExcelChart {
[cmdletbinding(DefaultParameterSetName = 'Worksheet')] [CmdletBinding(DefaultParameterSetName = 'Worksheet')]
[OutputType([OfficeOpenXml.Drawing.Chart.ExcelChart])] [OutputType([OfficeOpenXml.Drawing.Chart.ExcelChart])]
param( param(
[Parameter(ParameterSetName = 'Worksheet', Mandatory = $true)] [Parameter(ParameterSetName = 'Worksheet', Mandatory = $true)]

View File

@@ -1,6 +1,6 @@
Function Add-ExcelDataValidationRule { function Add-ExcelDataValidationRule {
[CmdletBinding()] [CmdletBinding()]
Param( param(
[Parameter(ValueFromPipeline = $true,Position=0)] [Parameter(ValueFromPipeline = $true,Position=0)]
[Alias("Address")] [Alias("Address")]
$Range , $Range ,

View File

@@ -1,5 +1,5 @@
function Add-PivotTable { function Add-PivotTable {
[cmdletbinding(defaultParameterSetName = 'ChartbyParams')] [CmdletBinding(defaultParameterSetName = 'ChartbyParams')]
[OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])] [OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])]
param ( param (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]

View File

@@ -1,8 +1,7 @@
function Close-ExcelPackage {
Function Close-ExcelPackage {
[CmdLetBinding()] [CmdLetBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")]
Param ( param (
[parameter(Mandatory=$true, ValueFromPipeline=$true)] [parameter(Mandatory=$true, ValueFromPipeline=$true)]
[OfficeOpenXml.ExcelPackage]$ExcelPackage, [OfficeOpenXml.ExcelPackage]$ExcelPackage,
[switch]$Show, [switch]$Show,
@@ -16,7 +15,7 @@ Function Close-ExcelPackage {
else { else {
if ($Calculate) { if ($Calculate) {
try { [OfficeOpenXml.CalculationExtension]::Calculate($ExcelPackage.Workbook) } try { [OfficeOpenXml.CalculationExtension]::Calculate($ExcelPackage.Workbook) }
Catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."} catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."}
} }
if ($SaveAs) { if ($SaveAs) {
$SaveAs = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SaveAs) $SaveAs = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SaveAs)

View File

@@ -1,8 +1,8 @@
Function Compare-Worksheet { function Compare-Worksheet {
[cmdletbinding(DefaultParameterSetName)] [CmdletBinding(DefaultParameterSetName)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification="Write host used for sub-warning level message to operator which does not form output")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification="Write host used for sub-warning level message to operator which does not form output")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")]
Param( param(
[parameter(Mandatory=$true,Position=0)] [parameter(Mandatory=$true,Position=0)]
$Referencefile , $Referencefile ,
[parameter(Mandatory=$true,Position=1)] [parameter(Mandatory=$true,Position=1)]
@@ -29,7 +29,7 @@
#if the filenames don't resolve, give up now. #if the filenames don't resolve, give up now.
try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)} try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)}
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] ) ) {
@@ -46,7 +46,7 @@
$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 }
#Get Column headings and create a hash table of Name to column letter. #Get Column headings and create a hash table of Name to column letter.
$headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using Get-member would sort them alphabetically! $headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using Get-member would sort them alphabetically!

View File

@@ -1,6 +1,6 @@
Function Convert-ExcelRangeToImage { function Convert-ExcelRangeToImage {
[alias("Convert-XlRangeToImage")] [alias("Convert-XlRangeToImage")]
Param ( param (
[parameter(Mandatory=$true)] [parameter(Mandatory=$true)]
$Path, $Path,
$workSheetname = "Sheet1" , $workSheetname = "Sheet1" ,

View File

@@ -1,13 +1,13 @@
Function ConvertTo-ExcelXlsx { function ConvertTo-ExcelXlsx {
[CmdletBinding()] [CmdletBinding()]
Param param
( (
[parameter(Mandatory = $true, ValueFromPipeline)] [parameter(Mandatory = $true, ValueFromPipeline)]
[string]$Path, [string]$Path,
[parameter(Mandatory = $false)] [parameter(Mandatory = $false)]
[switch]$Force [switch]$Force
) )
Process { process {
if (-Not ($Path | Test-Path) ) { if (-Not ($Path | Test-Path) ) {
throw "File not found" throw "File not found"
} }

View File

@@ -1,34 +1,5 @@
 function Expand-NumberFormat {
function Expand-NumberFormat { [CmdletBinding()]
<#
.SYNOPSIS
Converts short names for number formats to the formatting strings used in Excel
.DESCRIPTION
Where you can type a number format you can write, for example, 'Short-Date'
and the module will translate it into the format string used by Excel.
Some formats, like Short-Date change how they are presented when Excel
loads (so date will use the local ordering of year, month and Day). Other
formats change how they appear when loaded with different cultures
(depending on the country "," or "." or " " may be the thousand seperator
although Excel always stores it as ",")
.EXAMPLE
Expand-NumberFormat percentage
Returns "0.00%"
.EXAMPLE
Expand-NumberFormat Currency
Returns the currency format specified in the local regional settings. This
may not be the same as Excel uses. The regional settings set the currency
symbol and then whether it is before or after the number and separated with
a space or not; for negative numbers the number may be wrapped in parentheses
or a - sign might appear before or after the number and symbol.
So this returns $#,##0.00;($#,##0.00) for English US, #,##0.00 €;€#,##0.00-
for French. (Note some Eurozone countries write €1,23 and others 1,23€ )
In French the decimal point will be rendered as a "," and the thousand
separator as a space.
#>
[cmdletbinding()]
[OutputType([String])] [OutputType([String])]
param ( param (
#the format string to Expand #the format string to Expand

View File

@@ -403,7 +403,7 @@
Write-Warning -Message "AutoNameRange: Property name '$targetRangeName' is also a valid Excel address and may cause issues. Consider renaming the property." Write-Warning -Message "AutoNameRange: Property name '$targetRangeName' is also a valid Excel address and may cause issues. Consider renaming the property."
} }
} }
Catch { catch {
Write-Warning -Message "AutoNameRange: Testing '$targetRangeName' caused an error. This should be harmless, but a change of property name may be needed.." Write-Warning -Message "AutoNameRange: Testing '$targetRangeName' caused an error. This should be harmless, but a change of property name may be needed.."
} }
} }

View File

@@ -1,5 +1,4 @@
function Export-ExcelSheet { function Export-ExcelSheet {
[CmdletBinding()] [CmdletBinding()]
param param
( (

View File

@@ -1,7 +1,6 @@
function Export-MultipleExcelSheets { function Export-MultipleExcelSheets {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="No suitable singular")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="No suitable singular")]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
$Path, $Path,

View File

@@ -1,4 +1,4 @@
Function Get-ExcelSheetInfo { function Get-ExcelSheetInfo {
[CmdletBinding()] [CmdletBinding()]
param( param(
[Alias('FullName')] [Alias('FullName')]

View File

@@ -1,13 +1,13 @@
Function Get-ExcelWorkbookInfo { function Get-ExcelWorkbookInfo {
[CmdletBinding()] [CmdletBinding()]
Param ( param (
[Alias('FullName')] [Alias('FullName')]
[Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)]
[String]$Path [String]$Path
) )
Process { process {
Try { try {
$Path = (Resolve-Path $Path).ProviderPath $Path = (Resolve-Path $Path).ProviderPath
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite' $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite'
@@ -20,7 +20,7 @@
$xl.Dispose() $xl.Dispose()
$xl = $null $xl = $null
} }
Catch { catch {
throw "Failed retrieving Excel workbook information for '$Path': $_" throw "Failed retrieving Excel workbook information for '$Path': $_"
} }
} }

View File

@@ -1,3 +1,5 @@
function Get-Range ($start=0,$stop,$step=1) { function Get-Range {
[CmdletBinding()]
param($start=0,$stop,$step=1)
for ($idx = $start; $idx -lt $stop; $idx+=$step) {$idx} for ($idx = $start; $idx -lt $stop; $idx+=$step) {$idx}
} }

View File

@@ -1,4 +1,5 @@
function Get-XYRange { function Get-XYRange {
[CmdletBinding()]
param($targetData) param($targetData)
$record = $targetData | Select-Object -First 1 $record = $targetData | Select-Object -First 1

View File

@@ -47,20 +47,20 @@
else { else {
$Paths = '' $Paths = ''
} }
Function Get-PropertyNames { function Get-PropertyNames {
<# <#
.SYNOPSIS .SYNOPSIS
Create objects containing the column number and the column name for each of the different header types. Create objects containing the column number and the column name for each of the different header types.
#> #>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")]
Param ( param(
[Parameter(Mandatory)] [Parameter(Mandatory)]
[Int[]]$Columns, [Int[]]$Columns,
[Parameter(Mandatory)] [Parameter(Mandatory)]
[Int]$StartRow [Int]$StartRow
) )
Try { try {
if ($HeaderName) { if ($HeaderName) {
$i = 0 $i = 0
foreach ($H in $HeaderName) { foreach ($H in $HeaderName) {
@@ -86,7 +86,7 @@
} }
} }
} }
Catch { catch {
throw "Failed creating property names: $_" ; return throw "Failed creating property names: $_" ; return
} }
} }

View File

@@ -1,4 +1,5 @@
function Import-UPS { function Import-UPS {
[CmdletBinding()]
param( param(
$TrackingNumber, $TrackingNumber,
[Switch]$UseDefaultCredentials [Switch]$UseDefaultCredentials

View File

@@ -1,5 +1,5 @@
function Import-USPS { function Import-USPS {
[CmdletBinding()]
param( param(
$TrackingNumber, $TrackingNumber,
[Switch]$UseDefaultCredentials [Switch]$UseDefaultCredentials

View File

@@ -1,4 +1,5 @@
function Invoke-Sum { function Invoke-Sum {
[CmdletBinding()]
param( param(
$data, $data,
$dimension, $dimension,

View File

@@ -1,5 +1,5 @@
function Merge-MultipleSheets { function Merge-MultipleSheets {
[cmdletbinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")]
#[Alias("Merge-MulipleSheets")] #There was a spelling error in the first release. This was there to ensure things didn't break but intelisense gave the alias first. #[Alias("Merge-MulipleSheets")] #There was a spelling error in the first release. This was there to ensure things didn't break but intelisense gave the alias first.

View File

@@ -1,6 +1,6 @@
function Merge-Worksheet { function Merge-Worksheet {
[cmdletbinding(SupportsShouldProcess=$true)] [CmdletBinding(SupportsShouldProcess=$true)]
Param( param(
[parameter(ParameterSetName='A',Mandatory=$true,Position=0)] #A = Compare two files default headers [parameter(ParameterSetName='A',Mandatory=$true,Position=0)] #A = Compare two files default headers
[parameter(ParameterSetName='B',Mandatory=$true,Position=0)] #B = Compare two files user supplied headers [parameter(ParameterSetName='B',Mandatory=$true,Position=0)] #B = Compare two files user supplied headers
[parameter(ParameterSetName='C',Mandatory=$true,Position=0)] #C = Compare two files headers P1, P2, P3 etc [parameter(ParameterSetName='C',Mandatory=$true,Position=0)] #C = Compare two files headers P1, P2, P3 etc
@@ -76,7 +76,7 @@
if ($Referencefile -and $Differencefile) { if ($Referencefile -and $Differencefile) {
#if the filenames don't resolve, give up now. #if the filenames don't resolve, give up now.
try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)} try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)}
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 $WorksheetName can be a single string or two strings. #If we have one file , we must have two different Worksheet names. If we have two files $WorksheetName can be 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] ) ) {
@@ -94,7 +94,7 @@
$ReferenceObject = Import-Excel -Path $Referencefile -WorksheetName $Worksheet1 @params $ReferenceObject = Import-Excel -Path $Referencefile -WorksheetName $Worksheet1 @params
$DifferenceObject = Import-Excel -Path $Differencefile -WorksheetName $Worksheet2 @Params $DifferenceObject = Import-Excel -Path $Differencefile -WorksheetName $Worksheet2 @Params
} }
Catch {Write-Warning -Message "Could not read the Worksheet from $Referencefile::$Worksheet1 and/or $Differencefile::$Worksheet2." ; return } catch {Write-Warning -Message "Could not read the Worksheet from $Referencefile::$Worksheet1 and/or $Differencefile::$Worksheet2." ; return }
if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1} if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1}
} }
elseif ( $Differencefile) { elseif ( $Differencefile) {
@@ -102,7 +102,7 @@
$params = @{WorksheetName=$WorksheetName; Path=$Differencefile; ErrorAction=[System.Management.Automation.ActionPreference]::Stop } $params = @{WorksheetName=$WorksheetName; Path=$Differencefile; 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 {$DifferenceObject = Import-Excel @Params } try {$DifferenceObject = Import-Excel @Params }
Catch {Write-Warning -Message "Could not read the Worksheet '$WorksheetName' from $Differencefile::$WorksheetName." ; return } catch {Write-Warning -Message "Could not read the Worksheet '$WorksheetName' from $Differencefile::$WorksheetName." ; return }
if ($DiffPrefix -eq "=>" ) { if ($DiffPrefix -eq "=>" ) {
$DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$","" $DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$",""
} }

View File

@@ -1,5 +1,5 @@
function New-ConditionalText { function New-ConditionalText {
[cmdletbinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')]
param( param(
#[Parameter(Mandatory=$true)] #[Parameter(Mandatory=$true)]

View File

@@ -1,6 +1,6 @@
function New-ExcelChartDefinition { function New-ExcelChartDefinition {
[Alias("New-ExcelChart")] #This was the former name. The new name reflects that we are defining a chart, not making one in the workbook. [Alias("New-ExcelChart")] #This was the former name. The new name reflects that we are defining a chart, not making one in the workbook.
[cmdletbinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')]
param( param(
$Title = "Chart Title", $Title = "Chart Title",

View File

@@ -1,5 +1,5 @@
function New-ExcelStyle { function New-ExcelStyle {
[cmdletbinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')]
param ( param (
[Alias("Address")] [Alias("Address")]

View File

@@ -1,7 +1,7 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='New*', Justification='Does not change system State')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='New*', Justification='Does not change system State')]
param() param()
function New-PSItem { function New-PSItem {
param()
$totalArgs = $args.Count $totalArgs = $args.Count
if($args[-1] -is [array]) { if($args[-1] -is [array]) {

View File

@@ -1,8 +1,8 @@
Function Open-ExcelPackage { function Open-ExcelPackage {
[CmdLetBinding()] [CmdLetBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")]
[OutputType([OfficeOpenXml.ExcelPackage])] [OutputType([OfficeOpenXml.ExcelPackage])]
Param ( param(
#The path to the file to open. #The path to the file to open.
[Parameter(Mandatory=$true)]$Path, [Parameter(Mandatory=$true)]$Path,
#If specified, any running instances of Excel will be terminated before opening the file. #If specified, any running instances of Excel will be terminated before opening the file.

View File

@@ -1,5 +1,5 @@
Function Remove-Worksheet { function Remove-Worksheet {
[cmdletbinding(SupportsShouldProcess=$true)] [CmdletBinding(SupportsShouldProcess=$true)]
param( param(
# [Parameter(ValueFromPipelineByPropertyName)] # [Parameter(ValueFromPipelineByPropertyName)]
[Parameter(ValueFromPipelineByPropertyName)] [Parameter(ValueFromPipelineByPropertyName)]

View File

@@ -1,4 +1,4 @@
Function Send-SQLDataToExcel { function Send-SQLDataToExcel {
[CmdletBinding(DefaultParameterSetName="none")] [CmdletBinding(DefaultParameterSetName="none")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification="Allowed to use DBSessions Global variable from GETSQL Module")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification="Allowed to use DBSessions Global variable from GETSQL Module")]

View File

@@ -2,6 +2,7 @@
param() param()
function Set-CellStyle { function Set-CellStyle {
[CmdletBinding()]
param( param(
$Worksheet, $Worksheet,
$Row, $Row,

View File

@@ -1,10 +1,10 @@
Function Set-ExcelColumn { function Set-ExcelColumn {
[cmdletbinding()] [CmdletBinding()]
[Alias("Set-Column")] [Alias("Set-Column")]
[OutputType([OfficeOpenXml.ExcelColumn],[String])] [OutputType([OfficeOpenXml.ExcelColumn],[String])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '',Justification='Does not change system state')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")]
Param ( param(
[Parameter(ParameterSetName="Package",Mandatory=$true)] [Parameter(ParameterSetName="Package",Mandatory=$true)]
[OfficeOpenXml.ExcelPackage]$ExcelPackage, [OfficeOpenXml.ExcelPackage]$ExcelPackage,
[Parameter(ParameterSetName="Package")] [Parameter(ParameterSetName="Package")]

View File

@@ -1,8 +1,8 @@
function Set-ExcelRange { function Set-ExcelRange {
[cmdletbinding()] [CmdletBinding()]
[Alias("Set-Format")] [Alias("Set-Format")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')]
Param ( param(
[Parameter(ValueFromPipeline = $true,Position=0)] [Parameter(ValueFromPipeline = $true,Position=0)]
[Alias("Address")] [Alias("Address")]
$Range , $Range ,

View File

@@ -1,10 +1,10 @@
Function Set-ExcelRow { function Set-ExcelRow {
[cmdletbinding()] [CmdletBinding()]
[Alias("Set-Row")] [Alias("Set-Row")]
[OutputType([OfficeOpenXml.ExcelRow],[String])] [OutputType([OfficeOpenXml.ExcelRow],[String])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '',Justification='Does not change system state')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")]
Param ( param(
[Parameter(ParameterSetName="Package",Mandatory=$true)] [Parameter(ParameterSetName="Package",Mandatory=$true)]
[OfficeOpenXml.ExcelPackage]$ExcelPackage, [OfficeOpenXml.ExcelPackage]$ExcelPackage,
[Parameter(ParameterSetName="Package")] [Parameter(ParameterSetName="Package")]

View File

@@ -1,6 +1,6 @@
Function Set-WorksheetProtection { function Set-WorksheetProtection {
[Cmdletbinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '',Justification='Does not change system state')]
param ( param (
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[OfficeOpenXml.ExcelWorksheet]$Worksheet , [OfficeOpenXml.ExcelWorksheet]$Worksheet ,

View File

@@ -3,9 +3,10 @@
param() param()
Function Update-FirstObjectProperties { function Update-FirstObjectProperties {
[CmdletBinding()]
Try { param()
try {
$Union = @() $Union = @()
$Input | ForEach-Object { $Input | ForEach-Object {
If ($Union.Count) { If ($Union.Count) {
@@ -17,7 +18,7 @@ Function Update-FirstObjectProperties {
} }
$Union $Union
} }
Catch { catch {
throw "Failed updating the properties of the first object: $_" throw "Failed updating the properties of the first object: $_"
} }
} }

View File

@@ -1,5 +1,5 @@
Function Get-ExcelTableName { function Get-ExcelTableName {
Param ( param(
$Path, $Path,
$WorksheetName $WorksheetName
) )
@@ -28,8 +28,8 @@ Function Get-ExcelTableName {
$Excel = $null $Excel = $null
} }
Function Get-ExcelTable { function Get-ExcelTable {
Param ( param(
$Path, $Path,
$TableName, $TableName,
$WorksheetName $WorksheetName

View File

@@ -11,9 +11,9 @@ foreach ($directory in @('ExportedCommands','Charting','InferData','Pivot')) {
if ($PSVersionTable.PSVersion.Major -ge 5) { if ($PSVersionTable.PSVersion.Major -ge 5) {
. $PSScriptRoot\Plot.ps1 . $PSScriptRoot\Plot.ps1
Function New-Plot { function New-Plot {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'New-Plot does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '', Justification = 'New-Plot does not change system state')]
Param() param()
[PSPlot]::new() [PSPlot]::new()
} }

View File

@@ -4,7 +4,7 @@
File must not have BOM for GitHub deploy to work. File must not have BOM for GitHub deploy to work.
#> #>
[CmdletBinding(DefaultParameterSetName = 'Default')] [CmdletBinding(DefaultParameterSetName = 'Default')]
Param ( param(
# Path to install the module to, if not provided -Scope used. # Path to install the module to, if not provided -Scope used.
[Parameter(Mandatory, ParameterSetName = 'ModulePath')] [Parameter(Mandatory, ParameterSetName = 'ModulePath')]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
@@ -106,7 +106,7 @@ function Invoke-MultiLike {
} }
} }
Try { try {
Write-Verbose -Message 'Module installation started' Write-Verbose -Message 'Module installation started'
if (!$ModulePath) { if (!$ModulePath) {
@@ -202,7 +202,7 @@ Try {
Import-Module -Name $ModuleName -Force Import-Module -Name $ModuleName -Force
Write-Verbose -Message "Module installed" Write-Verbose -Message "Module installed"
} }
Catch { catch {
throw ('Failed installing module "{0}". Error: "{1}" in Line {2}' -f $ModuleName, $_, $_.InvocationInfo.ScriptLineNumber) throw ('Failed installing module "{0}". Error: "{1}" in Line {2}' -f $ModuleName, $_, $_.InvocationInfo.ScriptLineNumber)
} }
finally { finally {