VB.NET获取Excel单元格内容
想获取某个Excel中的某个单元格的内容,让它显示在文本框里,应该用哪个命令?网上找了半天,都是给单元格赋值的...
想获取某个Excel中的某个单元格的内容,让它显示在文本框里,应该用哪个命令?
网上找了半天,都是给单元格赋值的 展开
网上找了半天,都是给单元格赋值的 展开
2个回答
展开全部
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'读取第一行第一列值,其它的你自己可以写
xlApp.Application.Visible = False
xlBook.Close()
xlApp = Nothing'"交还控制给Excel
xlBook = Nothing
xlSheet = Nothing
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'读取第一行第一列值,其它的你自己可以写
xlApp.Application.Visible = False
xlBook.Close()
xlApp = Nothing'"交还控制给Excel
xlBook = Nothing
xlSheet = Nothing
展开全部
在程序中引用spire.xls.dll
Imports Spire.Xls
Namespace GetCellValue
Class Program
Shared Sub Main(ByVal args() As String)
'创建Workbook对象
Dim wb As Workbook = New Workbook()
'加载Excel文档
wb.LoadFromFile("C:\Users\Administrator\Desktop\test.xlsx")
'获取第一个工作表
Dim sheet As Worksheet = wb.Worksheets(0)
'获取指定单元格的值
Dim value As String = sheet.Range("C4").Value2.ToString()
End Sub
End Class
End Namespace
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |