vb.net - 从“范围”类型到“字符串”类型的转换无效。在 vb.net 中
问题描述
在调试此错误时单击“下载目录”按钮会发生“从类型“范围”到类型“字符串”的转换无效”。Microsoft.VisualBasic 中发生了“System.InvalidCastException”类型的未处理异常。
If Trim(.Cells._Default(1, 1)) = "" Then
MsgBox("Please Enter the Auction No in Cell B2 ", MsgBoxStyle.Information)
Exit Function
Else
StrAuctionNo = Trim(.Cells._Default(1, 1))
End If
解决方案
好的,这是 Vb.net 版本:
Public Sub Test()
dim excel as new Microsoft.Office.Interop.Excel.Application
Dim workbook As Microsoft.Office.Interop.Excel.Workbook
Dim cellRange As Microsoft.Office.Interop.Excel.Range
Dim sheet As Microsoft.Office.Interop.Excel.Worksheet
workbook = excel.Workbooks.Open("c:\temp\Book1.xls")
sheet = workbook.Sheets(1)
cellRange = sheet.Range("A1:B2")
Dim val As String = cellRange.Cells(2,2).Value
If String.IsNullOrEmpty(val) orelse val.Trim() = String.Empty Then
MsgBox("Field missing ....")
Else
MsgBox("OK!!")
End If
End Sub
推荐阅读
- c# - 动画状态..因为找不到而无法播放?
- google-cloud-platform - 将 dataproc 集群连接到 Cloud SQL 实例时,没有要代理的 Cloud SQL 实例
- git - JGit 克隆存储库在运行时显示进度
- api - 如何将变量传递回控制器中的调用方法
- mongodb - Mongo db - 使用嵌套字段(嵌套数组和对象)查询文档
- javascript - 将 ArrayBuffer 发送到 S3 放到 signedURL
- python - 气流无法识别使用 pytest 夹具构建的 zip 文件 DAG
- react-native - 如何在 React Native 中将 base64 字符串图像转换为 blob?
- linux - 如何使查询在linux服务器中工作?
- list - 将列表转换为张量更准确