以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 获取EXCEL单元格的值一直报错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=191842) |
-- 作者:9EQ98 -- 发布时间:2024/5/11 9:36:00 -- 获取EXCEL单元格的值一直报错 请问:下述报错如何修改语句代码 ? 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 |
-- 作者:有点蓝 -- 发布时间:2024/5/11 9:45:00 -- If Rg_val.Value isnot nothing AndAlso rg_val.Value.ToString.Contains("|") Then \' 出错语句 |
-- 作者:9EQ98 -- 发布时间:2024/5/11 9:53:00 -- Dim rg_v As String = Rg_val.Value.ToString 请问:这个语句如何修改 ?
|
-- 作者:有点蓝 -- 发布时间:2024/5/11 9:59:00 -- If Rg_val.Value isnot nothing Dim rg_v As String = Rg_val.Value.ToString …… |
-- 作者:9EQ98 -- 发布时间:2024/5/11 12:37:00 -- 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 \' 执行这个语句还是会报错,请问为什么? |
-- 作者:有点蓝 -- 发布时间:2024/5/11 13:59:00 -- 请提供实例测试 |