在这里,我试图删除该行任何单元格中具有'*'值的行。 下面是我的代码。
这是用于标题的
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
我在这里做错了什么?预先感谢。
答案 0 :(得分:0)
我将条件(如果不是r.Item(10).ToString()。Contains(“ *”)然后)(其中r.Item(10)是我的列号。)移到了For Each r中作为ds.Tables(0).Rows循环中的DataRow。
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