How I Delete Rows of an Excel Spreadsheet Using Open XML in VB.Net

Anonymous
2023-05-02T14:09:04.04+00:00

I have an Excel Spreadsheet that I am using as a template file. I want to start by deleting all but the first row of the first worksheet. I tried the following code. It should work, but it immediately exits the For loop right after the Row.Remove() statement is executed. This seems like a bug. How do I accomplish this?

The For Loop

For Each Row As Row In SheetData.Elements(Of Row)
    If Int(Row.RowIndex) > 1 Then
       Row.Remove()
    End If
Next

The full code block.



Microsoft 365 and Office Development Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.