作者:乔山办公网日期:
返回目录:excel表格制作
VSTO你可以看看
vb.NET有时很怪,不同版本,或者不zd同机器,在操作excel时,判断单元格是否为空时,会出现不同的错误提示。
大多数情况,xlSheet.Cells(1, 1)="" 就可以判断这个单元是否有内容。
但是有时也会有不同的提示。总结不同机版器,不同版本,用下面几种来试试单元格是否是空白。权
xlSheet.Cells(1, 1)=""
xlSheet.Cells(1, 1).value=""
xlSheet.Cells(1, 1).value.tostring=""
如果上面三个代码都会自动提示错误,请用下面终极模式:)
xlSheet.Cells(1, 1).value = Nothing
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlRange As Excel.Range
Dim strTmp As String = ""
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Open(txtfileName.Text)
xlSheet = xlBook.Worksheets(1)
xlApp.Visible = False
xlRange = xlSheet.Cells(1, 1)
strTmp = xlRange.Value'读取zd第一行第一列值,其它的你回自己可以写
xlApp.Application.Visible = False
xlBook.Close()
xlApp = Nothing'"交还控制答给Excel
xlBook = Nothing
xlSheet = Nothing