diff --git a/PSExcel/Format-Cell.ps1 b/PSExcel/Format-Cell.ps1 index 166cac5..61470d1 100644 --- a/PSExcel/Format-Cell.ps1 +++ b/PSExcel/Format-Cell.ps1 @@ -1,4 +1,4 @@ -function Format-Cell { +function Format-Cell { <# .SYNOPSIS Format cells in an Excel worksheet @@ -69,6 +69,12 @@ .PARAMETER AutoFitMaxWidth Maximum width to set autofit with + + .PARAMETER Height + If specified, override autofit preferences to apply the defined row height. + + .PARAMETER Width + If specified, override autofit preferences to apply the defined row width. .PARAMETER VerticalAlignment Set the vertical alignment @@ -85,6 +91,12 @@ .PARAMETER BorderColor Color for the border. Defaults to Black + .PARAMETER Comment + Add a comment to the cell(s). You must include the comment and author + + .Parameter AutoFitComment + If specified, the comment box will autofit to the text supplied. Ignored if comment not specified + .PARAMETER Passthru If specified, pass the Worksheet back @@ -112,6 +124,9 @@ $WorkSheet | Format-Cell -StartRow 2 -StartColumn 1 -EndColumn 1 -Italic $True -Size 10 # Set the first column, rows 2 through the end to size 10, italic + .EXAMPLE + # Add a comment to the first 3 columns of the second row, and autofit the comment box to the included text. + $WorkSheet | Format-Cell -StartRow 2 -StartColumn 1 -EndColumn 3 -Comment "This is a comment on a cell.`nWe can even do multiple lines!","JohnSmith" -AutoFitComment .EXAMPLE @@ -181,6 +196,7 @@ [System.Drawing.KnownColor]$Color, [System.Drawing.KnownColor]$BackgroundColor, + [string[]]$Comment, [OfficeOpenXml.Style.ExcelFillStyle]$FillStyle, [boolean]$WrapText, [String]$NumberFormat, @@ -189,6 +205,8 @@ [switch]$Autofit, [double]$AutofitMinWidth, [double]$AutofitMaxWidth, + [double]$Height, + [double]$Width, [OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment, [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment, @@ -294,6 +312,18 @@ $CellRange.Style.Fill.PatternType = $FillStyle $CellRange.Style.Fill.BackgroundColor.SetColor($BackgroundColorConverted) } + 'Comment' { ForEach ($Row in $StartRow..$EndRow) { + ForEach ($Column in $StartColumn..$EndColumn) { + $CommentCell = ConvertTo-ExcelCoordinate -Row $Row -Column $Column + $NewComment = $WorkSheet.Cells["$CommentCell`:$CommentCell"].AddComment($Comment[0],$Comment[1]) + if($PSBoundParameters.ContainsKey('AutoFitComment')) + { + $NewComment.Autofit = $true + } + + } + } + } 'WrapText' { $CellRange.Style.WrapText = $WrapText } 'VerticalAlignment' { $CellRange.Style.VerticalAlignment = $VerticalAlignment } 'HorizontalAlignment' { $CellRange.Style.HorizontalAlignment = $HorizontalAlignment } @@ -320,6 +350,28 @@ Write-Error $_ } } + 'Height' { + try + { + for($i=$StartRow;$i -le $EndRow; $i++) + {$WorkSheet.Row($i).Height = $Height } + } + Catch + { + Write-Error $_ + } + } + 'Width' { + try + { + for($i=$StartColumn;$i -le $EndColumn; $i++) + {$WorkSheet.Column($i).Width = $Width } + } + Catch + { + Write-Error $_ + } + } 'Border' { If($Border -eq '*') { @@ -348,4 +400,4 @@ $WorkSheet } } -} \ No newline at end of file +}