Cannot delete rows, see description
Error: Exception calling "DeleteRow" with "1" argument(s): "Comment does not exist in the worksheet"
I have tried clearing all comments in the file to an empty string, but the error persists. Any ideas?
Need a small repo, script and code or what you are trying to do.
@dfinke ah yes sorry. I am simply calling excel.deleterow(1). I am not at my pc right now to get the specifics but the logic is:
I want to delete the first 13 rows. So I do a simple loop 13 times and call deleterow(1) for each of them.
This works great until I get to rows that have comments in them, this exception is throw. If I had to guess, the module is trying to delete the comment but fails. My next step was to look at that function but I couldn’t find it in a timely manner today.
Thank you!
Still need to see the script. Off the top of my head, maybe deleting the rows from the last row to first row of the range.
Tried it backwards but it still crashes on the same rows:
$excel = Open-ExcelPackage -path $excelInFile.FullName # CREATE EXCEL OBJECT
$DATAws = $excel.Workbook.Worksheets["Data"]
Write-Log -Level 'INFO' -Message ("REMOVING ROWS")
$i = 13
1..13 | % {
##Write-Log -Level 'INFO' -Message ("REMOVING ROW " + $_)
##$DATAws.DeleteRow(1)
Write-Log -Level 'INFO' -Message ("REMOVING ROW " + $i)
$DATAws.DeleteRow($i)
$i--
}
Log Output:
[INFO ] REMOVING ROWS [INFO ] REMOVING ROW 13 [INFO ] REMOVING ROW 12 [INFO ] REMOVING ROW 11 [INFO ] REMOVING ROW 10 [ERROR ] ForEach-Object: Script.ps1:184:21 Line | 184 | 1..13 | % { | ~~~ | Exception calling "DeleteRow" with "1" argument(s): "Comment does not exist in the worksheet
Need to see the spreadsheet too. Could be an internal issue.
I had to remove the table data due to sensitivity, but the file contains the rows with issues.
Not sure why that doesn't work. Don't have time right now. Not sure it is the module causing it. I would try a stepped approach to figure things out. See where it breaks first. Delete 1 row, then 1 and 2, then 1,2,3. Go from there.
This worked for me $excel.Data.DeleteRow(1, 13) in one block.
Wow that one liner is way more practical. I wasn’t aware you could pass it two parameters. Thanks for the suggestions. I might just use the working method and leave this issue for now. Thank you for the awesome toolset and looking into this.