用vb读取Excel中某个单元格的数据
3个回答
展开全部
单纯的说怎么读取很简单,假设你的控件名称为A,则 A.text = “sheet1.cells(2,2).value”
下面给出VB.NET 的完整代码:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim DataSPath As String
DataSPath = "C:\a.xls"
Dim ExlApp = CreateObject("Excel.Application")
Dim xlbook = ExlApp.Workbooks
Dim xlbk = ExlApp.workbooks.Open(DataSPath)
Dim St1 = xlbk.worksheets(1)
TextBox1.Text = DataSPath & " 表1中 " & St1.cells(2, 2).value
St1 = Nothing
xlbook = Nothing
ExlApp = Nothing
MsgBox("OK", MsgBoxStyle.Exclamation, "Tudy")
End Sub
End Class
展开全部
Private Sub Command1_Click()
Dim A As Integer
Dim scxls As New excel.Application
Dim scbook As excel.Workbook
Dim scsheet As excel.Worksheet
Set scxls = CreateObject("excel.application") '创建EXCEL对象
scxls.DisplayAlerts = False '不显示对话框,如果D:\2\1\3.xls文件已存在,让它不出现这个提示,就需加这段代码。
Set scbook = scxls.Workbooks.Open("D:\2\4.xls")
'Set scbook = scxls.Workbooks.Add '新建EXCEL工件簿文件
Set scsheet = scbook.Worksheets(1) '设置活动工作表
scxls.Visible = True '显示Excle
Text1.Text = scsheet.Cells(2, 2) '读取数据 并在text1里显示
Text2.Text = scsheet.Cells(2, 6) '读取数据 并在text1里显示
scsheet.SaveAs ("D:\2\1\3.xls") 'excel 存档 语法:表达式.SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
scxls.Quit 'excel 关闭
End Sub
Dim A As Integer
Dim scxls As New excel.Application
Dim scbook As excel.Workbook
Dim scsheet As excel.Worksheet
Set scxls = CreateObject("excel.application") '创建EXCEL对象
scxls.DisplayAlerts = False '不显示对话框,如果D:\2\1\3.xls文件已存在,让它不出现这个提示,就需加这段代码。
Set scbook = scxls.Workbooks.Open("D:\2\4.xls")
'Set scbook = scxls.Workbooks.Add '新建EXCEL工件簿文件
Set scsheet = scbook.Worksheets(1) '设置活动工作表
scxls.Visible = True '显示Excle
Text1.Text = scsheet.Cells(2, 2) '读取数据 并在text1里显示
Text2.Text = scsheet.Cells(2, 6) '读取数据 并在text1里显示
scsheet.SaveAs ("D:\2\1\3.xls") 'excel 存档 语法:表达式.SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
scxls.Quit 'excel 关闭
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
range("xx").value或者 cells(x,x).value
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询