如何使用 epplus 动态删除行?



在这里,我正在尝试删除该行的任何单元格中具有"*"值的行。 下面是我的代码。

这适用于标头:

If ds.Tables.Count > 0 Then
Dim k As Integer = 0
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
If Not skip.Contains(j) Then
If columnNames.Count > 0 AndAlso columnNames.Count = (ds.Tables(0).Columns.Count - skip.Count) Then
strTitle = columnNames(k)
Else
strTitle = ds.Tables(0).Columns(j).ColumnName.Replace("_", " ")
End If
worksheet5.Cells(p, k + 1).Value = strTitle
k = k + 1
End If
Next

行从这里开始:

Dim i As Integer = p + 1
For Each r As DataRow In ds.Tables(0).Rows
If Not r.ToString().Contains("*") Then
k = 0
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
If Not skip.Contains(j) Then
'If Not r.Item(j).ToString().Contains("*") Then
If r.Item(j) Is DBNull.Value Then
worksheet5.Cells(i, k + 1).Value = ""
Else
If k = 0 Then
worksheet5.Cells(i, k + 1).Style.Numberformat.Format = "@"
worksheet5.Cells(i, k + 1).Value = r.Item(j).ToString()
Else
worksheet5.Cells(i, k + 1).Value = r.Item(j)
End If
End If
End If
k = k + 1
End If
Next
i = i + 1
End If
Next
End If

我在这里做错了什么?提前谢谢。

我已经移动了条件(如果不是r.Item(10(。ToString((.包含("*"( 然后( (其中 are.Item(10( 是我的 col 编号。 到 对于每个 r 作为 数据行 在 ds 中。表(0(.行循环。

Dim i As Integer = p + 1
Dim a As Integer = 0
For Each r As DataRow In ds.Tables(0).Rows
If Not r.Item(10).ToString().Contains("*") Then
k = 0
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
If Not skip.Contains(j) Then
If r.Item(j) Is DBNull.Value Then
worksheet5.Cells(i, k + 1).Value = ""
Else
If k = 0 Then
worksheet5.Cells(i, k + 1).Style.Numberformat.Format = "@"
worksheet5.Cells(i, k + 1).Value = r.Item(j).ToString()
Else
worksheet5.Cells(i, k + 1).Value = r.Item(j)
End If
End If
End If
k = k + 1
End If
Next
i = i + 1
End If
Next
End If

最新更新