在这里,我试图删除该行的任何单元格中具有“*”值的行。下面是我的代码..
这是标题:
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
Row从这里开始:
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()。包含(“*”)然后)(其中r.Item(10)是我的col号。)来自For Each r As DataRow In ds.Tables(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