Home > database >  POwershell excel cell font formating
POwershell excel cell font formating

Time:11-02

I use a script to find rows in an excel and to delete entire row. Now I want not to delete but change fonts to strikethrough.

The part of the code is: `

$Rows = get-content c:\temp\Rrows.txt
foreach($Row in $Rows){
if ($ExcelWorkSheet2.cells.Item($Row,3).Value() -ne "Something"){
                                
                                #$ExcelWorkSheet2.Cells.Item($Row,1).style.Font.Strikethrough = $True
                                #$ExcelWorkSheet2.Cells.Item($Row,2).style.Font.Strikethrough = $True
                                #$ExcelWorkSheet2.Cells.Item($Row,3).style.Font.Strikethrough = $True
                                
                                #$ExcelWorkSheet2.rows($Row).style.Font.Strikethrough = $True


                                $RowToDelete = $ExcelWorkSheet2.Cells.Item($Row,1).EntireRow
                                $RowToDelete.Delete()
                                }}

` I tried 2 different methods and the results were to stikethrough entire sheet and not only the specified rows. What is wrong here?

CodePudding user response:

Just change line $RowToDelete.Delete() into

$RowToDelete.Font.Strikethrough = $true

Strikethrough is a property of the Font object of the row. Just set that to $true and save the changes

  • Related