From 652a6111376adaf3f0d5a8655af0acc09659779b Mon Sep 17 00:00:00 2001 From: Thomas Hofkens Date: Sat, 12 Nov 2022 00:24:17 +0100 Subject: [PATCH] Added new function 'Set-CellComment' --- ImportExcel.psd1 | 1 + Public/Set-CellComment.ps1 | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Public/Set-CellComment.ps1 diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 1cc336b..d37aa3f 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -88,6 +88,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Remove-Worksheet', 'Select-Worksheet', 'Send-SQLDataToExcel', + 'Set-CellComment', 'Set-CellStyle', 'Set-ExcelColumn', 'Set-ExcelRange', diff --git a/Public/Set-CellComment.ps1 b/Public/Set-CellComment.ps1 new file mode 100644 index 0000000..a68cdca --- /dev/null +++ b/Public/Set-CellComment.ps1 @@ -0,0 +1,31 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Set*', Justification='Does not change system state')] +param() + +function Set-CellComment { + [CmdletBinding(DefaultParameterSetName = "ColumnLetter")] + param( + [Parameter(Mandatory = $True)] + [OfficeOpenXml.ExcelWorkSheet]$Worksheet, + + [Parameter(Mandatory = $True)] + [Int]$Row, + + [Parameter(Mandatory = $True, ParameterSetName = "ColumnLetter")] + [String]$ColumnLetter, + + [Parameter(Mandatory = $True, ParameterSetName = "ColumnNumber")] + [Int]$ColumnNumber, + + [Parameter(Mandatory = $True)] + [String]$Text + ) + + If ($PSCmdlet.ParameterSetName -eq "ColumnNumber") { + $ColumnLetter = (Get-ExcelColumnName -ColumnNumber $ColumnNumber).ColumnName + } + + $a = "{0}{1}" -f $ColumnLetter,$Row + $t = $Worksheet.Cells[$a] + [Void]$t.AddComment($Text, "ImportExcel") + $t.Comment.AutoFit = $True +} \ No newline at end of file