将数据从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