There are few ways to do this.
One way is to manipulate the data table, however, you may find that after removing some rows with this method, that writing it back to the file, the existing data in the file has more rows therefore leaving the excess rows at the bottom of the spreadsheet.
dt1.AsEnumerable.Where(Function(r) r("CEDULA").ToString.Trim<>"90850158" ).ToArray
or if you have the ids in an array/list, then the condition would look like this:
dt1.AsEnumerable.Where(Function(r) Not idsToRemove.Contains(r("CEDULA").ToString.Trim) ).ToArray
or if you already have an array of rows, then change the dt1.AsEmuerable to the array:
matchedRows.Where(Function(r) Not idsToRemove.Contains(r("CEDULA").ToString.Trim) ).ToArray
Then, process those rows as you would as previously presented.
However, like I mentioned, when you try to write this new data set back to the existing file, if the data in the existing file has more rows than what you are writing, it will keep those excess rows. This means you would need to clear the file prior to writing it back to the file.
There is another way though, which removes the row directly in the file, but slightly slower:
The ‘Insert/Delete Rows’ activity lets you perform the action directly in the file. This also means you need to run loops over all the ids you want to remove.
For this, you still need to find the row index because it is required by the activity. You can use .net for this (but if you already are using a ForEach of the row, then use the output property for the index value.)
First, you need to run a loop over all the IDs you want to remove. Then, inside the loop, assign the index using the cedula value from the loop. After that, just place the index into the ‘Insert/Delete Rows’ activity.
It will also be important assign the rows to delete to an array of DataRows, so you can remove all rows matching to the ID and it won’t throw any errors:
ForEach id In idsArray //typeargument: String
Assign: idRowsToDelete = dt1.AsEnumerable.Where(Function(r) r("CEDULA").ToString.Trim = id ).ToArray
IF idRowsToDelete.Count > 0
ForEach idRow In idRowsToDelete //typeargument: DataRow
idRowIndex = dt1.Rows.IndexOf(idRow)
Insert/Delete Row activity using idRowIndex with Delete option.
I hope that makes sense. If you have trouble, I might be able when I have time later to provide the .xaml with this working.
Note: if you have the Excel AutoSave option off, the execution of the delete will be faster. Then, use the ‘Save Workbook’ activity when all rows are done deleting.
Regards.