请问:下述报错如何修改语句代码 ?
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(输出文件)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg_Use As MSExcel.Range = Ws.UsedRange
MessageBox.Show(Rg_Use.Rows.Count & " " & Rg_Use.Columns.Count & " " & Rg_Use.Count)
For i As Integer = 1 To Rg_Use.Rows.Count
For j As Integer = 1 To Rg_Use.Columns.Count
Dim Rg_val As MSExcel.Range = Ws.Cells(i, j)
'Dim rg_v As String = Rg_val.Value.ToString ' 出错语句
MessageBox.Show(rg_val.Value.ToString) ' 这里不出错
If Rg_val.Value.ToString <> "" AndAlso rg_val.Value.ToString.Contains("|") Then ' 出错语句
MessageBox.Show(rg_val.Value.ToString)
End If
Next
Next
If Rg_val.Value isnot nothing AndAlso rg_val.Value.ToString.Contains("|") Then ' 出错语句
If Rg_val.Value isnot nothing Dim rg_v As String = Rg_val.Value.ToString
……
If 换行 = True AndAlso Rg_Val_Str.Contains(换行符) Then
Dim Rg_Use As MSExcel.Range = Ws.UsedRange
For i As Integer = 1 To Rg_Use.Rows.Count
For j As Integer = 1 To Rg_Use.Columns.Count
Dim Rg_val As MSExcel.Range = Ws.Cells(i, j)
Dim Rg_Val_Str As String = ""
If Rg_val.Value IsNot Nothing Then
Dim 行 As String = "行: " & I & "(" & RG_VAL.Row & ")"
Dim 列 As String = "列: " & j & "(" & RG_VAL.Column & ")"
Rg_Val_Str = Rg_val.Value.ToString()
If Rg_Val_Str > "" Then
If 换行 = True AndAlso Rg_Val_Str.Contains(换行符) Then
Dim VS As String = Rg_Val_Str.Replace(换行符, vbCrLf)
Try
Rg_val.Value = VS
Catch ex As Exception
MessageBox.Show( 行 & vbCrLf & 列 & vbCrLf & VS, "自动换行符错误")
End Try
End If
...
Rg_val.Value = VS ' 执行这个语句还是会报错,请问为什么?