将数据从Excel导入到Visual Basic中的文本框 [英] importing data from excel to textbox in visual basic

查看:210
本文介绍了将数据从Excel导入到Visual Basic中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在将excel(2003)中的单个单元格中的数字数据导入的简单方法?

Is there a simple way of importing numeric data from a single cell in excel (2003) into
a textbox in a visual basic form?

推荐答案

您可以将excel中的所有数据导入datagrid视图,然后选择datagrid视图的垂直单元格并将单元格数据导入文本框.
You can Take all the data from the excel into datagrid view and Select the perticular cell of datagrid view and take cell data to textbox..


http://www .google.nl/#hl = eng& q = vb + read + excel + data [

好,我将创建一个类来处理OleDB Connection(假设您正在使用VB .NET),以便您可以重用代码;让我们假设您有一个包含人员姓名和年龄的Excel数据库,并且希望您的文本框显示所选人员的年龄.

Ok I would create a class to handle the OleDB Connection(I''m assuming you''re using VB .NET), so that you can reuse code; lets assume that you have an Excel Database with Names and Ages of people and you would like your Textbox to display the age of the selected person.

Public Class ExcelReader

         Private Function ConnString(ByVal str As String) As String
                 ''str is the Path to the Excel File.
              Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
              + str + ";Extended Properties=""Excel 8.0;HDR=Yes"""
         End Function

         Public Sub RetrieveRecord(ByVal str As String, ByVal Name As String)
               ''str is again the Path to the Excel File, and Name is the Name
               ''you would like to find the age for.
              Dim Conn As New OleDBConnection
              Dim Comm As New OleDBCommand
              Dim DReader As OleDBDataReader

              Conn.ConnectionString = ConnString(str)
              Comm.Connection = Conn
              Comm.CommandText = "Select * From [Sheet1


这篇关于将数据从Excel导入到Visual Basic中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆