diff --git a/AddConditionalFormatting.ps1 b/AddConditionalFormatting.ps1 index 05a04d4..de6402f 100644 --- a/AddConditionalFormatting.ps1 +++ b/AddConditionalFormatting.ps1 @@ -209,7 +209,7 @@ #region set the rule conditions #for lessThan/GreaterThan/Equal/Between conditions make sure that strings are wrapped in quotes. Formulas should be passed with = which will be stripped. if ($RuleType -match "Than|Equal|Between" ) { - if ($ConditionValue) { + if ($PSBoundParameters.ContainsKey("ConditionValue" )) { $number = $Null #if the condition type is not a value type, but parses as a number, make it the number if ($ConditionValue -isnot [System.ValueType] -and [Double]::TryParse($ConditionValue, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) ) { @@ -219,7 +219,7 @@ $ConditionValue = '"' + $ConditionValue +'"' } } - if ($ConditionValue2) { + if ($PSBoundParameters.ContainsKey("$ConditionValue2")) { $number = $Null if ($ConditionValue -isnot [System.ValueType] -and [Double]::TryParse($ConditionValue2, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) ) { $ConditionValue2 = $number diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 84acdf9..58bde31 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -412,7 +412,7 @@ Runs a query against a SQL Server database and outputs the resulting rows DataRows using the -OutputAs parameter. The results are then piped to the Export-Excel function. NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet. - + .LINK https://github.com/dfinke/ImportExcel #> @@ -681,10 +681,10 @@ $ws.Cells[$Row, $StartColumn].Value = $Title $ws.Cells[$Row, $StartColumn].Style.Font.Size = $TitleSize - if ($TitleBold) { + if ($PSBoundParameters.ContainsKey("TitleBold")) { #Set title to Bold face font if -TitleBold was specified. #Otherwise the default will be unbolded. - $ws.Cells[$Row, $StartColumn].Style.Font.Bold = $True + $ws.Cells[$Row, $StartColumn].Style.Font.Bold = [boolean]$TitleBold } if ($TitleBackgroundColor ) { if ($TitleBackgroundColor -is [string]) {$TitleBackgroundColor = [System.Drawing.Color]::$TitleBackgroundColor } @@ -820,6 +820,7 @@ } catch {Write-Warning -Message "Failed adding named ranges to worksheet '$WorksheetName': $_" } } + #Empty string is not allowed as a name for ranges or tables. if ($RangeName) { Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $RangeName} if ($TableName) { @@ -894,22 +895,22 @@ $ws.View.FreezePanes(1, 2) Write-Verbose -Message "Froze first column" } - + #Must be 1..maxrows or and array of 1..maxRows,1..MaxCols if ($FreezePane) { $freezeRow, $freezeColumn = $FreezePane if (-not $freezeColumn -or $freezeColumn -eq 0) { $freezeColumn = 1 } - if ($freezeRow -gt 1) { + if ($freezeRow -ge 1) { $ws.View.FreezePanes($freezeRow, $freezeColumn) - Write-Verbose -Message "Froze pandes at row $freezeRow and column $FreezeColumn" + Write-Verbose -Message "Froze panes at row $freezeRow and column $FreezeColumn" } } } catch {Write-Warning -Message "Failed adding Freezing the panes in worksheet '$WorksheetName': $_"} - if ($BoldTopRow) { #it sets bold as far as there are populated cells: for whole row could do $ws.row($x).style.font.bold = $true + if ($PSBoundParameters.ContainsKey("BoldTopRow")) { #it sets bold as far as there are populated cells: for whole row could do $ws.row($x).style.font.bold = $true try { if ($Title) { $range = $ws.Dimension.Address -replace '\d+', ($StartRow + 1) @@ -917,7 +918,7 @@ else { $range = $ws.Dimension.Address -replace '\d+', $StartRow } - $ws.Cells[$range].Style.Font.Bold = $true + $ws.Cells[$range].Style.Font.Bold = [boolean]$BoldTopRow Write-Verbose -Message "Set $range font style to bold." } catch {Write-Warning -Message "Failed setting the top row to bold in worksheet '$WorksheetName': $_"} @@ -1040,6 +1041,7 @@ catch {Write-Warning -Message "Failed processing CellStyleSB in worksheet '$WorksheetName': $_"} } + #Can only add password, may want to support -password $Null removing password. if ($Password) { try { $ws.Protection.SetPassword($Password) diff --git a/Join-Worksheet.ps1 b/Join-Worksheet.ps1 index bea36db..d9384fd 100644 --- a/Join-Worksheet.ps1 +++ b/Join-Worksheet.ps1 @@ -63,7 +63,7 @@ #Join-Worksheet assumes each sheet has identical headers and the headers should be copied to the target sheet, unless -NoHeader is specified. [switch]$NoHeader, #If -NoHeader is NOT specified, then rows of data will be labeled with the name of the sheet they came from. FromLabel is the header for this column. If it is null or empty, the labels will be omitted. - $FromLabel = "From" , + [string]$FromLabel = "From" , #If specified, the copied blocks of data will have the name of the sheet they were copied from inserted above them as a title. [switch]$LabelBlocks, #Sets the width of the Excel columns to display all the data in their cells. @@ -161,6 +161,7 @@ #Assume every row has titles in row 1, copy row 1 from first sheet to new sheet. $destinationSheet.Select("A$row") $ExcelPackage.Workbook.Worksheets[1].cells["1:1"].Copy($destinationSheet.SelectedRange) + #fromlabel can't be an empty string if ($FromLabel ) { #Add a column which says where the data comes from. $fromColumn = ($destinationSheet.Dimension.Columns + 1) diff --git a/New-ExcelChart.ps1 b/New-ExcelChart.ps1 index 43b4307..473979d 100644 --- a/New-ExcelChart.ps1 +++ b/New-ExcelChart.ps1 @@ -401,14 +401,16 @@ function Add-ExcelChart { } if ($NoLegend) { $chart.Legend.Remove() } else { - if ($LegendPosition) {$Chart.Legend.Position = $LegendPosition} - if ($LegendSize) {$chart.Legend.Font.Size = $LegendSize} - if ($legendBold) {$chart.Legend.Font.Bold = $true} + if ($PSBoundParameters.ContainsKey('LegendPosition')) {$chart.Legend.Position = $LegendPosition} + if ($PSBoundParameters.ContainsKey('LegendBold')) {$chart.Legend.Font.Bold = [boolean]$LegendBold} + if ($LegendSize) {$chart.Legend.Font.Size = $LegendSize} } if ($XAxisTitleText) { $chart.XAxis.Title.Text = $XAxisTitleText - if ($XAxisTitleBold) {$chart.XAxis.Title.Font.Bold = $true} + if ($PSBoundParameters.ContainsKey('XAxisTitleBold')) { + $chart.XAxis.Title.Font.Bold = [boolean]$XAxisTitleBold + } if ($XAxisTitleSize) {$chart.XAxis.Title.Font.Size = $XAxisTitleSize} } if ($XAxisPosition) {Write-Warning "X-axis position is not being set propertly at the moment, parameter ignored" } @@ -421,7 +423,9 @@ function Add-ExcelChart { if ($YAxisTitleText) { $chart.YAxis.Title.Text = $YAxisTitleText - if ($YAxisTitleBold) {$chart.YAxis.Title.Font.Bold = $true} + if ($PSBoundParameters.ContainsKey('YAxisTitleBold')) { + $chart.YAxis.Title.Font.Bold = [boolean]$YAxisTitleBold + } if ($YAxisTitleSize) {$chart.YAxis.Title.Font.Size = $YAxisTitleSize} } if ($YAxisPosition) {Write-Warning "Y-axis position is not being set propertly at the moment, parameter ignored" } diff --git a/Set-Column.ps1 b/Set-Column.ps1 index 36eb2eb..36a181e 100644 --- a/Set-Column.ps1 +++ b/Set-Column.ps1 @@ -147,7 +147,7 @@ Add-ExcelName -Range $Worksheet.Cells[($StartRow+1), $Column, $endRow, $Column] -RangeName $Worksheet.Cells[$StartRow, $Column].Value } - #Fill in the data + #Fill in the data -it can be zero null or and empty string. if ($PSBoundParameters.ContainsKey('Value')) { foreach ($row in ($StartRow..$endRow)) { if ($Value -is [scriptblock]) { #re-create the script block otherwise variables from this function are out of scope. $cellData = & ([scriptblock]::create( $Value )) diff --git a/compare-worksheet.ps1 b/compare-worksheet.ps1 index e43cb93..7cb58fe 100644 --- a/compare-worksheet.ps1 +++ b/compare-worksheet.ps1 @@ -168,7 +168,7 @@ foreach ($file in $updates) { try {$xl = Open-ExcelPackage -Path $file.name } catch {Write-warning -Message "Can't open $($file.Name) for writing." ; return} - if ($AllDataBackgroundColor) { + if ($PSBoundParameters.ContainsKey("AllDataBackgroundColor")) { $file.Group._sheet | Sort-Object -Unique | ForEach-Object { $ws = $xl.Workbook.Worksheets[$_] if ($headerName) {$range = "A" + $startrow + ":" + $ws.dimension.end.address} @@ -181,7 +181,7 @@ $range = $ws.Dimension -replace "\d+",$row._row Set-Format -WorkSheet $ws -Range $range -BackgroundColor $BackgroundColor } - if ($TabColor) { + if ($PSBoundParameters.ContainsKey("TabColor")) { if ($TabColor -is [string]) {$TabColor = [System.Drawing.Color]::$TabColor } foreach ($tab in ($file.group._sheet | Select-Object -Unique)) { $xl.Workbook.Worksheets[$tab].TabColor = $TabColor