This topic contains 2 replies, has 2 voices, and was last updated by

Participant
1 year ago.

• Author
Posts
• #84073

Participant
Points: 0
Rank: Member

I need to write a comment in a cell if it contains the word "family" (for now as it will point to an array) – however, I have no idea how to do it.
This is what i have so far (i used PSEXCEL, but if anyone has any other ideas (this will run on a server however – no excel installed)

## https://github.com/RamblingCookieMonster/PSExcel
Import-Module "\\path\to\PSExcel"
$k = Search-CellValue -Path "C:\test.xlsx" {$_ -like 'family'}
if ($k.worksheetname -ne$null){
#knowing that i have a good sheet, i can get the row, column and write a comment, but i don't know how to do it
}


I have a basic excel file like so (called it "text.xlsx")
group
family
test1
test23
tedsfgsd
sdfsd
sdrfsd
sdfssd
sdfasd
sdftsd
sdhfsdf
sdf

• #84115

Participant
Points: 13
Rank: Member

Try

[void] $CurrentSheet.Cells.Item($ServerRow+1,$ServerCol).Addcomment("comment") • #84118 Participant Points: 0 Rank: Member tried that one and received a "You cannot call a method on a null-valued expression." (in my case the$CurrentSheet was set either static or dynamic ie. $CurrentSheet =$k.WorksheetName and/or \$CurrentSheet = "Sheet1"